Repository navigation
build(packaging): publish DicoGIS on PyPI #521
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c59cdd1
build: require setuptools>=77 for the SPDX license expression
claude bc07a32
build: drop the unused setuptools-scm build requirement
claude e12eead
test(packaging): check package-data patterns and the setuptools floor
claude 5a4fd15
ci: publish to PyPI on tags with Trusted Publishing
claude 96274ec
docs(releasing): document the PyPI publication
claude 759e1d2
ci(release): build the Python package and attach it to the GitHub rel…
claude a67ea3b
ci(release): publish to PyPI from the build and release workflow
claude 7dddb36
docs(releasing): describe the PyPI publication as part of the release…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #! python3 # noqa E265 | ||
|
|
||
| """ | ||
| Usage from the repo root folder: | ||
|
|
||
| .. code-block:: bash | ||
| # for whole tests | ||
| python -m unittest tests.test_packaging | ||
| # for specific test | ||
| python -m unittest tests.test_packaging.TestPackaging.test_ui_and_translation_files_are_packaged | ||
| """ | ||
|
|
||
| # standard library | ||
| import tomllib | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| # 3rd party | ||
| from packaging.requirements import Requirement | ||
|
|
||
|
|
||
| # ############################################################################ | ||
| # ########## Globals ############# | ||
| # ################################ | ||
|
|
||
| PROJECT_ROOT = Path(__file__).parent.parent | ||
| PACKAGE_DIR = PROJECT_ROOT / "dicogis" | ||
|
|
||
| # Qt files loaded at runtime: if one is missing from the wheel, the GUI breaks | ||
| RUNTIME_DATA_SUFFIXES = {".ui", ".qm"} | ||
|
|
||
|
|
||
| # ############################################################################ | ||
| # ########## Classes ############# | ||
| # ################################ | ||
|
|
||
|
|
||
| class TestPackaging(unittest.TestCase): | ||
| """Test the packaging configuration declared in pyproject.toml.""" | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls) -> None: | ||
| """Read pyproject.toml once.""" | ||
| with (PROJECT_ROOT / "pyproject.toml").open("rb") as pyproject_file: | ||
| cls.pyproject = tomllib.load(pyproject_file) | ||
|
|
||
| cls.package_data_patterns: list[str] = cls.pyproject["tool"]["setuptools"][ | ||
| "package-data" | ||
| ]["dicogis"] | ||
|
|
||
| def test_package_data_patterns_match_files(self) -> None: | ||
| """A pattern matching nothing is a typo or a moved folder: files would be | ||
| silently left out of the wheel. | ||
| """ | ||
| for pattern in self.package_data_patterns: | ||
| with self.subTest(pattern=pattern): | ||
| self.assertTrue(any(PACKAGE_DIR.glob(pattern))) | ||
|
|
||
| def test_ui_and_translation_files_are_packaged(self) -> None: | ||
| """Every .ui and .qm file must be covered by a package-data pattern, e.g. a | ||
| new dialog in a new subfolder. | ||
| """ | ||
| packaged = { | ||
| path | ||
| for pattern in self.package_data_patterns | ||
| for path in PACKAGE_DIR.glob(pattern) | ||
| } | ||
| runtime_data = { | ||
| path | ||
| for path in PACKAGE_DIR.rglob("*") | ||
| if path.suffix in RUNTIME_DATA_SUFFIXES | ||
| } | ||
|
|
||
| missing = sorted( | ||
| str(path.relative_to(PROJECT_ROOT)) for path in runtime_data - packaged | ||
| ) | ||
| self.assertEqual(missing, [], "Not declared in [tool.setuptools.package-data]") | ||
|
|
||
| def test_build_requires_setuptools_supports_spdx_license(self) -> None: | ||
| """An SPDX `license` expression (PEP 639) is only understood by setuptools | ||
| >= 77: with a lower floor, builds without isolation fail. | ||
| """ | ||
| if not isinstance(self.pyproject["project"]["license"], str): | ||
| self.skipTest("The license is not declared as an SPDX expression.") | ||
|
|
||
| requirements = [ | ||
| Requirement(requirement) | ||
| for requirement in self.pyproject["build-system"]["requires"] | ||
| ] | ||
| setuptools = next(req for req in requirements if req.name == "setuptools") | ||
|
|
||
| self.assertNotIn("76.1.0", setuptools.specifier) | ||
| self.assertIn("77.0.0", setuptools.specifier) | ||
|
|
||
|
|
||
| # ############################################################################ | ||
| # ####### Stand-alone run ######## | ||
| # ################################ | ||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.