Skip to content

Commit

Permalink
Merge pull request #106 from bwhmather/freeze-version
Browse files Browse the repository at this point in the history
Automatically freeze version during release
  • Loading branch information
bwhmather authored Jan 18, 2024
2 parents 8292bd8 + b2fcc09 commit 3d87560
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
*.egg-info/
.tox
src/ssort/_version.py
40 changes: 40 additions & 0 deletions scripts/freeze_version.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 5 additions & 1 deletion src/ssort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 3d87560

Please sign in to comment.