-
Notifications
You must be signed in to change notification settings - Fork 54
Migrate off setuppy #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate off setuppy #245
Changes from all commits
61dcc06
15f3d17
61fc715
7e44494
d788396
dc9a126
81c1ed6
7cd1ba9
6a2c03b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ exclude = (?x)( | |
| ^build/ | | ||
| ^dist/ | | ||
| ^setup/ | | ||
| ^setup\.py$ | | ||
| ^\.tox/ | | ||
| ^\.venv/ | | ||
| ^venv.*/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["setuptools", "wheel"] | ||
| build-backend = "setuptools.build_meta" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| -r requirements.prod.txt | ||
| -r requirements.test.txt | ||
| build | ||
| ruff | ||
| setuptools | ||
| mypy | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| #!/bin/sh | ||
|
|
||
| python setup/setup.approval_utilities.py sdist bdist_wheel | ||
| cp setup/setup.approval_utilities.py setup.py | ||
| python -m build . | ||
| rm setup.py | ||
| twine upload --repository-url ${TWINE_REPOSITORY_URL} dist/* | ||
| rm -r dist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| #! /bin/sh | ||
| #!/bin/sh | ||
|
|
||
| python setup/setup.publish.py sdist bdist_wheel | ||
| cp setup/setup.publish.py setup.py | ||
| python -m build . | ||
| rm setup.py | ||
| twine upload --repository-url ${TWINE_REPOSITORY_URL} dist/* | ||
| rm -r dist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| #! /bin/sh | ||
| #!/bin/sh | ||
|
|
||
| python setup/setup.minimal.py sdist bdist_wheel | ||
| cp setup/setup.minimal.py setup.py | ||
| python -m build . | ||
| rm setup.py | ||
| twine upload --repository-url ${TWINE_REPOSITORY_URL} dist/* | ||
| rm -r dist |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,38 @@ | ||
| import glob | ||
| import pathlib | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| import time | ||
| import typing | ||
|
|
||
| from version import version_number | ||
|
|
||
|
|
||
| def main() -> None: | ||
| for package_name, setup_file in [ | ||
| ("approval_utilities", "setup/setup.approval_utilities.py"), | ||
| ("approvaltests", "setup/setup.py"), | ||
| ("approvaltests", "setup/setup.publish.py"), | ||
| ]: | ||
| build_number = str(int(time.time())) | ||
| _run_python_checked( | ||
| [ | ||
| setup_file, | ||
| "--quiet", | ||
| "bdist_wheel", | ||
| "--build-number", | ||
| build_number, | ||
| ] | ||
| ) | ||
| print(f"Testing build {package_name} ...") | ||
| dist_dir = pathlib.Path("dist") | ||
| if dist_dir.exists(): | ||
| shutil.rmtree(dist_dir) | ||
|
|
||
| shutil.copy2(setup_file, "setup.py") | ||
| try: | ||
| _run_python_checked(["-m", "build", "--wheel", "."], quiet=True) | ||
| finally: | ||
| _unlink_with_retry(pathlib.Path("setup.py")) | ||
|
|
||
| wheel_files = glob.glob("dist/*.whl") | ||
| assert len(wheel_files) == 1, f"Expected 1 wheel, found {wheel_files}" | ||
| _run_python_checked( | ||
| [ | ||
| "-m", | ||
| "pip", | ||
| "install", | ||
| "--force-reinstall", | ||
| f"dist/{package_name}-{version_number}-{build_number}-py3-none-any.whl", | ||
| wheel_files[0], | ||
| "--quiet", | ||
| "--no-warn-script-location", | ||
| ] | ||
|
|
@@ -47,14 +50,32 @@ def main() -> None: | |
|
|
||
|
|
||
| def _run_python_checked( | ||
| args: typing.List[str], cwd: typing.Optional[pathlib.Path] = None | ||
| args: typing.List[str], | ||
| cwd: typing.Optional[pathlib.Path] = None, | ||
| quiet: bool = False, | ||
| ) -> None: | ||
| subprocess.run( | ||
| [sys.executable, *args], | ||
| check=True, | ||
| cwd=cwd, | ||
| stdout=subprocess.DEVNULL if quiet else None, | ||
|
Comment on lines
52
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Quiet mode hides build output, which can make diagnosing failing packaging tests difficult. Using Suggested implementation: # Suppress only stdout in quiet mode so build / packaging errors remain visible
stdout=subprocess.DEVNULL if quiet else None,
stderr=None,If any callers relied on stderr being suppressed by |
||
| stderr=subprocess.DEVNULL if quiet else None, | ||
| ) | ||
|
|
||
|
|
||
| def _unlink_with_retry( | ||
| path: pathlib.Path, retries: int = 5, delay: float = 1.0 | ||
| ) -> None: | ||
| for attempt in range(retries): | ||
| try: | ||
| path.unlink(missing_ok=True) | ||
| return | ||
| except PermissionError: | ||
| if attempt < retries - 1: | ||
| time.sleep(delay) | ||
| else: | ||
| raise | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| set -euo pipefail | ||
|
|
||
| mise task --quiet run tidy_code | ||
| git add --renormalize . | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Be cautious about staging all files from within a tidy script.
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Also assert that the wheel belongs to the expected package, not just that there is exactly one wheel.
As written, this will pass as long as there’s exactly one wheel in
dist/, even if it’s for a different package. To make the test safer, also assert that the wheel filename matches the expected package name, e.g.Path(wheel_files[0]).name.startswith(f"{package_name}-"), so mismatches between the built wheel and the package under test are caught.