Skip to content

Commit 7aaaaf1

Browse files
committed
organize for dist as pypi package
1 parent 182cbd6 commit 7aaaaf1

File tree

21 files changed

+226
-40
lines changed

21 files changed

+226
-40
lines changed

dj_idom/consumers.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

noxfile.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import re
5+
import subprocess
6+
from pathlib import Path
7+
from typing import List, Tuple
8+
9+
import nox
10+
from nox.sessions import Session
11+
12+
13+
HERE = Path(__file__).parent
14+
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
15+
16+
17+
@nox.session(reuse_venv=True)
18+
def format(session: Session) -> None:
19+
install_requirements_file(session, "check-style")
20+
session.run("black", ".")
21+
session.run("isort", ".")
22+
23+
24+
@nox.session
25+
def test(session: Session) -> None:
26+
"""Run the complete test suite"""
27+
session.install("--upgrade", "pip", "setuptools", "wheel")
28+
test_suite(session)
29+
test_style(session)
30+
31+
32+
@nox.session
33+
def test_suite(session: Session) -> None:
34+
"""Run the Python-based test suite"""
35+
session.env["IDOM_DEBUG_MODE"] = "1"
36+
install_requirements_file(session, "test-env")
37+
session.install(".[all]")
38+
session.run("figure-it-out")
39+
40+
41+
@nox.session
42+
def test_style(session: Session) -> None:
43+
"""Check that style guidelines are being followed"""
44+
install_requirements_file(session, "check-style")
45+
session.run("flake8", "src/django_idom", "tests")
46+
black_default_exclude = r"\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist"
47+
session.run(
48+
"black",
49+
".",
50+
"--check",
51+
"--exclude",
52+
rf"/({black_default_exclude}|venv|node_modules)/",
53+
)
54+
session.run("isort", ".", "--check-only")
55+
56+
57+
def install_requirements_file(session: Session, name: str) -> None:
58+
file_path = HERE / "requirements" / (name + ".txt")
59+
assert file_path.exists(), f"requirements file {file_path} does not exist"
60+
session.install("-r", str(file_path))

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.isort]
6+
multi_line_output = 3
7+
force_grid_wrap = 0
8+
use_parentheses = "True"
9+
ensure_newline_before_comments = "True"
10+
include_trailing_comma = "True"
11+
line_length = 88
12+
lines_after_imports = 2

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
django<4.0.0 # Django Library
2-
daphne<4.0.0 # Production ASGI webserver
3-
channels<4.0.0 # Django websocket features
4-
idom<1.0.0 # Python React
1+
-r requirements/pkg-deps.txt
2+
-r requirements/check-style.txt
3+
-r requirements/test-env.txt
4+
-r requirements/test-run.txt

requirements/check-style.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
black
2+
flake8
3+
isort

requirements/pkg-deps.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
channels<4.0.0 # Django websocket features
2+
idom<1.0.0 # Python React

requirements/test-env.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
django<4.0.0 # Django Library
2+
daphne<4.0.0 # Production ASGI webserver

requirements/test-run.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nox

setup.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[bdist_wheel]
2+
universal=1
3+
4+
[flake8]
5+
ignore = E203, E266, E501, W503, F811, N802
6+
max-line-length = 88
7+
max-complexity = 18
8+
select = B,C,E,F,W,T4,B9,N,ROH
9+
exclude =
10+
.eggs/*
11+
.nox/*

setup.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from pathlib import Path
2+
3+
from setuptools import find_packages, setup
4+
5+
6+
# the name of the project
7+
name = "django_idom"
8+
9+
# basic paths used to gather files
10+
root_dir = Path(__file__).parent
11+
src_dir = root_dir / "src"
12+
package_dir = src_dir / name
13+
14+
15+
# -----------------------------------------------------------------------------
16+
# Package Definition
17+
# -----------------------------------------------------------------------------
18+
19+
20+
package = {
21+
"name": name,
22+
"python_requires": ">=3.7",
23+
"packages": find_packages(str(src_dir)),
24+
"package_dir": {"": "src"},
25+
"description": "Control the web with Python",
26+
"author": "Ryan Morshead",
27+
"author_email": "[email protected]",
28+
"url": "https://github.com/idom-team/django-idom",
29+
"license": "MIT",
30+
"platforms": "Linux, Mac OS X, Windows",
31+
"keywords": ["interactive", "widgets", "DOM", "React"],
32+
"zip_safe": False,
33+
"classifiers": [
34+
"Framework :: Django",
35+
"Framework :: Django :: 3.1",
36+
"Framework :: Django :: 3.2",
37+
"Operating System :: OS Independent",
38+
"Intended Audience :: Developers",
39+
"Intended Audience :: Science/Research",
40+
"Topic :: Multimedia :: Graphics",
41+
"Programming Language :: Python :: 3.7",
42+
"Programming Language :: Python :: 3.8",
43+
"Programming Language :: Python :: 3.9",
44+
"Environment :: Web Environment",
45+
],
46+
}
47+
48+
49+
# -----------------------------------------------------------------------------
50+
# Requirements
51+
# -----------------------------------------------------------------------------
52+
53+
54+
requirements = []
55+
with (root_dir / "requirements" / "pkg-deps.txt").open() as f:
56+
for line in map(str.strip, f):
57+
if not line.startswith("#"):
58+
requirements.append(line)
59+
package["install_requires"] = requirements
60+
61+
62+
# -----------------------------------------------------------------------------
63+
# Library Description
64+
# -----------------------------------------------------------------------------
65+
66+
67+
with (root_dir / "README.md").open() as f:
68+
long_description = f.read()
69+
70+
package["long_description"] = long_description
71+
package["long_description_content_type"] = "text/markdown"
72+
73+
74+
# -----------------------------------------------------------------------------
75+
# Install It
76+
# -----------------------------------------------------------------------------
77+
78+
79+
if __name__ == "__main__":
80+
setup(**package)

src/django_idom/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .websocket_consumer import IdomAsyncWebSocketConsumer
2+
3+
__all__ = ["IdomAsyncWebSocketConsumer"]

src/django_idom/websocket_consumer.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Anything used to construct a websocket endpoint"""
2+
import asyncio
3+
from typing import Any
4+
5+
from channels.generic.websocket import AsyncJsonWebsocketConsumer
6+
7+
from idom.core.dispatcher import dispatch_single_view
8+
from idom.core.component import ComponentConstructor
9+
10+
11+
class IdomAsyncWebSocketConsumer(AsyncJsonWebsocketConsumer):
12+
"""Communicates with the browser to perform actions on-demand."""
13+
14+
def __init__(
15+
self, component_constructor: ComponentConstructor, *args: Any, **kwargs: Any
16+
) -> None:
17+
self._idom_component_constructor = component_constructor
18+
super().__init__(*args, **kwargs)
19+
20+
async def connect(self) -> None:
21+
self._idom_recv_queue = recv_queue = asyncio.Queue()
22+
self._idom_dispatcher_future = dispatch_single_view(
23+
self._idom_component_constructor,
24+
self.send_json,
25+
recv_queue.get,
26+
)
27+
28+
async def close(self, *args: Any, **kwargs: Any) -> None:
29+
self._idom_dispatcher_future.cancel()
30+
await asyncio.wait([self._idom_dispatcher_future])
31+
super().close(*args, **kwargs)
32+
33+
async def receive_json(self, content: Any, **kwargs: Any) -> None:
34+
await self._idom_recv_queue.put(content)
File renamed without changes.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
22
ASGI config for dj_idom project.
3-
43
It exposes the ASGI callable as a module-level variable named ``application``.
5-
64
For more information on this file, see
75
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
86
"""
@@ -12,18 +10,18 @@
1210
from django.conf.urls import url
1311
from django.core.asgi import get_asgi_application
1412

15-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj_idom.settings")
13+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
1614

1715
# Fetch ASGI application before importing dependencies that require ORM models.
1816
http_asgi_app = get_asgi_application()
1917

2018
from channels.routing import ProtocolTypeRouter, URLRouter
2119

22-
from .consumers import CommandConsumer
20+
from django_idom import IdomAsyncWebSocketConsumer
2321

2422
application = ProtocolTypeRouter(
2523
{
2624
"http": http_asgi_app,
27-
"websocket": URLRouter([url("", CommandConsumer().as_asgi())]),
25+
"websocket": URLRouter([url("", IdomAsyncWebSocketConsumer().as_asgi())]),
2826
}
2927
)

tests/migrations/__init__.py

Whitespace-only changes.

dj_idom/settings.py renamed to tests/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"""
22
Django settings for dj_idom project.
3-
43
Generated by 'django-admin startproject' using Django 3.2.3.
5-
64
For more information on this file, see
75
https://docs.djangoproject.com/en/3.2/topics/settings/
8-
96
For the full list of settings and their values, see
107
https://docs.djangoproject.com/en/3.2/ref/settings/
118
"""
File renamed without changes.
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
{% load static %}
22
<!DOCTYPE html>
33
<html lang="en">
4-
5-
<head>
6-
<meta charset="UTF-8">
7-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
8-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
98
<script src="{% static 'scripts.js' %}" crossorigin="anonymous"></script>
109
<title>IDOM</title>
11-
</head>
10+
</head>
1211

13-
<body>
12+
<body>
1413
<h1>IDOM Test Page</h1>
15-
</body>
16-
17-
</html>
14+
</body>
15+
</html>

tests/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

dj_idom/urls.py renamed to tests/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""dj_idom URL Configuration
2-
32
The `urlpatterns` list routes URLs to views. For more information please see:
43
https://docs.djangoproject.com/en/3.2/topics/http/urls/
54
Examples:
File renamed without changes.

0 commit comments

Comments
 (0)