Skip to content

Commit 5d3260f

Browse files
authored
Fix scripts to run under uv correctly (#174)
* Fix scripts to run under uv correctly * Fixes * Fix detection of changelog files * Remove py3.12
1 parent de18dd0 commit 5d3260f

File tree

32 files changed

+91
-106
lines changed

32 files changed

+91
-106
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555

5656
- name: Changelog
5757
if: ${{ !contains(github.event.head_commit.author, 'renovate') }}
58-
run: PYTHONPATH=build-support/bin uv run build changelog check
58+
run: uv run scripts/changelog.py check
5959

6060
# - name: Upload coverage to CodeCov
6161
# uses: codecov/codecov-action@v1

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ WORKDIR /home/dev/src
4141
FROM uv as release
4242

4343
USER dev
44-
ENV PYTHONPATH="build-support/bin/"
4544

4645
WORKDIR /home/dev
4746
RUN mkdir -m 0750 .ssh

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ This set of libraries is managed using [uv](https://docs.astral.sh/uv/).
1212
- Install `uv` as described in the manual: https://docs.astral.sh/uv/
1313
- Bootstrap the `uv` environment: `uv python install 3.11 ; uv sync`
1414

15-
> [!WARNING]
16-
> If you're running `uv` locally, any calls to the `build` command will need help.
17-
> Prepend `PYTHONPATH=build-support/bin` to the command so uv will launch it properly.
18-
1915
#### Use the Docker Compose environment (recommended)
2016

2117
The Compose environment includes a container for general use called `shell` and one specifically for building releases called `release`. In either case, you'll get a shell with `uv` already set up, and with a PostgreSQL database available.
@@ -37,7 +33,7 @@ The `release` container is special and is set up to run `build` commands, includ
3733
**Using:**
3834
1. Build the images, so the source code in the image is up to date: `docker compose build`
3935
2. Get a shell: `docker compose run --rm -ti release bash`
40-
3. Run your command: `uv run build release create etc. etc. etc.`
36+
3. Run your command: `uv run scripts/release.py create` etc. etc. etc.
4137
4. If you've done things that involve Git, make sure you `git pull` when you leave the session.
4238

4339
### Navigating this repository
@@ -89,7 +85,7 @@ Run `uv run pytest`. This should run all the tests. If you want to run a specifi
8985

9086
We maintain changelogs in `changelog.d/` directories with each app. To create a new changelog for your changes, run:
9187

92-
- `uv run build changelog create --app APPNAME`
88+
- `uv run scripts/changelog.py create --app APPNAME`
9389
- `APPNAME`: the name of an application directory
9490

9591
Note warning above about `PYTHONPATH`. You will need to adjust permissions/ownership on the new file if you're using the Compose setup.
@@ -102,7 +98,7 @@ Changelogs are maintained according to [Keep a Changelog](https://keepachangelog
10298
Versioning uses a date-based versioning scheme with incremental builds on the same day.
10399
Version tags follow `{package-name}/v{version}`
104100
To perform a release, run:
105-
- `uv run build release create --app APPNAME --push`:
101+
- `uv run scripts/release.py create --app APPNAME --push`:
106102
- `APPNAME`: the name of an application directory
107103

108104
`release` expects to be run on the `main` branch and it expects you to not have changes pending.

build-support/bin/mitol/build_support/cli.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

build-support/bin/mitol/build_support/commands/version.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ requires-python = ">= 3.8"
2828
requires = ["hatchling"]
2929
build-backend = "hatchling.build"
3030

31-
[project.scripts]
32-
build = "mitol.build_support.cli:cli"
33-
3431
[tool.uv]
3532
managed = true
3633
dev-dependencies = [
File renamed without changes.

build-support/bin/mitol/build_support/apps.py renamed to scripts/apps.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
77

88
import toml
99

10-
from mitol.build_support.contextlib import chdir
11-
12-
SOURCE_PATH = "src/"
10+
from scripts.contextlibs import chdir
1311

1412

1513
def get_source_dir() -> Path:
1614
"""Get the source directory"""
17-
source_dir = Path.cwd()
18-
if SOURCE_PATH not in str(source_dir):
19-
source_dir = source_dir / SOURCE_PATH
20-
return source_dir
15+
return Path(__file__).parent.parent / "src"
2116

2217

2318
def get_app_dir(path: str) -> Path:

build-support/bin/mitol/build_support/commands/changelog.py renamed to scripts/changelog.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
from scriv.create import create
1111
from scriv.scriv import Scriv
1212

13-
from mitol.build_support.apps import App, list_apps
14-
from mitol.build_support.contextlib import chdir
15-
from mitol.build_support.decorators import app_option, pass_app, pass_project
16-
from mitol.build_support.project import Project
13+
from scripts.apps import App, list_apps
14+
from scripts.contextlibs import chdir
15+
from scripts.decorators import app_option, pass_app, pass_project
16+
from scripts.project import Project
1717

1818

1919
@group("changelog")
2020
@pass_context
21-
def changelog(ctx): # noqa: ARG001
21+
def changelog(ctx):
2222
"""Manage application changelogs"""
23+
ctx.ensure_object(Project)
2324

2425
makedirs("changelog.d", exist_ok=True) # noqa: PTH103
2526

@@ -49,12 +50,22 @@ def _echo_change(change: Diff):
4950
"""Echo the change to stdout"""
5051
line = [change.change_type, change.a_path]
5152

52-
if change.renamed:
53+
if change.renamed_file:
5354
line.extend(["->", changelog.b_path])
5455

5556
echo(indent(" ".join(line), "\t"))
5657

5758

59+
def _is_source_excluded(path) -> bool:
60+
excluded_paths = ["*/changelog.d/*", "*/CHANGELOG.md"]
61+
return any([fnmatch(path, exclude) for exclude in excluded_paths]) # noqa: C419
62+
63+
64+
def _is_changelog_excluded(path) -> bool:
65+
excluded_paths = ["*/scriv.ini"]
66+
return any([fnmatch(path, exclude) for exclude in excluded_paths]) # noqa: C419
67+
68+
5869
@changelog.command()
5970
@option(
6071
"-b",
@@ -71,7 +82,7 @@ def _echo_change(change: Diff):
7182
@simple_verbosity_option()
7283
@pass_project
7384
@pass_context
74-
def check(ctx: Context, project: Project, base: str, target: str): # noqa: C901
85+
def check(ctx: Context, project: Project, base: str, target: str):
7586
"""Check for missing changelogs"""
7687
base_commit = project.repo.commit(base)
7788
target_commit = project.repo.commit(target)
@@ -81,38 +92,24 @@ def check(ctx: Context, project: Project, base: str, target: str): # noqa: C901
8192
for app_abs_path in list_apps():
8293
app_rel_path = app_abs_path.relative_to(project.path)
8394

84-
excluded_paths = [app_rel_path / "changelog.d/*", app_rel_path / "CHANGELOG.md"]
85-
86-
def _is_excluded(path):
87-
return any([fnmatch(path, exclude) for exclude in excluded_paths]) # noqa: B023, C419
88-
8995
source_changes = [
9096
change
9197
for change in base_commit.diff(target_commit, paths=[app_rel_path])
92-
if not _is_excluded(change.a_path) and not _is_excluded(change.b_path)
98+
if not _is_source_excluded(change.a_path)
99+
and not _is_source_excluded(change.b_path)
93100
]
94101
has_source_changes = len(source_changes) > 0
95102

96-
changelogd_changes = base_commit.diff(
97-
target_commit, paths=[app_rel_path / "changelog.d"]
98-
)
103+
changelogd_changes = [
104+
change
105+
for change in base_commit.diff(
106+
target_commit, paths=[app_rel_path / "changelog.d"]
107+
)
108+
if not _is_changelog_excluded(change.a_path)
109+
and not _is_changelog_excluded(change.b_path)
110+
]
99111
has_changelogd_changes = len(changelogd_changes) > 0
100112

101-
# If there's changes to the base requirements.txt, then we need to allow for
102-
# changelogs to exist without the app code changing. There won't necessarily be
103-
# changes in the individual apps if we're just updating project-wide dependencies. # noqa: E501
104-
# So, if there's no source changes, check if there's been changes to the
105-
# requirements, and treat that as source changes.
106-
107-
if not has_source_changes:
108-
reqs_paths = [
109-
"build-support/requirements/requirements-testing.txt",
110-
"build-support/requirements/requirements.txt",
111-
]
112-
113-
reqs_changes = base_commit.diff(target_commit, paths=reqs_paths)
114-
has_source_changes = len(reqs_changes) > 0
115-
116113
if has_source_changes and not has_changelogd_changes:
117114
echo(f"Changelog(s) are missing in {app_rel_path} for these changes:")
118115
for change in source_changes:
@@ -146,3 +143,7 @@ def _is_excluded(path):
146143

147144
if is_error:
148145
ctx.exit(1)
146+
147+
148+
if __name__ == "__main__":
149+
changelog()

build-support/bin/mitol/build_support/decorators.py renamed to scripts/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from click import Choice, Command, make_pass_decorator, option
44
from cloup import Context, pass_context
55

6-
from mitol.build_support.apps import App, list_app_names
7-
from mitol.build_support.project import Project
6+
from scripts.apps import App, list_app_names
7+
from scripts.project import Project
88

99
pass_project = make_pass_decorator(Project)
1010
pass_app = make_pass_decorator(App)
File renamed without changes.

build-support/bin/mitol/build_support/commands/release.py renamed to scripts/release.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
from click import echo, pass_context
22
from cloup import Context, group, option
33

4-
from mitol.build_support.apps import App
5-
from mitol.build_support.commands import changelog, version
6-
from mitol.build_support.decorators import (
4+
from scripts import changelog, version
5+
from scripts.apps import App
6+
from scripts.decorators import (
77
app_option,
88
no_require_main,
99
pass_app,
1010
pass_project,
1111
)
12-
from mitol.build_support.project import Project
12+
from scripts.project import Project
1313

1414

1515
@group()
16-
def release():
17-
pass
16+
@pass_context
17+
def release(ctx: Context):
18+
ctx.ensure_object(Project)
1819

1920

2021
@release.command()
@@ -88,3 +89,7 @@ def push_to_remote(project: Project, app: App):
8889
[app.version_git_tag, "HEAD"],
8990
follow_tags=True,
9091
)
92+
93+
94+
if __name__ == "__main__":
95+
release()

scripts/version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from bumpver import cli
2+
from cloup import Context, group, pass_context
3+
4+
from scripts.decorators import app_option
5+
from scripts.project import Project
6+
7+
8+
@group()
9+
@pass_context
10+
def version(ctx: Context):
11+
"""CLI for build tools"""
12+
ctx.ensure_object(Project)
13+
ctx.invoke(cli.cli, **ctx.params)
14+
15+
16+
version.add_command(app_option(cli.grep))
17+
version.add_command(app_option(cli.init))
18+
version.add_command(app_option(cli.show))
19+
version.add_command(cli.test) # this doesn't require config so doesn't require --app
20+
version.add_command(app_option(cli.update))
21+
22+
23+
if __name__ == "__main__":
24+
version()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

src/common/changelog.d/scriv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

src/geoip/changelog.d/scriv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

src/hubspot_api/changelog.d/scriv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

src/mail/changelog.d/scriv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

src/olposthog/changelog.d/scriv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

src/openedx/changelog.d/scriv.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[scriv]
22
format = md
33
md_header_level = 2
4-
entry_title_template = file: ../../build-support/scriv/entry_title.${config:format}.j2
4+
entry_title_template = file: ../../scripts/scriv/entry_title.${config:format}.j2
55
version = literal: __init__.py: __version__

0 commit comments

Comments
 (0)