diff --git a/devbin/update_version_py.py b/devbin/update_version_py.py new file mode 100755 index 0000000..e182f31 --- /dev/null +++ b/devbin/update_version_py.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import filecmp +import os +import shutil +import subprocess +import tempfile + + +VERSIONFILE = "px/version.py" + +git_version = ( + subprocess.check_output(["git", "describe", "--dirty"]).decode("utf-8").strip() +) +with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as tmp: + tmp.write(b"# NOTE: Auto generated by setup.py, no touchie!\n") + tmp.write(b'VERSION = "%s"\n' % bytearray(git_version, "utf_8")) + + # Flushing is required for filecmp.cmp() to work (below) + tmp.flush() + + if not os.path.isfile(VERSIONFILE): + # No version file found + shutil.move(tmp.name, VERSIONFILE) + elif not filecmp.cmp(tmp.name, VERSIONFILE): + # Version file needs updating + shutil.move(tmp.name, VERSIONFILE) + else: + # VERSIONFILE was already up to date. If we touch it in this + # case, it will have its file timestamp updated, which will + # force the slow px_integration_test.py tests to get rerun. + # + # Just clean up our tempfile and be merry. + os.remove(tmp.name) diff --git a/setup.py b/setup.py index 48ee550..bddb049 100755 --- a/setup.py +++ b/setup.py @@ -2,38 +2,13 @@ import os import re -import shutil -import filecmp -import tempfile import subprocess from setuptools import setup -VERSIONFILE = "px/version.py" - git_version = ( subprocess.check_output(["git", "describe", "--dirty"]).decode("utf-8").strip() ) -with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as tmp: - tmp.write(b"# NOTE: Auto generated by setup.py, no touchie!\n") - tmp.write(b'VERSION = "%s"\n' % bytearray(git_version, "utf_8")) - - # Flushing is required for filecmp.cmp() to work (below) - tmp.flush() - - if not os.path.isfile(VERSIONFILE): - # No version file found - shutil.move(tmp.name, VERSIONFILE) - elif not filecmp.cmp(tmp.name, VERSIONFILE): - # Version file needs updating - shutil.move(tmp.name, VERSIONFILE) - else: - # VERSIONFILE was already up to date. If we touch it in this - # case, it will have its file timestamp updated, which will - # force the slow px_integration_test.py tests to get rerun. - # - # Just clean up our tempfile and be merry. - os.remove(tmp.name) requirements = None with open("requirements.txt", encoding="utf-8") as reqsfile: diff --git a/tox.ini b/tox.ini index fcb594c..3c95585 100644 --- a/tox.ini +++ b/tox.ini @@ -30,8 +30,8 @@ allowlist_externals = /bin/bash deps = setuptools == {[tox]setuptools_version} commands = - # This creates px/version.py - /bin/bash -c './setup.py check' + # This keeps px/version.py up to date + /bin/bash -c './devbin/update_version_py.py' [testenv:ruff-format] deps = @@ -122,7 +122,6 @@ deps = commands = # clean up build/ and dist/ folders /bin/rm -rf build dist - python setup.py clean --all # build wheel /bin/rm -rf dist python setup.py bdist_wheel --bdist-dir {toxinidir}/bdist --dist-dir {toxinidir}/dist