Skip to content

Commit

Permalink
Keep updating version from setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Sep 14, 2024
1 parent c93d092 commit 837bd0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
Empty file added devbin/__init__.py
Empty file.
54 changes: 31 additions & 23 deletions devbin/update_version_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@

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)

def main():
"""Update px/version.py with the current git version."""
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 update_version_py.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)


if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

from setuptools import setup

from devbin import update_version_py

update_version_py.main()

git_version = (
subprocess.check_output(["git", "describe", "--dirty"]).decode("utf-8").strip()
)
Expand Down

0 comments on commit 837bd0e

Please sign in to comment.