Skip to content

Commit 754a619

Browse files
authored
minor improvements to project setup (#1082)
* minor improvements to project setup * install docs + fix ruff errors * fix lint * fixes first
1 parent 3f804ca commit 754a619

File tree

9 files changed

+74
-25
lines changed

9 files changed

+74
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.jupyter
1212

1313
# --- Python ---
14+
.hatch
1415
.venv
1516
venv
1617
MANIFEST

.pre-commit-config.yaml

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@ repos:
33
hooks:
44
- id: lint-py-fix
55
name: Fix Python Lint
6-
entry: hatch run lint-py --fix
7-
language: system
8-
pass_filenames: false
9-
- repo: local
10-
hooks:
11-
- id: lint-py-check
12-
name: Check Python Lint
136
entry: hatch run lint-py
147
language: system
8+
args: [--fix]
159
pass_filenames: false
1610
- repo: local
1711
hooks:
@@ -20,6 +14,13 @@ repos:
2014
entry: hatch run lint-js --fix
2115
language: system
2216
pass_filenames: false
17+
- repo: local
18+
hooks:
19+
- id: lint-py-check
20+
name: Check Python Lint
21+
entry: hatch run lint-py
22+
language: system
23+
pass_filenames: false
2324
- repo: local
2425
hooks:
2526
- id: lint-js-check

docs/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.poetry]
2-
name = "docs"
2+
name = "docs_app"
33
version = "0.0.0"
44
description = "docs"
55
authors = ["rmorshea <[email protected]>"]

docs/source/_exts/reactpy_example.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from pathlib import Path
5-
from typing import Any
5+
from typing import Any, ClassVar
66

77
from docs_app.examples import (
88
SOURCE_DIR,
@@ -21,7 +21,7 @@ class WidgetExample(SphinxDirective):
2121
required_arguments = 1
2222
_next_id = 0
2323

24-
option_spec = {
24+
option_spec: ClassVar[dict[str, Any]] = {
2525
"result-is-default-tab": directives.flag,
2626
"activate-button": directives.flag,
2727
}

docs/source/_exts/reactpy_view.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
2-
import sys
3-
4-
print(sys.path)
2+
from typing import Any, ClassVar
53

64
from docs_app.examples import get_normalized_example_name
75
from docutils.nodes import raw
@@ -20,7 +18,7 @@ class IteractiveWidget(SphinxDirective):
2018
required_arguments = 1
2119
_next_id = 0
2220

23-
option_spec = {
21+
option_spec: ClassVar[dict[str, Any]] = {
2422
"activate-button": directives.flag,
2523
"margin": float,
2624
}

docs/source/about/contributor-guide.rst

+22
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ Then, you should be able to activate your development environment with:
118118
119119
hatch shell
120120
121+
From within the shell, to install the projects in this repository, you should then run:
122+
123+
.. code-block:: bash
124+
125+
invoke env
126+
127+
Project Structure
128+
-----------------
129+
130+
This repository is set up to be able to manage many applications and libraries written
131+
in a variety of languages. All projects can be found under the ``src`` directory:
132+
133+
- ``src/py/{project}`` - Python packages
134+
- ``src/js/app`` - ReactPy's built-in JS client
135+
- ``src/js/packages/{project}`` - JS packages
136+
137+
At the root of the repository is a ``pyproject.toml`` file that contains scripts and
138+
their respective dependencies for managing all other projects. Most of these global
139+
scripts can be run via ``hatch run ...`` however, for more complex scripting tasks, we
140+
rely on Invoke_. Scripts implements with Invoke can be found in ``tasks.py``.
121141

122142
Running The Tests
123143
-----------------
@@ -308,6 +328,8 @@ you should refer to their respective documentation in the links below:
308328
.. Links
309329
.. =====
310330
331+
.. _Hatch: https://hatch.pypa.io/
332+
.. _Invoke: https://www.pyinvoke.org/
311333
.. _Google Chrome: https://www.google.com/chrome/
312334
.. _Docker: https://docs.docker.com/get-docker/
313335
.. _Git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

src/py/reactpy/reactpy/core/events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def event(
2121

2222
@overload
2323
def event(
24-
function: Literal[None] = None,
24+
function: Literal[None] = ...,
2525
*,
2626
stop_propagation: bool = ...,
2727
prevent_default: bool = ...,

src/py/reactpy/reactpy/core/layout.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
class Layout:
3838
"""Responsible for "rendering" components. That is, turning them into VDOM."""
3939

40-
__slots__ = [
40+
__slots__: tuple[str, ...] = (
4141
"root",
4242
"_event_handlers",
4343
"_rendering_queue",
4444
"_root_life_cycle_state_id",
4545
"_model_states_by_life_cycle_state_id",
46-
]
46+
)
4747

4848
if not hasattr(abc.ABC, "__weakref__"): # nocov
49-
__slots__.append("__weakref__")
49+
__slots__ += ("__weakref__",)
5050

5151
def __init__(self, root: ComponentType) -> None:
5252
super().__init__()

tasks.py

+34-7
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,21 @@ def env(context: Context):
7777
@task
7878
def env_py(context: Context):
7979
"""Install Python development environment"""
80-
for py_proj in PY_PROJECTS:
81-
py_proj_toml = toml.load(py_proj / "pyproject.toml")
82-
hatch_default_env = py_proj_toml["tool"]["hatch"]["envs"].get("default", {})
83-
hatch_default_features = hatch_default_env.get("features", [])
84-
hatch_default_deps = hatch_default_env.get("dependencies", [])
80+
for py_proj in [
81+
DOCS_DIR,
82+
# Docs installs non-editable versions of packages - ensure
83+
# we overwrite that by installing projects afterwards.
84+
*PY_PROJECTS,
85+
]:
86+
py_proj_toml_tools = toml.load(py_proj / "pyproject.toml")["tool"]
87+
if "hatch" in py_proj_toml_tools:
88+
install_func = install_hatch_project
89+
elif "poetry" in py_proj_toml_tools:
90+
install_func = install_poetry_project
91+
else:
92+
raise Exit(f"Unknown project type: {py_proj}")
8593
with context.cd(py_proj):
86-
context.run(f"pip install '.[{','.join(hatch_default_features)}]'")
87-
context.run(f"pip install {' '.join(map(repr, hatch_default_deps))}")
94+
install_func(context, py_proj)
8895

8996

9097
@task
@@ -103,6 +110,7 @@ def lint_py(context: Context, fix: bool = False):
103110
"""Run linters and type checkers"""
104111
if fix:
105112
context.run("ruff --fix .")
113+
context.run("black .")
106114
else:
107115
context.run("ruff .")
108116
context.run("black --check --diff .")
@@ -417,3 +425,22 @@ def publish(dry_run: bool):
417425
)
418426

419427
return publish
428+
429+
430+
def install_hatch_project(context: Context, path: Path) -> None:
431+
py_proj_toml = toml.load(path / "pyproject.toml")
432+
hatch_default_env = py_proj_toml["tool"]["hatch"]["envs"].get("default", {})
433+
hatch_default_features = hatch_default_env.get("features", [])
434+
hatch_default_deps = hatch_default_env.get("dependencies", [])
435+
context.run(f"pip install -e '.[{','.join(hatch_default_features)}]'")
436+
context.run(f"pip install {' '.join(map(repr, hatch_default_deps))}")
437+
438+
439+
def install_poetry_project(context: Context, path: Path) -> None:
440+
# install dependencies from poetry into the current environment - not in Poetry's venv
441+
poetry_lock = toml.load(path / "poetry.lock")
442+
packages_to_install = [
443+
f"{package['name']}=={package['version']}" for package in poetry_lock["package"]
444+
]
445+
context.run("pip install -e .")
446+
context.run(f"pip install {' '.join(packages_to_install)}")

0 commit comments

Comments
 (0)