Should I use --no-root ? Some description of building problems, and lots of strange behaviour #3924
-
I am observing some strange things. I would love to hear some explanation of the concepts. ( Extra context: I recently read: https://hynek.me/articles/testing-packaging/ by @hynek, and #3923 is also related) StructureI have a project directory like this: .
├── poetry.lock
├── pyproject.toml
├── README.rst
├── src
│ ├── another_p
│ │ ├── __init__.py
│ └── custom_learn_p
│ ├── __init__.py
├── test.py
Files
def another():
return 'another'
def whatever():
return 'hello'
from custom_learn_p import whatever
from another_p import another
assert whatever() == 'hello'
assert another() == 'another'
print('end of test') RunningFrom inside the root of the project, I open my terminal and run: $ poetry shell
# success
(.venv) $ poetry install
# success
(.venv) $ python test.py
end of test
# no errors raised In the project virtual env, everything worked. ProblemNow, I build the package: $ poetry build The Now, I create another fresh virtual environment and install the $ python -m venv .new_venv
$ source .new_venv/bin/activate
(.new_venv) $ pip install dist/custom_learn_p-0.1.0-py3-none-any.whl Now, from inside this fresh virtual environment, I run, $ python test.py
Traceback (most recent call last):
File "/home/aahnik/Projects/new_folder/test.py", line 2, in <module>
from another_p import another
ModuleNotFoundError: No module named 'another_p' What I realize: package I realized this fault, only after using a separate virtual environment, and pretending to be a user. In the project's virtual env, why? If I would not have pretended to be a user, and installed the While developing, should I always run I think poetry installs the current package in editable mode. Any change in my code immediately reflects. Any new package added under the Is this expected behavior? Thanks a lot for your time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @aahnik, this is (more or less) an expected behavior, due to how editable installs works. A path configuration file is used to add the root folder of the package to the search path for modules. This means that the This is a good reason why you want to use fin swimmer |
Beta Was this translation helpful? Give feedback.
Hello @aahnik,
this is (more or less) an expected behavior, due to how editable installs works. A path configuration file is used to add the root folder of the package to the search path for modules. This means that the
src
folder is now included in this search path and every package folder that is located there, can be found as well.This is a good reason why you want to use
tox
for testing, which will build your package and install it into a new venv for testing. You can see how I do this herefin swimmer