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

Cannot import name '__version__' from 'platformdirs.version' #203

Closed bassmadrigal closed 1 year ago

bassmadrigal commented 1 year ago

I recently took over maintaining the platformdirs package for Slackware. In doing so, I found it was on version 2.5.1, so I wanted to make it up-to-date, so I attempted to update it to 3.8.1.

In doing so, I was able to successfully compile the package after switching to using the build module and satisfying the other dependencies. However, when I go to test the program by importing platformdirs, I get the following:

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

This was done on a fully updated Slackware 15.0 with python-3.9.17. I imagine this is something minor on my end, but I've not been able to figure it out.

Any pointers or suggestions? Thanks!

gaborbernat commented 1 year ago

This shows that you did not build the project correctly https://github.com/platformdirs/platformdirs/blob/main/pyproject.toml#L70-L72, and this is a problem with your build setup. Nothing to do for us.

bassmadrigal commented 1 year ago

I was using the following to build it. Am I doing it wrong?

python3 -m build --wheel --no-isolation
python3 -m installer --destdir=$PKG dist/*.whl

(With $PKG being the packaging directory.)

This is how I've built other packages without a setup.py and haven't ran into this issue before.

The hatch dependencies meet the version requirements listed on pyproject.toml.

Do you have any hints or ideas on how to properly build the project? I maintain several dozen python packages for Slackware and haven't ran into this issue before and my google-fu is failing me. I appreciate any guidance you can share!

ofek commented 1 year ago

What build dependencies do you have installed and how are you fetching this repository?

bassmadrigal commented 1 year ago

In addition to the stock packages in a fully updated 15.0 Slackware64 system, I have python3 versions of the following:

These are all dependencies of hatch-vcs that are not provided on a full Slackware install as documented by the maintainer on SlackBuilds.org (the 3rd-party build script repo for Slackware). As mentioned earlier, python itself is v3.9.17. The entire output from pip3 freeze can be seen at the end of this comment.

The initial build was done using the 3.8.1 source tarball hosted on pypi, but I had the same issue after cloning the repo and building from within the git repo.

I've attempted on both my normal desktop (with lots of packages installed -- unclean environment) and a clean chroot and both give the same error message.

Here is the output from pip3 freeze:

appdirs==1.4.4
Brotli==1.0.9
build==0.10.0
caca==0.99b19
calver==2022.6.26
certifi==2021.10.8
cffi==1.15.0
chardet==4.0.0
charset-normalizer==2.0.10
cupshelpers==1.0
Cython==0.29.27
distro==1.6.0
dnspython==2.1.0
docutils==0.17.1
doxypypy==0.8.8.6
doxyqml==0.5.1
editables==0.3
flit_core==3.9.0
future==0.18.2
getmail6==6.18.6
gpg==1.16.0
gyp==0.1
hatch-vcs==0.3.0
hatchling==1.17.1
idna==3.3
include_server==3.4
installer==0.7.0
isc==2.0
Jinja2==3.0.3
kapidox==5.90.0
lensfun==0.3.95
libwebp==0.0
M2Crypto==0.38.0
Mako==1.1.6
Markdown==3.3.4
MarkupSafe==2.0.1
mercurial==6.0.1
meson==0.59.4
netsnmp-python==1.0a1
nftables==0.1
notify2==0.3.1
packaging==21.3
pathspec==0.11.1
pbr==5.8.0
Pillow==8.4.0
platformdirs==3.8.1
pluggy==1.0.0
ply==3.11
pssh==2.3.4
pwquality==1.4.4
pycairo==1.20.1
pycparser==2.21
pycups==2.0.1
pycurl==7.44.1
Pygments==2.10.0
PyGObject==3.42.0
pyparsing==2.4.7
pyproject_hooks==1.0.0
PyQt5==5.15.2
PyQt5_sip==4.19.25
pysol-cards==0.12.0
python-sane==2.9.1
pyxdg==0.27
PyYAML==6.0
QScintilla==2.11.6
random2==1.0.1
requests==2.26.0
rpm==4.16.1.3
SCons==4.2.0
setuptools-scm==6.3.2
sip==4.19.25
six==1.16.0
tomli==1.2.2
trove-classifiers==2023.5.24
undervolt==0.3.0
urllib3==1.26.8
gaborbernat commented 1 year ago

I can't see anything wrong, but I don't think the issue is with this project either. You'll need to debug your build environment yourself.

bassmadrigal commented 1 year ago

I was able to find due to an issue in another project that this issue is caused by having a setuptools-scm version earlier that v7.0. There are workarounds to the issue, but it might be worth adjusting your minimum version of setuptools-scm to 7.0 or greater.

My distro uses setuptools-scm 6.3.2, so that's ultimately why I was running into this issue.

Thanks for your work on this project!