From 4d5a20823b4ec44a68741bf79d1ae87e551ce9e4 Mon Sep 17 00:00:00 2001 From: Ben Mather Date: Fri, 29 Dec 2023 21:56:59 +0000 Subject: [PATCH 1/2] Add script to freeze version --- .gitignore | 1 + scripts/freeze_version.py | 40 +++++++++++++++++++++++++++++++++++++++ src/ssort/__init__.py | 6 +++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 scripts/freeze_version.py diff --git a/.gitignore b/.gitignore index e9201f2..29408c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ *.egg-info/ .tox +src/ssort/_version.py diff --git a/scripts/freeze_version.py b/scripts/freeze_version.py new file mode 100644 index 0000000..6b21186 --- /dev/null +++ b/scripts/freeze_version.py @@ -0,0 +1,40 @@ +""" +Reads a version string from stdin and writes a python script which exports it +to stdout. +""" + +import argparse +import pathlib + + +def main(): + parser = argparse.ArgumentParser( + description="Hard codes the version number reported by ssort" + ) + parser.add_argument( + "-o", + "--output", + type=pathlib.Path, + default=pathlib.Path("src/ssort/_version.py"), + help="Where to write the frozen version number", + ) + parser.add_argument( + "version", + type=str, + help="The new version number to write", + ) + + args = parser.parse_args() + + output = f"""\"\"\" +Generated by `scripts/freeze_version.py`. Do not edit directly. +\"\"\" + +VERSION = {args.version!r} +""" + + args.output.write_text(output) + + +if __name__ == "__main__": + main() diff --git a/src/ssort/__init__.py b/src/ssort/__init__.py index 75fae03..1960f50 100644 --- a/src/ssort/__init__.py +++ b/src/ssort/__init__.py @@ -17,5 +17,9 @@ assert UnknownEncodingError is not None assert WildcardImportError is not None -__version__ = "0.12.0" +try: + from ssort._version import VERSION as __version__ # type: ignore +except ImportError: + __version__ = "0.0.1+dev" + __all__ = ["ssort"] From b2fcc09ae6dc21bb4233b308b1bc325a5f4a4443 Mon Sep 17 00:00:00 2001 From: Ben Mather Date: Fri, 29 Dec 2023 22:15:54 +0000 Subject: [PATCH 2/2] Freeze version before pushing to pypi --- .github/workflows/release.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a5fa6f3..b03ac75 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,11 +15,14 @@ jobs: - name: Set up Python uses: actions/setup-python@v3 with: - python-version: 3.7 + python-version: 3.11 - name: Install dependencies run: | python -m pip install --upgrade pip pip install build + - name: Freeze version + run: | + python scripts/freeze_version.py "$GITHUB_REF_NAME" - name: Build package run: python -m build - name: Publish distribution to PyPI