Skip to content

Commit

Permalink
Remedy some setup.py deprecations
Browse files Browse the repository at this point in the history
Some still remain.

DoD: No warnings about setup deprecations printed when running tox.

Ref:
https://packaging.python.org/en/latest/discussions/setup-py-deprecated/#id2
  • Loading branch information
walles committed Sep 11, 2024
1 parent c3668d0 commit f723ddb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
34 changes: 34 additions & 0 deletions devbin/update_version_py.py
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 0 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f723ddb

Please sign in to comment.