[issue44070] __file__ is now fully qualified in 3.8 and 3.9

Thomas Grainger report at bugs.python.org
Thu Jul 15 08:01:23 EDT 2021


Thomas Grainger <tagrain at gmail.com> added the comment:

hello, just chiming in to let you know that this broke CI on twisted: https://github.com/twisted/twisted/pull/1628/ (As above for Chalice, I think this didn't actually break the framework itself, just the tests for the framework. )

do you know what the correct usage of importlib.util.spec_from_file_location is to match importlib.import_module ?


I have a tree like this:

.
└── mypkg
    ├── demo.py
    ├── __init__.py
    └── __pycache__
        ├── __init__.cpython-38.pyc
        └── __init__.cpython-39.pyc

2 directories, 4 files


but I'm not sure how to get a spec for ./mypkg/demo.py:


Python 3.9.6 (default, Jul  3 2021, 16:40:50) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/dist-packages', '/usr/lib/python3/dist-packages']
>>> import os
>>> os.getcwd()
'/home/graingert/projects/syspath-tests'
>>> import importlib.util
>>> importlib.util.spec_from_file_location(name="mypkg.demo", location="mypkg/demo.py")
ModuleSpec(name='mypkg.demo', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fc94644bfd0>, origin='mypkg/demo.py')
>>> import mypkg.demo
>>> mypkg.demo.__spec__
ModuleSpec(name='mypkg.demo', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fc94645a160>, origin='/home/graingert/projects/syspath-tests/mypkg/demo.py')
>>>

----------
nosy: +graingert

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44070>
_______________________________________


More information about the Python-bugs-list mailing list