tox-dev / platformdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
https://platformdirs.readthedocs.io
MIT License
593 stars 51 forks source link

Support setuptools-scm 6.x #199

Closed sunpoet closed 1 year ago

sunpoet commented 1 year ago

hatch-vcs 0.3.0 depends on setuptools-scm 6.4.0+. Since setuptools-scm 6.x and 7.x generates different version.py (see below), the following error occurs with setuptools-scm 6.x. Therefore, we add a workaround to support both versions.

With setuptools-scm 6.4.2:

% cat src/platformdirs/version.py
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = '3.8.0'
version_tuple = (3, 8, 0)

With setuptools-scm 7.1.0:

% cat src/platformdirs/version.py
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = '3.8.0'
__version_tuple__ = version_tuple = (3, 8, 0)

The error without this workaround:

>>> import platformdirs
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/site-packages/platformdirs/__init__.py", line 12, in <module>
    from .version import __version__
ImportError: cannot import name '__version__' from 'platformdirs.version' (/usr/local/lib/python3.11/site-packages/platformdirs/version.py)

Reference: https://github.com/pypa/setuptools_scm/commit/b45e19f9f275a31873fd5e07faabef16fd0bbec0

gaborbernat commented 1 year ago

I don't want to do this. I would rather submit an issue Upstream, and once they fix it just bump the dependency. That is in essence, just drop support for the older version.

RonnyPfannschmidt commented 1 year ago

Or just use the classical import names which work on all supported versions

sunpoet commented 1 year ago
from .version import version
from .version import version_tuple as __version_info__

works for both versions.

Not sure why pre-commit.ci removes "from .version import version" line in https://github.com/platformdirs/platformdirs/commit/bab1568a8ab8b55afb3ed199213cc2dfdb239b27.

RonnyPfannschmidt commented 1 year ago

Pretty sure pre commit removes it because it's breaking parent package name assignment

gaborbernat commented 1 year ago

I don't want to do this. I would rather submit an issue Upstream, and once they fix it just bump the dependency. That is in essence, just drop support for the older version.