-
Notifications
You must be signed in to change notification settings - Fork 135
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
Circular import if script is called <module>.py
#693
Comments
<module>.py
AFAIK it would be enough if I would be able to put files into |
Hello! Thanks for I think there's a Unix-specific way you could work around this by specifying an external data directory with your script at |
You could also combine the workaround with a new command like |
Good idea, I will try that. The more I think about it, the more I come to the conclusion that the only reasonable way forward is to get rid of I'll close this issue as this is not a bug/issue with flit. Thanks for your help and kind words! |
Thanks! You might be able to do something where a script import sys
from warnings import warn
warn("Deprecated bottle.py command, use python -m bottle instead")
if os.path.basename(sys.path[0]) in ('bin', 'Scripts'):
del sys.path[0]
from bottle import * |
Hi there, I'm trying to port an old project from
setuptools
(setup.py/cfg
) topyproject.toml
andflit
and hitting a wall with then generated script stub. Problem is: The script is calledbottle.py
and the module is calledbottle
. This breaks with anImportError: cannot import name 'main' from partially initialized module 'bottle' (most likely due to a circular import)
because the script-stub tries to import itself. This wasn't an issue with the old setuptoolssetup(..., scripts=['bottle.py'])
approach because setuptools copied the entire module into thebin
folder and the main method containedsys.modules.setdefault('bottle', sys.modules['__main__'])
. This worked because afterbin/bottle.py
was loaded as__main__
, it copied itself intosys.modules['bottle']
and future imports forbottle
would already find the initialized module and not search for it anymore.I know this is use-case you probably to not want to support. Having a script with that name was a mistake I made a decode ago. I'm just asking if you perhaps have any idea how this could be worked around. Something I missed. I really do not want to break user scripts that rely on
./venv/bin/bottle.py
to work.The text was updated successfully, but these errors were encountered: