Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError with version = attr: and variable annotation syntax type hints #2563

Closed
homeworkprod opened this issue Feb 10, 2021 · 2 comments

Comments

@homeworkprod
Copy link

Observed behavior

setup.cfg contains:

[metadata]
version = attr: mypackage.VERSION

mypackage/__init__.py contains:

VERSION: str = '42.0-dev'

pip install -e . results in:

Obtaining […]
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /projectpath/venv/bin/python3.7 /projectpath/venv/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpwip8xxcd
       cwd: /projectpath
  Complete output (64 lines):
  Traceback (most recent call last):
    File "/tmp/pip-build-env-tprf3sb3/overlay/lib/python3.7/site-packages/setuptools/config.py", line 35, in __getattr__
      for statement in self.module.body
  StopIteration
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File "/tmp/pip-build-env-tprf3sb3/overlay/lib/python3.7/site-packages/setuptools/config.py", line 387, in _parse_attr
      return getattr(StaticModule(module_name), attr_name)
    File "/tmp/pip-build-env-tprf3sb3/overlay/lib/python3.7/site-packages/setuptools/config.py", line 43, in __getattr__
      ) from e
  AttributeError: [mypackage] has no attribute VERSION
  
  During handling of the above exception, another exception occurred:

  […]

Expectation

It works.

Workaround

Updating mypackage/__init__.py to

VERSION = '42.0-dev'

works.

@abravalheri
Copy link
Contributor

Hi @homeworkprod, thank you very much for bringing this topic up.

I did a quick investigation and it seems that this problem has already been solved 👏

I tried to verify this problem, by using one of your opensource repositories in GitHub:

> docker run -it --rm python:3.7 /bin/bash
$ git clone https://github.com/homeworkprod/syslog2irc.git
$ cd syslog2irc
$ sed -i 's/VERSION =/VERSION: str =/' src/syslog2irc/__init__.py
$ python3.7 -m pip install -U pip build
$ python3.7 -m build
...
Successfully built syslog2irc-0.14.dev0.tar.gz and syslog2irc-0.14.dev0-py3-none-any.whl

Is that the outcome you had in mind? Would this approach work for you?


Since it looks like this problem was solved, I will go ahead and close this issue, but please let me know if you still have problems and I will re-open it.

@homeworkprod
Copy link
Author

Thanks a lot, @abravalheri, for getting back to this!

Yes, I can confirm that this works for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants