mitol-release-tools 2026.11.6__tar.gz
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.
- mitol_release_tools-2026.11.6/.gitignore +83 -0
- mitol_release_tools-2026.11.6/PKG-INFO +125 -0
- mitol_release_tools-2026.11.6/README.md +107 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/__init__.py +3 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/apps.py +262 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/changelog.py +189 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/changes.py +180 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/cli.py +60 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/config.py +165 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/decorators.py +78 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/init.py +600 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/project.py +20 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/publish.py +81 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/py.typed +0 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/release.py +76 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/templates/entry_title.md.j2 +1 -0
- mitol_release_tools-2026.11.6/mitol/release_tools/version.py +72 -0
- mitol_release_tools-2026.11.6/pyproject.toml +52 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Temporary Python files
|
|
2
|
+
*.pyc
|
|
3
|
+
*.egg-info
|
|
4
|
+
__pycache__
|
|
5
|
+
.ipynb_checkpoints
|
|
6
|
+
|
|
7
|
+
# Temporary OS files
|
|
8
|
+
Icon*
|
|
9
|
+
|
|
10
|
+
# Temporary virtual environment files
|
|
11
|
+
.cache/
|
|
12
|
+
*venv/
|
|
13
|
+
|
|
14
|
+
# Temporary server files
|
|
15
|
+
.env
|
|
16
|
+
*.pid
|
|
17
|
+
|
|
18
|
+
# Testing and coverage results
|
|
19
|
+
.coverage
|
|
20
|
+
.coverage.*
|
|
21
|
+
coverage.*
|
|
22
|
+
htmlcov/
|
|
23
|
+
|
|
24
|
+
# Build and release directories
|
|
25
|
+
build/
|
|
26
|
+
dist/
|
|
27
|
+
*.spec
|
|
28
|
+
|
|
29
|
+
# Sublime Text
|
|
30
|
+
*.sublime-workspace
|
|
31
|
+
|
|
32
|
+
# Eclipse
|
|
33
|
+
.settings
|
|
34
|
+
|
|
35
|
+
# Pycharm/IDEA
|
|
36
|
+
.idea/
|
|
37
|
+
|
|
38
|
+
# OSX
|
|
39
|
+
*.DS_Store
|
|
40
|
+
|
|
41
|
+
# vscode
|
|
42
|
+
.vscode/
|
|
43
|
+
|
|
44
|
+
#pyenv
|
|
45
|
+
.python-version
|
|
46
|
+
|
|
47
|
+
# pytest
|
|
48
|
+
.pytest_cache/
|
|
49
|
+
|
|
50
|
+
# tox
|
|
51
|
+
.tox
|
|
52
|
+
coverage/
|
|
53
|
+
|
|
54
|
+
# poetry
|
|
55
|
+
pip-wheel-metadata/
|
|
56
|
+
setup.py
|
|
57
|
+
|
|
58
|
+
# django
|
|
59
|
+
db.sqlite3
|
|
60
|
+
testapp/settings/dev.py
|
|
61
|
+
|
|
62
|
+
# mypy
|
|
63
|
+
.mypy_cache/
|
|
64
|
+
|
|
65
|
+
# Pants workspace files
|
|
66
|
+
/.pants.d/
|
|
67
|
+
/dist/
|
|
68
|
+
/.pids
|
|
69
|
+
/.pants.workdir.file_lock*
|
|
70
|
+
*.pex
|
|
71
|
+
|
|
72
|
+
.claude/
|
|
73
|
+
|
|
74
|
+
# drf-lint project index cache
|
|
75
|
+
.drf_lint_cache.json
|
|
76
|
+
|
|
77
|
+
# mitol-django-benchmark
|
|
78
|
+
.bench/
|
|
79
|
+
benchmarks/benchmark.local.toml
|
|
80
|
+
# Exported OTel traces are production data and are never committed. Only the
|
|
81
|
+
# distilled benchmarks/*.baseline.json belongs in the repository.
|
|
82
|
+
traces/
|
|
83
|
+
*.trace.json
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mitol-release-tools
|
|
3
|
+
Version: 2026.11.6
|
|
4
|
+
Summary: Changelog, version and PyPI release management for a monorepo of Python packages
|
|
5
|
+
Project-URL: Repository, https://github.com/mitodl/ol-django
|
|
6
|
+
Author-email: MIT Open Learning Engineering <odl-devops@mit.edu>
|
|
7
|
+
License-Expression: BSD-3-Clause
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: bumpver>=2026.1132
|
|
10
|
+
Requires-Dist: certifi>=2026.10.19
|
|
11
|
+
Requires-Dist: click-log>=0.4.0
|
|
12
|
+
Requires-Dist: click>=8.5.0
|
|
13
|
+
Requires-Dist: cloup>=4.0.0
|
|
14
|
+
Requires-Dist: gitpython>=3.1.62
|
|
15
|
+
Requires-Dist: scriv[toml]>=1.8.0
|
|
16
|
+
Requires-Dist: tomlkit>=0.13.3
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# mitol-release-tools
|
|
20
|
+
|
|
21
|
+
Changelog, version and PyPI release management for Python packages, as
|
|
22
|
+
`ol-release`. Works on a monorepo of many packages or on a repository that is
|
|
23
|
+
a single package.
|
|
24
|
+
|
|
25
|
+
The model is that **a release is a version change merged to the default
|
|
26
|
+
branch**. Nothing is tagged or uploaded by hand: CI compares each package's
|
|
27
|
+
`[project] version` against PyPI and publishes whatever is missing there.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
ol-release init bootstrap a repo for the commands below
|
|
31
|
+
ol-release changelog create --app X write a new changelog fragment
|
|
32
|
+
ol-release changelog check fail a PR with missing or misplaced fragments
|
|
33
|
+
ol-release version check fail a PR whose version declarations disagree
|
|
34
|
+
ol-release prepare --app X bump the version and collect the fragments
|
|
35
|
+
ol-release publish matrix emit the packages that are not yet on PyPI
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Layout
|
|
39
|
+
|
|
40
|
+
A repository that is one package says so, and gets the conventions that come
|
|
41
|
+
with that - tags without a package prefix, and `--app` optional since there is
|
|
42
|
+
only one answer:
|
|
43
|
+
|
|
44
|
+
```toml
|
|
45
|
+
[project]
|
|
46
|
+
name = "my-package"
|
|
47
|
+
version = "1.2.3"
|
|
48
|
+
|
|
49
|
+
[tool.ol-release]
|
|
50
|
+
layout = "single"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The default is `layout = "workspace"`, so a monorepo needs nothing. Layout is
|
|
54
|
+
stated rather than inferred: a repo can have both a root `[project]` and a
|
|
55
|
+
workspace, and guessing wrong changes what gets tagged and published.
|
|
56
|
+
|
|
57
|
+
`tag-format` overrides the default for either layout - `{name}/v{version}` for
|
|
58
|
+
a workspace, `v{version}` for a single package:
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
[tool.ol-release]
|
|
62
|
+
tag-format = "release-{version}"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
In single layout the whole repository is the package, so anything at the root
|
|
66
|
+
counts as a change to it - except `CHANGELOG.md`, `changelog.d/` and the
|
|
67
|
+
lockfile. `init` writes `.scriv/` and `changelog.d/` into that same tree, so
|
|
68
|
+
exclude both from your build backend's sdist and wheel configuration.
|
|
69
|
+
|
|
70
|
+
CI for a single-package repo builds with a bare `uv build`: `--package` only
|
|
71
|
+
means something inside a workspace and is rejected outside one.
|
|
72
|
+
|
|
73
|
+
## Where it looks for packages
|
|
74
|
+
|
|
75
|
+
In the default workspace layout, packages come from the uv workspace the repo
|
|
76
|
+
already declares, so there is no second place to keep that list in step:
|
|
77
|
+
|
|
78
|
+
```toml
|
|
79
|
+
[tool.uv.workspace]
|
|
80
|
+
members = ["src/*", "testapp"]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Each matching directory with a `pyproject.toml` is a package. `[tool.uv.workspace] exclude`
|
|
84
|
+
is honoured. Repos with no workspace table fall back to `src/*`.
|
|
85
|
+
|
|
86
|
+
What the workspace cannot say is which members are the tool's business, so:
|
|
87
|
+
|
|
88
|
+
```toml
|
|
89
|
+
[tool.ol-release]
|
|
90
|
+
exclude = ["uvtestapp", "testapp"]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
An excluded member is ignored entirely — no changelog required of it, no
|
|
94
|
+
version consistency enforced, never published. Separately, a package
|
|
95
|
+
classified `Private :: Do Not Upload` stays fully managed but is never offered
|
|
96
|
+
to `publish matrix`. Use the classifier for something whose changelog you still
|
|
97
|
+
want governed, and `exclude` for a directory the tool should not look at.
|
|
98
|
+
|
|
99
|
+
## Layout it expects
|
|
100
|
+
|
|
101
|
+
Per package: a `changelog.d/` of [scriv](https://scriv.readthedocs.io/)
|
|
102
|
+
fragments, a `CHANGELOG.md` carrying scriv's insert marker, and a
|
|
103
|
+
`[tool.bumpver]` table whose `file_patterns` name every file declaring the
|
|
104
|
+
version. Repo-wide: a shared entry-title template at `.scriv/entry_title.md.j2`.
|
|
105
|
+
|
|
106
|
+
`ol-release init` creates whatever is missing, and `init --check` reports it
|
|
107
|
+
without writing, which makes it usable as a CI step.
|
|
108
|
+
|
|
109
|
+
`--versioning date|semver` is needed only when a package has no
|
|
110
|
+
`[tool.bumpver]` table yet, and `init` asks for it by name when that is the
|
|
111
|
+
case. It is never inferred from the version: `2024.10.24` is a valid
|
|
112
|
+
`MAJOR.MINOR.PATCH` and a valid date both, so the string cannot say which
|
|
113
|
+
scheme produced it. A package that already has the table keeps the scheme
|
|
114
|
+
declared there. Run `init` once per scheme, scoped with `--app`, in a repo
|
|
115
|
+
whose packages disagree. Both are
|
|
116
|
+
idempotent and neither rewrites content it did not write.
|
|
117
|
+
|
|
118
|
+
Changelog fragments are markdown in every repository. A package that already
|
|
119
|
+
keeps a reStructuredText changelog keeps it: `init` adds a `CHANGELOG.md` that
|
|
120
|
+
links to it rather than converting it.
|
|
121
|
+
|
|
122
|
+
## Why click and not cyclopts
|
|
123
|
+
|
|
124
|
+
`ol-release version` and `ol-release changelog` re-export bumpver's and scriv's
|
|
125
|
+
own commands rather than reimplementing them, and those are click commands.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# mitol-release-tools
|
|
2
|
+
|
|
3
|
+
Changelog, version and PyPI release management for Python packages, as
|
|
4
|
+
`ol-release`. Works on a monorepo of many packages or on a repository that is
|
|
5
|
+
a single package.
|
|
6
|
+
|
|
7
|
+
The model is that **a release is a version change merged to the default
|
|
8
|
+
branch**. Nothing is tagged or uploaded by hand: CI compares each package's
|
|
9
|
+
`[project] version` against PyPI and publishes whatever is missing there.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
ol-release init bootstrap a repo for the commands below
|
|
13
|
+
ol-release changelog create --app X write a new changelog fragment
|
|
14
|
+
ol-release changelog check fail a PR with missing or misplaced fragments
|
|
15
|
+
ol-release version check fail a PR whose version declarations disagree
|
|
16
|
+
ol-release prepare --app X bump the version and collect the fragments
|
|
17
|
+
ol-release publish matrix emit the packages that are not yet on PyPI
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Layout
|
|
21
|
+
|
|
22
|
+
A repository that is one package says so, and gets the conventions that come
|
|
23
|
+
with that - tags without a package prefix, and `--app` optional since there is
|
|
24
|
+
only one answer:
|
|
25
|
+
|
|
26
|
+
```toml
|
|
27
|
+
[project]
|
|
28
|
+
name = "my-package"
|
|
29
|
+
version = "1.2.3"
|
|
30
|
+
|
|
31
|
+
[tool.ol-release]
|
|
32
|
+
layout = "single"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The default is `layout = "workspace"`, so a monorepo needs nothing. Layout is
|
|
36
|
+
stated rather than inferred: a repo can have both a root `[project]` and a
|
|
37
|
+
workspace, and guessing wrong changes what gets tagged and published.
|
|
38
|
+
|
|
39
|
+
`tag-format` overrides the default for either layout - `{name}/v{version}` for
|
|
40
|
+
a workspace, `v{version}` for a single package:
|
|
41
|
+
|
|
42
|
+
```toml
|
|
43
|
+
[tool.ol-release]
|
|
44
|
+
tag-format = "release-{version}"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
In single layout the whole repository is the package, so anything at the root
|
|
48
|
+
counts as a change to it - except `CHANGELOG.md`, `changelog.d/` and the
|
|
49
|
+
lockfile. `init` writes `.scriv/` and `changelog.d/` into that same tree, so
|
|
50
|
+
exclude both from your build backend's sdist and wheel configuration.
|
|
51
|
+
|
|
52
|
+
CI for a single-package repo builds with a bare `uv build`: `--package` only
|
|
53
|
+
means something inside a workspace and is rejected outside one.
|
|
54
|
+
|
|
55
|
+
## Where it looks for packages
|
|
56
|
+
|
|
57
|
+
In the default workspace layout, packages come from the uv workspace the repo
|
|
58
|
+
already declares, so there is no second place to keep that list in step:
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
[tool.uv.workspace]
|
|
62
|
+
members = ["src/*", "testapp"]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Each matching directory with a `pyproject.toml` is a package. `[tool.uv.workspace] exclude`
|
|
66
|
+
is honoured. Repos with no workspace table fall back to `src/*`.
|
|
67
|
+
|
|
68
|
+
What the workspace cannot say is which members are the tool's business, so:
|
|
69
|
+
|
|
70
|
+
```toml
|
|
71
|
+
[tool.ol-release]
|
|
72
|
+
exclude = ["uvtestapp", "testapp"]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
An excluded member is ignored entirely — no changelog required of it, no
|
|
76
|
+
version consistency enforced, never published. Separately, a package
|
|
77
|
+
classified `Private :: Do Not Upload` stays fully managed but is never offered
|
|
78
|
+
to `publish matrix`. Use the classifier for something whose changelog you still
|
|
79
|
+
want governed, and `exclude` for a directory the tool should not look at.
|
|
80
|
+
|
|
81
|
+
## Layout it expects
|
|
82
|
+
|
|
83
|
+
Per package: a `changelog.d/` of [scriv](https://scriv.readthedocs.io/)
|
|
84
|
+
fragments, a `CHANGELOG.md` carrying scriv's insert marker, and a
|
|
85
|
+
`[tool.bumpver]` table whose `file_patterns` name every file declaring the
|
|
86
|
+
version. Repo-wide: a shared entry-title template at `.scriv/entry_title.md.j2`.
|
|
87
|
+
|
|
88
|
+
`ol-release init` creates whatever is missing, and `init --check` reports it
|
|
89
|
+
without writing, which makes it usable as a CI step.
|
|
90
|
+
|
|
91
|
+
`--versioning date|semver` is needed only when a package has no
|
|
92
|
+
`[tool.bumpver]` table yet, and `init` asks for it by name when that is the
|
|
93
|
+
case. It is never inferred from the version: `2024.10.24` is a valid
|
|
94
|
+
`MAJOR.MINOR.PATCH` and a valid date both, so the string cannot say which
|
|
95
|
+
scheme produced it. A package that already has the table keeps the scheme
|
|
96
|
+
declared there. Run `init` once per scheme, scoped with `--app`, in a repo
|
|
97
|
+
whose packages disagree. Both are
|
|
98
|
+
idempotent and neither rewrites content it did not write.
|
|
99
|
+
|
|
100
|
+
Changelog fragments are markdown in every repository. A package that already
|
|
101
|
+
keeps a reStructuredText changelog keeps it: `init` adds a `CHANGELOG.md` that
|
|
102
|
+
links to it rather than converting it.
|
|
103
|
+
|
|
104
|
+
## Why click and not cyclopts
|
|
105
|
+
|
|
106
|
+
`ol-release version` and `ol-release changelog` re-export bumpver's and scriv's
|
|
107
|
+
own commands rather than reimplementing them, and those are click commands.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""Utilities around library django apps"""
|
|
2
|
+
|
|
3
|
+
from contextlib import chdir, contextmanager
|
|
4
|
+
from fnmatch import fnmatch
|
|
5
|
+
from functools import cache, cached_property
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import tomllib
|
|
9
|
+
from git import Commit
|
|
10
|
+
from mitol.release_tools import config
|
|
11
|
+
from mitol.release_tools.changes import Changes
|
|
12
|
+
from mitol.release_tools.project import PROJECT_ROOT, Project
|
|
13
|
+
|
|
14
|
+
#: The standard marker for a distribution that must never reach an index.
|
|
15
|
+
PRIVATE_CLASSIFIER = "Private :: Do Not Upload"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class NoPackagesError(Exception):
|
|
19
|
+
"""Raised when a command needs packages and discovery found none"""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class App:
|
|
23
|
+
module_name: str | None = None
|
|
24
|
+
project: Project | None = None
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def create(cls, project: Project, module_name: str):
|
|
28
|
+
app = App()
|
|
29
|
+
app.project = project
|
|
30
|
+
app.module_name = module_name
|
|
31
|
+
return app
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def pyproject(self):
|
|
35
|
+
with (self.absolute_path / "pyproject.toml").open("rb") as f:
|
|
36
|
+
return tomllib.load(f)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def name(self) -> str:
|
|
40
|
+
return self.pyproject["project"]["name"]
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def version(self) -> str:
|
|
44
|
+
return self.pyproject["project"]["version"]
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def version_git_tag(self):
|
|
48
|
+
"""The git tag for this app's current version
|
|
49
|
+
|
|
50
|
+
A monorepo has to say which package a tag belongs to; a
|
|
51
|
+
single-package repo conventionally does not. Either default can be
|
|
52
|
+
overridden with ``[tool.ol-release] tag-format``.
|
|
53
|
+
"""
|
|
54
|
+
settings = config.load()
|
|
55
|
+
template = settings.tag_format or config.TAG_FORMATS[settings.layout]
|
|
56
|
+
|
|
57
|
+
return template.format(name=self.name, version=self.version)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def is_private(self) -> bool:
|
|
61
|
+
"""Whether the distribution is marked as never to be uploaded
|
|
62
|
+
|
|
63
|
+
``Private :: Do Not Upload`` is the standard classifier for a package
|
|
64
|
+
that must not reach PyPI. It says nothing about whether the changelog
|
|
65
|
+
and version are managed, so it gates publishing only.
|
|
66
|
+
"""
|
|
67
|
+
classifiers = self.pyproject.get("project", {}).get("classifiers", [])
|
|
68
|
+
|
|
69
|
+
return PRIVATE_CLASSIFIER in classifiers
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def bumpver(self) -> dict:
|
|
73
|
+
"""The app's ``[tool.bumpver]`` table, empty when it has none
|
|
74
|
+
|
|
75
|
+
Discovery follows the uv workspace, which says nothing about whether a
|
|
76
|
+
member is set up for release, so an app without this table is a shape
|
|
77
|
+
the tool has to survive rather than crash on.
|
|
78
|
+
"""
|
|
79
|
+
return self.pyproject.get("tool", {}).get("bumpver", {})
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def version_files(self) -> list[str]:
|
|
83
|
+
"""App-relative paths of the files bumpver rewrites when the version changes
|
|
84
|
+
|
|
85
|
+
Read from ``[tool.bumpver.file_patterns]`` rather than assumed, because not
|
|
86
|
+
every app keeps its code under ``mitol/<appname>/`` (edx-api-client's is
|
|
87
|
+
``edx_api/``). Falls back to the pyproject alone for an app with no
|
|
88
|
+
bumpver table, which still declares its version there.
|
|
89
|
+
"""
|
|
90
|
+
return list(self.bumpver.get("file_patterns", ["pyproject.toml"]))
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def is_semver(self) -> bool:
|
|
94
|
+
"""Whether the app versions with MAJOR.MINOR.PATCH instead of a date"""
|
|
95
|
+
return "MAJOR" in self.bumpver.get("version_pattern", "")
|
|
96
|
+
|
|
97
|
+
@cached_property
|
|
98
|
+
def absolute_path(self) -> Path:
|
|
99
|
+
return get_app_dir(self.module_name).absolute()
|
|
100
|
+
|
|
101
|
+
@cached_property
|
|
102
|
+
def relative_path(self):
|
|
103
|
+
return self.absolute_path.relative_to(self.project.path)
|
|
104
|
+
|
|
105
|
+
@contextmanager
|
|
106
|
+
def with_app_dir(self):
|
|
107
|
+
with chdir(self.absolute_path):
|
|
108
|
+
yield
|
|
109
|
+
|
|
110
|
+
def get_changes(self, base_commit: Commit, target_commit: Commit) -> Changes:
|
|
111
|
+
return Changes.from_app_commits(
|
|
112
|
+
app=self, base_commit=base_commit, target_commit=target_commit
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def get_source_dir() -> Path:
|
|
117
|
+
"""Get the source directory
|
|
118
|
+
|
|
119
|
+
Retained for the common single-root layout; discovery itself goes through
|
|
120
|
+
the workspace members, which need not all sit under one directory.
|
|
121
|
+
"""
|
|
122
|
+
return PROJECT_ROOT / "src"
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _is_excluded(path: Path, patterns: tuple[str, ...]) -> bool:
|
|
126
|
+
"""Whether a root-relative path matches any uv workspace exclude pattern"""
|
|
127
|
+
return any(fnmatch(str(path), pattern) for pattern in patterns)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _discover() -> tuple[dict[str, Path], dict[str, list[Path]]]:
|
|
131
|
+
"""Map each package's directory name to its path, from the uv workspace"""
|
|
132
|
+
return _discover_in(PROJECT_ROOT)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@cache
|
|
136
|
+
def _discover_in(root: Path) -> tuple[dict[str, Path], dict[str, list[Path]]]:
|
|
137
|
+
"""Discover the packages under one repository root
|
|
138
|
+
|
|
139
|
+
Keyed on the root rather than cached bare, so that the memo cannot outlive
|
|
140
|
+
the root it was computed for.
|
|
141
|
+
|
|
142
|
+
Returns the mapping and, separately, any name claimed by more than one
|
|
143
|
+
member. Members may sit at different depths, so two can share a basename;
|
|
144
|
+
that is reported at lookup rather than raised here, because the ``--app``
|
|
145
|
+
choices are built at import and a raise would take ``--help`` with it.
|
|
146
|
+
"""
|
|
147
|
+
settings = config.load(root)
|
|
148
|
+
|
|
149
|
+
if settings.layout is config.Layout.SINGLE:
|
|
150
|
+
return _discover_single(root), {}
|
|
151
|
+
|
|
152
|
+
found: dict[str, Path] = {}
|
|
153
|
+
clashes: dict[str, list[Path]] = {}
|
|
154
|
+
|
|
155
|
+
for pattern in settings.members:
|
|
156
|
+
for path in sorted(root.glob(pattern)):
|
|
157
|
+
relative = path.relative_to(root)
|
|
158
|
+
|
|
159
|
+
# uv tolerates a member glob matching a file, or a directory with
|
|
160
|
+
# no pyproject.toml; neither is a package this tool can manage.
|
|
161
|
+
if (
|
|
162
|
+
not path.is_dir()
|
|
163
|
+
or not (path / "pyproject.toml").exists()
|
|
164
|
+
or _is_excluded(relative, settings.workspace_exclude)
|
|
165
|
+
or path.name in settings.exclude
|
|
166
|
+
):
|
|
167
|
+
continue
|
|
168
|
+
|
|
169
|
+
if path.name in found and found[path.name] != path:
|
|
170
|
+
clashes.setdefault(path.name, [found[path.name]]).append(path)
|
|
171
|
+
continue
|
|
172
|
+
|
|
173
|
+
found[path.name] = path
|
|
174
|
+
|
|
175
|
+
return found, clashes
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _discover_single(root: Path) -> dict[str, Path]:
|
|
179
|
+
"""Treat the repo root as the one package
|
|
180
|
+
|
|
181
|
+
Keyed on the distribution name rather than the directory name: the
|
|
182
|
+
directory is whatever the checkout happens to be called, which differs
|
|
183
|
+
between machines and CI runners and would make ``--app`` unreproducible.
|
|
184
|
+
"""
|
|
185
|
+
try:
|
|
186
|
+
with (root / "pyproject.toml").open("rb") as handle:
|
|
187
|
+
data = tomllib.load(handle)
|
|
188
|
+
except (OSError, tomllib.TOMLDecodeError, ValueError):
|
|
189
|
+
return {}
|
|
190
|
+
|
|
191
|
+
project = data.get("project")
|
|
192
|
+
name = project.get("name") if isinstance(project, dict) else None
|
|
193
|
+
|
|
194
|
+
# Same discipline as the config loader: this runs while `decorators` is
|
|
195
|
+
# being imported to build the --app choices, so anything unexpected has to
|
|
196
|
+
# mean "no packages" rather than take `ol-release --help` down with it.
|
|
197
|
+
return {name: root} if isinstance(name, str) and name else {}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def get_app_dir(name: str) -> Path:
|
|
201
|
+
"""Get the directory of a specific app"""
|
|
202
|
+
found, clashes = _discover()
|
|
203
|
+
|
|
204
|
+
if name in clashes:
|
|
205
|
+
listed = ", ".join(str(path) for path in clashes[name])
|
|
206
|
+
message = f"{name} matches more than one workspace member: {listed}"
|
|
207
|
+
raise ValueError(message)
|
|
208
|
+
|
|
209
|
+
if name not in found:
|
|
210
|
+
known = ", ".join(sorted(found)) or "none"
|
|
211
|
+
message = f"No such package: {name}. Found: {known}"
|
|
212
|
+
raise ValueError(message)
|
|
213
|
+
|
|
214
|
+
return found[name]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def list_app_paths() -> list[Path]:
|
|
218
|
+
"""List the packages in the repo
|
|
219
|
+
|
|
220
|
+
Empty rather than an error when nothing matches: the ``--app`` choices are
|
|
221
|
+
built at import time, so a repo root that declares no workspace - or no
|
|
222
|
+
repo root at all - would otherwise make ``--help`` unavailable.
|
|
223
|
+
"""
|
|
224
|
+
found, _ = _discover()
|
|
225
|
+
|
|
226
|
+
return sorted(found.values())
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def list_app_names() -> list[str]:
|
|
230
|
+
"""List the app names"""
|
|
231
|
+
return sorted(_discover()[0])
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def list_apps(project: Project) -> list[App]:
|
|
235
|
+
"""Get a list of App instances"""
|
|
236
|
+
return [App.create(project, name) for name in list_app_names()]
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def require_apps(project: Project) -> list[App]:
|
|
240
|
+
"""List the repo's packages, refusing to carry on when there are none
|
|
241
|
+
|
|
242
|
+
A gate that iterates nothing and reports success is indistinguishable
|
|
243
|
+
from one that passed, which is how a misconfigured repo silently never
|
|
244
|
+
releases. Every command that checks or publishes goes through here.
|
|
245
|
+
"""
|
|
246
|
+
apps = list_apps(project)
|
|
247
|
+
|
|
248
|
+
if apps:
|
|
249
|
+
return apps
|
|
250
|
+
|
|
251
|
+
settings = config.load()
|
|
252
|
+
|
|
253
|
+
if settings.layout is config.Layout.SINGLE:
|
|
254
|
+
detail = "the root pyproject.toml declares no [project] name"
|
|
255
|
+
else:
|
|
256
|
+
detail = (
|
|
257
|
+
"check [tool.uv.workspace] members, or set\n"
|
|
258
|
+
'[tool.ol-release] layout = "single" if this repo is one package'
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
message = f"No packages found: {detail}."
|
|
262
|
+
raise NoPackagesError(message)
|