Importing Python modules from a scripts directory beside the tasks directory
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Reproduce the import failure with the shown scripts and tasks layout, starting from tasks/init.py and the loader path in invoke/loader.py. Compare behavior with Invoke 2.0.0 and the latest version; done means from scripts import useful_script_1 works from an Invoke task without the ImportError.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
We use invoke in a directory structure which looks like this:
-- scripts
-- __init__.py
-- useful_script_1.py
-- useful_script_2.py
-- ...
-- tasks
-- __init__.py
-- task_1.py
-- task_2.py
In our invoke tasks we import stuff from the scripts directory like this:
from scripts import useful_script_1
Some time between version 2.0.0 of invoke and the latest version something changed in invoke which stopped this working; we get the error:
ImportError: cannot import name 'useful_script_1' from 'scripts' (unknown location)
We have made this work up to now by sticking with version 2.0.0 of invoke but it would be better to adopt the latest version: what is the simplest way to make script-import work from an invoke task again?
The exact error with backtrace is:
Traceback (most recent call last):
File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python39\Scripts\inv.exe\__main__.py", line 7, in <module>
File "c:\program files\python39\lib\site-packages\invoke\program.py", line 387, in run
self.parse_collection()
File "c:\program files\python39\lib\site-packages\invoke\program.py", line 479, in parse_collection
self.load_collection()
File "c:\program files\python39\lib\site-packages\invoke\program.py", line 716, in load_collection
module, parent = loader.load(coll_name)
File "c:\program files\python39\lib\site-packages\invoke\loader.py", line 91, in load
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "c:\projects\my_project\tasks\__init__.py", line 2, in <module>
from scripts import useful_script_1
ImportError: cannot import name 'useful_script_1' from 'scripts' (unknown location)
- Lingua principale
- Python
- Stelle
- 4.8k
- Fork
- 412
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pyinvoke/invoke
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Tutte le issue di pyinvoke/invoke
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
use-agent-os/agent-os#3314 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
BasedHardware/omi#15662 · 1 commento ·
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
AiursoftWeb/AnduinOS-2#19 ·