wexample-wex-addon-dev-python 15.0.4__py3-none-any.whl → 15.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,3 +5,5 @@ from pathlib import Path
5
5
  PYTHON_PYTEST_COV_REPORT_DIR: Path = Path("htmlcov")
6
6
  PYTHON_PYTEST_COV_FORMAT_HTML: str = "html"
7
7
  PYTHON_PYTEST_COV_FORMAT_JSON: str = "json"
8
+ # The runner an app's tests go through when its `.wex/config.yml` declares `test.image`.
9
+ PYTHON_TEST_RUNNER_NAME: str = "test"
@@ -23,11 +23,15 @@ from wexample_wex_addon_ai.workdir.mixin.with_ai_workdir_mixin import (
23
23
  from wexample_wex_addon_app.workdir.code_base_workdir import (
24
24
  CodeBaseWorkdir,
25
25
  )
26
+ from wexample_wex_addon_app.workdir.mixin.with_runner_workdir_mixin import (
27
+ WithRunnerWorkdirMixin,
28
+ )
26
29
 
27
30
  from wexample_wex_addon_dev_python.const.python import (
28
31
  PYTHON_PYTEST_COV_FORMAT_HTML,
29
32
  PYTHON_PYTEST_COV_FORMAT_JSON,
30
33
  PYTHON_PYTEST_COV_REPORT_DIR,
34
+ PYTHON_TEST_RUNNER_NAME,
31
35
  )
32
36
  from wexample_wex_addon_dev_python.file.python_app_iml_file import PythonAppImlFile
33
37
 
@@ -48,6 +52,7 @@ if TYPE_CHECKING:
48
52
  ChildrenFileFactoryOption,
49
53
  )
50
54
  from wexample_helpers.const.types import StructuredData
55
+ from wexample_runner.runner_config import RunnerConfig
51
56
 
52
57
  from wexample_wex_addon_dev_python.file.python_pyproject_toml_file import (
53
58
  PythonPyprojectTomlFile,
@@ -56,7 +61,10 @@ if TYPE_CHECKING:
56
61
 
57
62
  @base_class
58
63
  class PythonWorkdir(
59
- WithAiWorkdirMixin, WithProfilingPythonWorkdirMixin, CodeBaseWorkdir
64
+ WithAiWorkdirMixin,
65
+ WithProfilingPythonWorkdirMixin,
66
+ WithRunnerWorkdirMixin,
67
+ CodeBaseWorkdir,
60
68
  ):
61
69
  def app_install(self, env: str | None = None, force: bool = False) -> Path:
62
70
  from wexample_wex_addon_app.helper.python import (
@@ -143,6 +151,35 @@ class PythonWorkdir(
143
151
  def get_python_path(self) -> Path:
144
152
  return self.get_venv_bin_path() / "python"
145
153
 
154
+ def get_runners(self) -> dict[str, RunnerConfig]:
155
+ """The `test` runner, when the app declares the image its tests belong in.
156
+
157
+ Declared, never guessed: `test: {image: develop}` in `.wex/config.yml`
158
+ names an entry of `docker.images`, and the tests then run in a container of
159
+ that image rather than in the host's venv. The host is not what ships — an
160
+ app rendering through system libraries and fonts passes or fails on what
161
+ the image holds, not on what happens to be installed here.
162
+
163
+ The runner only runs the image, never builds it: `docker.images` builds
164
+ come in chains (`develop` on `release` on `base`) that `app::image/build`
165
+ resolves and a single Dockerfile would not.
166
+ """
167
+ from wexample_runner.runner_config import RunnerConfig
168
+
169
+ tag = self._get_test_image_tag()
170
+ if tag is None:
171
+ return {}
172
+
173
+ return {
174
+ PYTHON_TEST_RUNNER_NAME: RunnerConfig(
175
+ image_name=tag,
176
+ container_workdir=self._get_test_container_path(),
177
+ # Kept alive between execs whatever the image's own CMD does: a
178
+ # `bash` CMD exits at once in a detached container.
179
+ command=["sleep", "infinity"],
180
+ )
181
+ }
182
+
146
183
  def get_src_import_name(self) -> str | None:
147
184
  """Name of the Python module under `src/` for distribution-time
148
185
  wiring (pyproject `tool.pdm.build.packages`, `tool.coverage.run.source`,
@@ -374,23 +411,17 @@ class PythonWorkdir(
374
411
  def test_get_command(
375
412
  self, format: str = PYTHON_PYTEST_COV_FORMAT_JSON
376
413
  ) -> list[str]:
377
- cmd = self.get_python_exec_module_command("pytest")
378
- # The json report is always produced: it feeds test.coverage.last_report.
379
- # The requested format is added as an extra view when it differs.
380
- cmd.extend(
381
- [
382
- "--cov",
383
- f"--cov-report={PYTHON_PYTEST_COV_FORMAT_JSON}",
384
- ]
385
- )
386
- if format != PYTHON_PYTEST_COV_FORMAT_JSON:
387
- cmd.append(f"--cov-report={format}")
388
-
389
- return cmd
414
+ return [
415
+ *self.get_python_exec_module_command("pytest"),
416
+ *self._get_pytest_arguments(format=format),
417
+ ]
390
418
 
391
419
  def test_run(self, format: str | None = None) -> None:
392
420
  format = format or PYTHON_PYTEST_COV_FORMAT_JSON
393
- self.shell_run_for_app(cmd=self.test_get_command(format=format))
421
+ if self._get_test_image_tag() is None:
422
+ self.shell_run_for_app(cmd=self.test_get_command(format=format))
423
+ else:
424
+ self._test_run_in_image(format=format)
394
425
 
395
426
  # pytest-cov writes no report at all when nothing was measured
396
427
  # (e.g. tests that never import the covered module) — a legitimate
@@ -644,6 +675,14 @@ class PythonWorkdir(
644
675
  def _get_iml_file_class(self) -> type[ImlFile]:
645
676
  return PythonAppImlFile
646
677
 
678
+ def _get_pytest_arguments(self, format: str) -> list[str]:
679
+ # The json report is always produced: it feeds test.coverage.last_report.
680
+ # The requested format is added as an extra view when it differs.
681
+ arguments = ["--cov", f"--cov-report={PYTHON_PYTEST_COV_FORMAT_JSON}"]
682
+ if format != PYTHON_PYTEST_COV_FORMAT_JSON:
683
+ arguments.append(f"--cov-report={format}")
684
+ return arguments
685
+
647
686
  def _get_source_code_directories(self) -> [TargetFileOrDirectoryType]:
648
687
  src = self.find_by_name(PATH_DIR_SRC)
649
688
 
@@ -660,6 +699,26 @@ class PythonWorkdir(
660
699
 
661
700
  return []
662
701
 
702
+ def _get_test_container_path(self) -> str:
703
+ return f"/opt/{self.get_path().name}"
704
+
705
+ def _get_test_image_name(self) -> str | None:
706
+ test_config = self.get_runtime_app_config().get("test") or {}
707
+ return test_config.get("image")
708
+
709
+ def _get_test_image_tag(self) -> str | None:
710
+ name = self._get_test_image_name()
711
+ if name is None:
712
+ return None
713
+
714
+ images = (self.get_runtime_app_config().get("docker") or {}).get("images") or {}
715
+ if name not in images:
716
+ raise ValueError(
717
+ f"`test.image: {name}` names no entry of `docker.images` in "
718
+ f".wex/config.yml (known: {', '.join(sorted(images)) or 'none'})."
719
+ )
720
+ return images[name]["tag"]
721
+
663
722
  def _init_listeners(self) -> None:
664
723
  """Add event listeners"""
665
724
  self.operation_add_event_listener(
@@ -685,3 +744,35 @@ class PythonWorkdir(
685
744
 
686
745
  def _on_test_event(self, event: Event) -> None:
687
746
  self.success("A python file has been renamed")
747
+
748
+ def _test_run_in_image(self, format: str) -> None:
749
+ import sys
750
+
751
+ from wexample_helpers.helper.docker import docker_image_exists
752
+
753
+ tag = self._get_test_image_tag()
754
+ if not docker_image_exists(tag):
755
+ name = self._get_test_image_name()
756
+ raise RuntimeError(
757
+ f"The tests run in image {tag} (`test.image: {name}`), which is not "
758
+ f"built. Build it with `wex app::image/build --name {name}`."
759
+ )
760
+
761
+ container_path = self._get_test_container_path()
762
+ result = self.runner_exec(
763
+ PYTHON_TEST_RUNNER_NAME,
764
+ ["python", "-m", "pytest", *self._get_pytest_arguments(format=format)],
765
+ # The mounted sources ahead of the copy baked into the image at build
766
+ # time: nothing to install, and nothing that needs root to install it.
767
+ env={"PYTHONPATH": f"{container_path}/{PATH_DIR_SRC}"},
768
+ )
769
+
770
+ # Written raw rather than through io: pytest output is not markup, and a
771
+ # `@name{` in a test id or an assertion would be parsed as a directive.
772
+ sys.stdout.write(result.stdout)
773
+ sys.stderr.write(result.stderr)
774
+
775
+ if result.exit_code != 0:
776
+ raise RuntimeError(
777
+ f"Tests failed in image {tag} (exit code {result.exit_code})."
778
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wexample-wex-addon-dev-python
3
- Version: 15.0.4
3
+ Version: 15.1.1
4
4
  Summary: Extends wex with commands to format, lint, and rename Python symbols, plus workdir types for Python packages and suites
5
5
  Author-Email: weeger <contact@wexample.com>
6
6
  License: MIT
@@ -19,8 +19,8 @@ Requires-Dist: pylint
19
19
  Requires-Dist: pyright
20
20
  Requires-Dist: wexample-api>=6.8.0
21
21
  Requires-Dist: wexample-filestate-python>=9.1.0
22
- Requires-Dist: wexample-wex-addon-ai>=17.0.0
23
- Requires-Dist: wexample-wex-addon-app>=32.4.0
22
+ Requires-Dist: wexample-wex-addon-ai>=18.1.0
23
+ Requires-Dist: wexample-wex-addon-app>=33.0.0
24
24
  Provides-Extra: dev
25
25
  Requires-Dist: pytest; extra == "dev"
26
26
  Requires-Dist: pytest-cov; extra == "dev"
@@ -28,7 +28,7 @@ Description-Content-Type: text/markdown
28
28
 
29
29
  # wex_addon_dev_python
30
30
 
31
- Version: 15.0.4
31
+ Version: 15.1.1
32
32
 
33
33
  `wex_addon_dev_python` extends the wex CLI with a `python::` command group that formats source files with isort and black (`python::code/format`), checks them with mypy, pylint, and pyright (`python::code/check`), and renames Python symbols — packages, modules, classes, functions, constants — while propagating every affected import statement across the workdir (`python::code/rename`). It also ships `PythonPackageWorkdir` and `PythonPackagesSuiteWorkdir`, two workdir types that let wex manage a single PDM-based package or a multi-package suite as a first-class project structure. The intended users are wex operators who develop and maintain Python packages within the wexample ecosystem.
34
34
 
@@ -258,8 +258,8 @@ Visit the [Wexample Suite documentation](https://docs.wexample.com) for the comp
258
258
  - pyright:
259
259
  - wexample-api: >=6.8.0
260
260
  - wexample-filestate-python: >=9.1.0
261
- - wexample-wex-addon-ai: >=17.0.0
262
- - wexample-wex-addon-app: >=32.4.0
261
+ - wexample-wex-addon-ai: >=18.1.0
262
+ - wexample-wex-addon-app: >=33.0.0
263
263
 
264
264
  ## Versioning & Compatibility Policy
265
265
 
@@ -1,6 +1,6 @@
1
- wexample_wex_addon_dev_python-15.0.4.dist-info/METADATA,sha256=B-8EyYxQ2Fgc6eRAu_O-Y-s-wRy8L51D6Vkc1cGYx7s,17482
2
- wexample_wex_addon_dev_python-15.0.4.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
3
- wexample_wex_addon_dev_python-15.0.4.dist-info/entry_points.txt,sha256=4WCjdYUa09eJPSM1ahhnId0BTg7ncgmLgeKtfKjuUy4,127
1
+ wexample_wex_addon_dev_python-15.1.1.dist-info/METADATA,sha256=cG_6C63cgzIn2hx_wqcz4GKbkpOigL5SklOTF2aFMPQ,17482
2
+ wexample_wex_addon_dev_python-15.1.1.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
3
+ wexample_wex_addon_dev_python-15.1.1.dist-info/entry_points.txt,sha256=4WCjdYUa09eJPSM1ahhnId0BTg7ncgmLgeKtfKjuUy4,127
4
4
  wexample_wex_addon_dev_python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  wexample_wex_addon_dev_python/__pycache__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  wexample_wex_addon_dev_python/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -28,7 +28,7 @@ wexample_wex_addon_dev_python/config_value/python_package_readme_config_value.py
28
28
  wexample_wex_addon_dev_python/const/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  wexample_wex_addon_dev_python/const/__pycache__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  wexample_wex_addon_dev_python/const/package.py,sha256=oRCPhaazJp5TujxF-35rrIYA4FJsqMqCns8lOFKOLeA,451
31
- wexample_wex_addon_dev_python/const/python.py,sha256=jxdPt5CnD0dcp4SmobEc_c7XcCkPFfX_lk3SVHsiVpM,203
31
+ wexample_wex_addon_dev_python/const/python.py,sha256=swBdTT6GHCZMdFMBLL0eiqt1PKZUwyRCqEpBYbKcvEo,330
32
32
  wexample_wex_addon_dev_python/const/tags.py,sha256=isvxhaBbendC6k_rluiJkQ2-yO7OwCEw9wse4wgEOIo,338
33
33
  wexample_wex_addon_dev_python/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  wexample_wex_addon_dev_python/file/__pycache__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -92,5 +92,5 @@ wexample_wex_addon_dev_python/workdir/mixin/__init__.py,sha256=47DEQpj8HBSa-_TIm
92
92
  wexample_wex_addon_dev_python/workdir/mixin/with_profiling_python_workdir_mixin.py,sha256=PA_kqwe2kF5t1nKakX5Q-6fant2R18aEnZfkjr6iJ6k,3097
93
93
  wexample_wex_addon_dev_python/workdir/python_package_workdir.py,sha256=VJDIuJ-WrebCMt4TGRisHfQfyaj-XXoW9AgCioEWt5k,19609
94
94
  wexample_wex_addon_dev_python/workdir/python_packages_suite_workdir.py,sha256=7Jb5mKGNV2RjFtrFhUm6jbkiTfLDmy7sA97UGHITVdw,2902
95
- wexample_wex_addon_dev_python/workdir/python_workdir.py,sha256=6OQlv1EMAZL3a_o_aP8eShCWiXak-TEDrRonlhH4EFw,28220
96
- wexample_wex_addon_dev_python-15.0.4.dist-info/RECORD,,
95
+ wexample_wex_addon_dev_python/workdir/python_workdir.py,sha256=NTqtMa88LW4MVDj_ndf0aVibQUl2mrNmewW1q4IjJu0,32061
96
+ wexample_wex_addon_dev_python-15.1.1.dist-info/RECORD,,