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

Modify setup.py to not import the whole module for package data #142

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

amureki
Copy link
Collaborator

@amureki amureki commented Feb 10, 2021

While working on #141 I found out that we are importing the whole model_bakery lib just in order to obtain __version__.
And due to the change in imports, tox starts to fail.

Run python -m tox
GLOB sdist-make: /home/runner/work/model_bakery/model_bakery/setup.py
ERROR: invocation failed (exit code 1), logfile: /home/runner/work/model_bakery/model_bakery/.tox/log/GLOB-0.log
================================== log start ===================================
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    import model_bakery
  File "/home/runner/work/model_bakery/model_bakery/model_bakery/__init__.py", line 8, in <module>
    from .utils import seq  # NoQA
  File "/home/runner/work/model_bakery/model_bakery/model_bakery/utils.py", line 16, in <module>
    from .timezone import tz_aware
  File "/home/runner/work/model_bakery/model_bakery/model_bakery/timezone.py", line 9, in <module>
    from django.conf import settings
ModuleNotFoundError: No module named 'django'

=================================== log end ====================================
ERROR: FAIL could not package project - v = InvocationError('/opt/hostedtoolcache/Python/3.8.7/x64/bin/python setup.py sdist --formats=zip --dist-dir /home/runner/work/model_bakery/model_bakery/.tox/dist', 1)

I decided to move some bits around and put stuff in a separate __about__.py, which would be read by setup.py.
This structure works quite fine in my other packages.
What do you think? I am happy to use a different approach, the only thing is important that we should not import lib for nothing. :)

@amureki amureki self-assigned this Feb 10, 2021
Copy link
Contributor

@anapaulagomes anapaulagomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for bring this up. 👍🏽

Copy link
Member

@berinhard berinhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for fixing this! I realy liked the __about__.py

@berinhard berinhard merged commit 357b9c7 into main Feb 17, 2021
@berinhard berinhard deleted the about branch February 17, 2021 16:48
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

Successfully merging this pull request may close these issues.

3 participants