wexample-wex-addon-dev-python 15.2.1__py3-none-any.whl → 15.3.0__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.
@@ -39,12 +39,22 @@ class PypiRegistryGateway(AbstractGateway):
39
39
  def has_version(self, package: str, version: str) -> bool:
40
40
  """Return True iff `package==version` is published on this index.
41
41
 
42
- Uses the PEP 503 Simple index and matches the version string against
43
- the HTML body. Returns False on 404 (unknown package, or version not
44
- yet propagated through the registry's CDN).
42
+ Uses the Simple index and matches the version string against its
43
+ body. Returns False on 404 (unknown package, or version not yet
44
+ propagated through the registry's CDN).
45
+
46
+ Asked for exactly as pip asks for it: PyPI's CDN caches each
47
+ representation of the page apart, and they do not refresh together.
48
+ The gzipped HTML one stayed without a release for over ten minutes
49
+ after pip's JSON one listed it, so a check reading the former waited
50
+ on a version pip could already install.
45
51
  """
46
52
  response = self.make_request(
47
53
  endpoint=f"simple/{package}/",
54
+ headers={
55
+ "Accept": "application/vnd.pypi.simple.v1+json, "
56
+ "application/vnd.pypi.simple.v1+html; q=0.1, text/html; q=0.01",
57
+ },
48
58
  expected_status_codes=_HAS_VERSION_STATUS_CODES,
49
59
  fatal_if_unexpected=False,
50
60
  quiet=True,
@@ -0,0 +1,4 @@
1
+ include:
2
+ - remote: 'https://gitlab.wexample.com/wexample-public/ci-cd/-/raw/main/.gitlab-ci.type.python.package.yml'
3
+ variables:
4
+ MAIN_BRANCH_NAME: main
@@ -58,6 +58,18 @@ class PythonPackageWorkdir(PythonWorkdir):
58
58
  "Install: pipx install pdm — then run: wex core::env/configure"
59
59
  )
60
60
 
61
+ def get_gitlab_registry_url(self) -> str | None:
62
+ """The GitLab PyPI registry of the group, when the suite publishes there.
63
+
64
+ `python.gitlab_registry.url`, the group's endpoint without `/simple`:
65
+ `https://gitlab.example.com/api/v4/groups/<group>/-/packages/pypi`.
66
+ Installs read its `/simple` index; each package uploads to its own
67
+ project's registry, which the group one gathers.
68
+ """
69
+ return self.search_app_or_suite_runtime_config(
70
+ "python.gitlab_registry.url", default=None
71
+ ).get_str_or_none()
72
+
61
73
  def get_required_knowledge_pages(self) -> dict[str, str]:
62
74
  return {
63
75
  **super().get_required_knowledge_pages(),
@@ -77,22 +89,28 @@ class PythonPackageWorkdir(PythonWorkdir):
77
89
  raw_value = super().prepare_value(raw_value=raw_value)
78
90
  children = raw_value.get("children")
79
91
 
80
- # Add .gitlab-ci.yml for private GitLab registry packages.
81
- # Both callbacks are evaluated after configure() completes, so base_name
82
- # and runtime config are fully available at that point.
92
+ # Every package is tested by GitLab at each push, the way a consumer
93
+ # installs it: the file only includes the job, which lives in the ci-cd
94
+ # repository. A package published to the private GitLab registry gets
95
+ # the job publishing it on a tag instead, and no tests: the base
96
+ # template's workflow runs no tag pipeline. Created when absent, never
97
+ # rewritten. The callback is evaluated after configure() completes, so
98
+ # the runtime config is available at that point.
83
99
  children.append(
84
100
  {
85
101
  "name": ".gitlab-ci.yml",
86
102
  "type": DiskItemType.FILE,
87
- "should_exist": lambda _target, _self=self: bool(
88
- _self.search_app_or_suite_runtime_config(
89
- "pdm.repository.url", default=None
90
- ).get_str_or_none()
91
- ),
92
- "default_content": lambda _: file_read(
103
+ "should_exist": True,
104
+ "default_content": lambda _, _self=self: file_read(
93
105
  module_get_path(wexample_wex_addon_dev_python)
94
106
  / "resources"
95
- / "package_publish_gitlab.yml"
107
+ / (
108
+ "package_publish_gitlab.yml"
109
+ if _self.search_app_or_suite_runtime_config(
110
+ "pdm.repository.url", default=None
111
+ ).get_str_or_none()
112
+ else "package_gitlab_ci.yml"
113
+ )
96
114
  ),
97
115
  }
98
116
  )
@@ -414,8 +432,9 @@ class PythonPackageWorkdir(PythonWorkdir):
414
432
  self.push_to_deployment_remote(branch_name=GIT_BRANCH_MAIN)
415
433
 
416
434
  def _publish(self, force: bool = False) -> None:
417
- from wexample_filestate_python.common.pipy_gateway import PipyGateway
418
- from wexample_helpers.helper.shell import shell_run
435
+ from wexample_helpers.exception.shell_command_failed_exception import (
436
+ ShellCommandFailedException,
437
+ )
419
438
  from wexample_helpers_git.helper.git import (
420
439
  git_push_tag,
421
440
  git_tag_annotated,
@@ -443,10 +462,75 @@ class PythonPackageWorkdir(PythonWorkdir):
443
462
  git_push_tag(tag, cwd=cwd, remote=remote, inherit_stdio=True)
444
463
  return
445
464
 
446
- # TODO: align public PyPI packages with the private registry approach — publish
447
- # via a GitLab CI pipeline triggered by a git tag rather than running
448
- # `pdm publish` locally.
449
- # PyPI public: publish locally
465
+ # Our own registry first, where the release counts: what installs read
466
+ # (wex, the apps) and what the publication waits for. PyPI then only
467
+ # mirrors it, and a refusal there no longer stops the suite.
468
+ if self.get_gitlab_registry_url():
469
+ self._publish_to_gitlab_registry(force=force)
470
+ try:
471
+ self._publish_to_pypi(force=force)
472
+ except ShellCommandFailedException as exception:
473
+ self.warning(
474
+ f"PyPI refused {package_name} {version}, published on the GitLab "
475
+ f"registry all the same: {exception}"
476
+ )
477
+ return
478
+
479
+ self._publish_to_pypi(force=force)
480
+
481
+ def _publish_to_gitlab_registry(self, force: bool = False) -> None:
482
+ import re
483
+ from urllib.parse import quote
484
+
485
+ from wexample_helpers.helper.shell import shell_run
486
+ from wexample_helpers_git.helper.git import git_get_remote_url
487
+
488
+ from wexample_wex_addon_dev_python.common.pypi_registry_gateway import (
489
+ PypiRegistryGateway,
490
+ )
491
+
492
+ package_name = self.get_package_name()
493
+ version = self.get_setup_version()
494
+ registry_url = self.get_gitlab_registry_url()
495
+
496
+ index = PypiRegistryGateway(base_url=registry_url, io=self.io, timeout=10)
497
+ if index.has_version(package_name, version) and not force:
498
+ self.log(f"{package_name} {version} is already on the GitLab registry.")
499
+ return
500
+
501
+ # The project is the package's origin: ssh://git@host:port/<group>/<name>.git
502
+ project_path = re.sub(
503
+ r"^(ssh://[^/]+/|git@[^:]+:|https?://[^/]+/)",
504
+ "",
505
+ git_get_remote_url(cwd=self.get_path()),
506
+ ).removesuffix(".git")
507
+ project = quote(project_path, safe="")
508
+ api_url = registry_url.split("/groups/", 1)[0]
509
+
510
+ self.subtitle("Publishing to the GitLab registry")
511
+ shell_run(
512
+ [
513
+ "pdm",
514
+ "publish",
515
+ "--repository",
516
+ f"{api_url}/projects/{project}/packages/pypi",
517
+ # GitLab authenticates the token alone; the name is required, not read.
518
+ "--username",
519
+ "__token__",
520
+ "--password",
521
+ self.get_env_parameter_or_suite_fallback("GITLAB_API_TOKEN"),
522
+ ],
523
+ inherit_stdio=True,
524
+ cwd=self.get_path(),
525
+ )
526
+
527
+ def _publish_to_pypi(self, force: bool = False) -> None:
528
+ from wexample_filestate_python.common.pipy_gateway import PipyGateway
529
+ from wexample_helpers.helper.shell import shell_run
530
+
531
+ package_name = self.get_package_name()
532
+ version = self.get_setup_version()
533
+
450
534
  client = PipyGateway(parent_io_handler=self)
451
535
  if client.package_release_exists(package_name=package_name, version=version):
452
536
  self.warning(
@@ -487,8 +571,12 @@ class PythonPackageWorkdir(PythonWorkdir):
487
571
  PypiRegistryGateway,
488
572
  )
489
573
 
574
+ # The GitLab registry, when the suite publishes there, is what installs
575
+ # read: it serves a version as soon as it is uploaded, where PyPI's CDN
576
+ # can lag for many minutes.
490
577
  repository_url = (
491
- self.search_app_or_suite_runtime_config(
578
+ self.get_gitlab_registry_url()
579
+ or self.search_app_or_suite_runtime_config(
492
580
  "pdm.repository.url", default=None
493
581
  ).get_str_or_none()
494
582
  or "https://pypi.org"
@@ -476,6 +476,23 @@ class PythonWorkdir(
476
476
 
477
477
  pyproject_path = self.get_path() / "pyproject.toml"
478
478
 
479
+ # The suite's GitLab registry beside PyPI: the wexample packages are
480
+ # there first. Written into requirements.txt, so `pip install -r` reads
481
+ # it too. Best match across both, as pip does: a package published
482
+ # before the registry existed is only on PyPI.
483
+ index_arguments: list[str] = []
484
+ registry_url = self.search_app_or_suite_runtime_config(
485
+ "python.gitlab_registry.url", default=None
486
+ ).get_str_or_none()
487
+ if registry_url:
488
+ index_arguments = [
489
+ "--extra-index-url",
490
+ f"{registry_url}/simple",
491
+ "--index-strategy",
492
+ "unsafe-best-match",
493
+ "--emit-index-url",
494
+ ]
495
+
479
496
  def _run_uv_compile() -> None:
480
497
  result = subprocess.run(
481
498
  [
@@ -494,6 +511,7 @@ class PythonWorkdir(
494
511
  # long as they satisfy constraints — causing stale
495
512
  # transitives even after their direct dependents bumped.
496
513
  "--upgrade",
514
+ *index_arguments,
497
515
  ],
498
516
  capture_output=True,
499
517
  text=True,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wexample-wex-addon-dev-python
3
- Version: 15.2.1
3
+ Version: 15.3.0
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
@@ -20,7 +20,7 @@ Requires-Dist: pyright
20
20
  Requires-Dist: wexample-api>=6.8.0
21
21
  Requires-Dist: wexample-filestate-python>=9.1.0
22
22
  Requires-Dist: wexample-wex-addon-ai>=19.0.0
23
- Requires-Dist: wexample-wex-addon-app>=34.0.0
23
+ Requires-Dist: wexample-wex-addon-app>=34.1.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.2.1
31
+ Version: 15.3.0
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
 
@@ -257,7 +257,7 @@ The suite includes packages for configuration management, file handling, prompts
257
257
  - wexample-api: >=6.8.0
258
258
  - wexample-filestate-python: >=9.1.0
259
259
  - wexample-wex-addon-ai: >=19.0.0
260
- - wexample-wex-addon-app: >=34.0.0
260
+ - wexample-wex-addon-app: >=34.1.0
261
261
 
262
262
  ## Versioning & Compatibility Policy
263
263
 
@@ -1,6 +1,6 @@
1
- wexample_wex_addon_dev_python-15.2.1.dist-info/METADATA,sha256=PjUNzyCjiV7GgYImPKLk-Y5Dv_eB43IAkiEQNpQWLtU,17370
2
- wexample_wex_addon_dev_python-15.2.1.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
3
- wexample_wex_addon_dev_python-15.2.1.dist-info/entry_points.txt,sha256=4WCjdYUa09eJPSM1ahhnId0BTg7ncgmLgeKtfKjuUy4,127
1
+ wexample_wex_addon_dev_python-15.3.0.dist-info/METADATA,sha256=ePyMaHRkUqiSlqk40I7iXcn4V3pzSU8IAEZfjUYcCH0,17370
2
+ wexample_wex_addon_dev_python-15.3.0.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
3
+ wexample_wex_addon_dev_python-15.3.0.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
@@ -21,7 +21,7 @@ wexample_wex_addon_dev_python/commands/examples/utils/some_example_type.py,sha25
21
21
  wexample_wex_addon_dev_python/commands/examples/validate.py,sha256=Ab_rIX2XElVSLLGypNPsuxRX6100vsfffaUaPgRV_wc,917
22
22
  wexample_wex_addon_dev_python/commands/release/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  wexample_wex_addon_dev_python/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- wexample_wex_addon_dev_python/common/pypi_registry_gateway.py,sha256=uGsbQcVACsYur673HXvMVqUOjDFyBJK2X4twfkrVaoM,1994
24
+ wexample_wex_addon_dev_python/common/pypi_registry_gateway.py,sha256=U-E21T_244IX66HKFFa2bwX1U6vxSgOfjZBPLh2Ku_s,2511
25
25
  wexample_wex_addon_dev_python/config_value/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  wexample_wex_addon_dev_python/config_value/__pycache__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  wexample_wex_addon_dev_python/config_value/python_package_readme_config_value.py,sha256=Teq9-j7NCXsZpkxAM9FHilV7fL_BtQS70xmIFRJWCGc,1865
@@ -61,6 +61,7 @@ wexample_wex_addon_dev_python/resources/ai/agents/describer/agent.yml,sha256=afT
61
61
  wexample_wex_addon_dev_python/resources/ai/agents/describer/context.j2,sha256=OTFLDQhKikePO20fRviui74Upwiyp42bMi6KPw_h1ws,2026
62
62
  wexample_wex_addon_dev_python/resources/design_rules/python_code.md,sha256=Xl6oGZnhuWIzmlcCI49p6SJmLFaQAQeGpr4hqjquWC4,974
63
63
  wexample_wex_addon_dev_python/resources/docker/Dockerfile.python-profiling,sha256=5ujzXfWNN2nv8qQzCLel6dlOwLQ1XhIGZuqplCNB_vQ,290
64
+ wexample_wex_addon_dev_python/resources/package_gitlab_ci.yml,sha256=X2aaKG710DyiWlMaeO1sMHs8YbtRDOj_1kMROKdS4s8,155
64
65
  wexample_wex_addon_dev_python/resources/package_publish_gitlab.yml,sha256=WVMj-DeFedQak5s5FraEnM1Rx1-ut4KgPodvAVv25ZM,304
65
66
  wexample_wex_addon_dev_python/resources/readme_templates/install.md.j2,sha256=PDfD-2_HQXKtgq8seSRDL5SGbZ2BRrxDEKoFpO7qhb8,104
66
67
  wexample_wex_addon_dev_python/resources/readme_templates/tests.md.j2,sha256=tKLcDwx7jhQkryXIxWr12AK-hKEaP6Rusu2MrluiABs,1289
@@ -90,7 +91,7 @@ wexample_wex_addon_dev_python/workdir/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCe
90
91
  wexample_wex_addon_dev_python/workdir/__pycache__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
92
  wexample_wex_addon_dev_python/workdir/mixin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
92
93
  wexample_wex_addon_dev_python/workdir/mixin/with_profiling_python_workdir_mixin.py,sha256=PA_kqwe2kF5t1nKakX5Q-6fant2R18aEnZfkjr6iJ6k,3097
93
- wexample_wex_addon_dev_python/workdir/python_package_workdir.py,sha256=VJDIuJ-WrebCMt4TGRisHfQfyaj-XXoW9AgCioEWt5k,19609
94
+ wexample_wex_addon_dev_python/workdir/python_package_workdir.py,sha256=zxPagcd9CvYc0nvX6Ry7kJj_0VLcI7fmvBAisvDQy4M,23310
94
95
  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=NTqtMa88LW4MVDj_ndf0aVibQUl2mrNmewW1q4IjJu0,32061
96
- wexample_wex_addon_dev_python-15.2.1.dist-info/RECORD,,
96
+ wexample_wex_addon_dev_python/workdir/python_workdir.py,sha256=1t4k3GX-3aNaV4aUb-NSstlDNtwPvmeGolPs9g3laI8,32833
97
+ wexample_wex_addon_dev_python-15.3.0.dist-info/RECORD,,