diff --git a/devbin/__init__.py b/devbin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/devbin/update_version_py.py b/devbin/update_version_py.py index e182f31..60bd8bb 100755 --- a/devbin/update_version_py.py +++ b/devbin/update_version_py.py @@ -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() diff --git a/setup.py b/setup.py index bddb049..fadbf7f 100755 --- a/setup.py +++ b/setup.py @@ -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() )