Skip to content

Commit e61cd0f

Browse files
author
Sylvain MARIE
committed
Fixed setuptools_scm issue with legacy python versions
1 parent 7f70bbb commit e61cd0f

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

setup.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@
2929
DOWNLOAD_URL = URL + "/tarball/" + get_version()
3030

3131

32-
# (3) Call setup() with as little args as possible
33-
setup(
34-
download_url=DOWNLOAD_URL,
35-
use_scm_version={
36-
"write_to": "src/makefun/_version.py",
37-
# Custom template to avoid type hints and annotations (python <3.8)
38-
"version_file_template": """# file generated by setuptools_scm
32+
# Setuptools_scm target version file to generate
33+
args = {
34+
"write_to": "src/makefun/_version.py",
35+
}
36+
# Use the 'version_file_template' directive if possible to avoid type hints and annotations (python <3.8)
37+
from packaging.version import Version
38+
setuptools_scm_version = pkg_resources.get_distribution("setuptools_scm").version
39+
if Version(setuptools_scm_version) >= Version('8.1.0'):
40+
# Note that it was named 'write_to_template' earlier. But at that time it was not generating annotations so no need.
41+
args["version_file_template"] = """# file generated by setuptools_scm
3942
# don't change, don't track in version control
4043
__version__ = version = '{version}'
4144
__version_tuple__ = version_tuple = {version_tuple}
4245
"""
43-
}, # we can't put `use_scm_version` in setup.cfg yet unfortunately
46+
# (3) Call setup() with as little args as possible
47+
setup(
48+
download_url=DOWNLOAD_URL,
49+
use_scm_version=args
4450
)

0 commit comments

Comments
 (0)