@@ -77,14 +77,21 @@ def env(context: Context):
7777@task
7878def 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