Hi. Being still new to Python ecosystem, I’d appreciate to get a helping hand with minimal pip install -e
+ pyproject.toml
configurations for local package development.
Please consider following example:
mylib
(src-layout here)
/tmp/demo-lib/
├── pyproject.toml
└── src
├── mylib
│ ├── helper.py
│ └── main.py
# pyproject.toml
[project]
name = "mylib"
version = "0.1"
# src/mylib/main.py
def say_hello():
print("Hello world")
# src/mylib/helper.py
def say_hello_helper():
print("Hello helper")
myclient
/tmp/demo-client/
├── main.py
└── venv
# main.py
import mylib.main as T
T.say_hello()
Testcases
. /tmp/demo-client/venv/bin/activate
pip install -e /tmp/demo-lib/
# ...
# Successfully built mylib
# Installing collected packages: mylib
# Successfully installed mylib-0.1
1.) Single module works
(venv) [myuser@sys demo-client]$ python main.py
Hello world
2.) helper.py
causes ModuleNotFoundError
To reproduce, change /tmp/demo-lib/src/mylib/main.py
:
import helper
def say_hello():
print("Hello world")
helper.say_hello_helper()
(venv) [myuser@sys demo-client]$ python main.py
File "/tmp/demo-lib/src/mylib/main.py", line 1, in <module>
import helper
ModuleNotFoundError: No module named 'helper'
(venv) [myuser@sys ~]$ pip --version
pip 23.3.1 from /tmp/demo-client/venv/lib64/python3.11/site-packages/pip (python 3.11)
I am able to navigate to demolib
and run main.py
(but this won’t solve problem client issue):
[myuser@sys ~]$ cd /tmp/demo-lib/src/mylib/
[myuser@sys mylib]$ python -c 'import main; main.say_hello()'
Hello world
Hello helper
Question
I am interested in the correct or recommended way to get this going natively - just vanilla Python/pip, not using any third-party dependencies as poetry.
From what I’ve read about PEP 660, this scenario with interactive pip install
and pyproject.toml
should be supported out of the box right? And shouldn’t the module import resolution for helper
handled transparently within mylib
from perspective of client, when using pip install -e
?
I totally might have missed something obvious, so please correct me in this case.