I want to understand what is considered the correct minimalist way to use setuptools with a "src/ layout" in a way that dispenses using src.
prefix in imports?
I have read most of the PyPA and setuptools documentation (and its many use cases), but I can't understand what is considered the correct way of doing this example.
The below layout reproduces what I want to achieve. I can't understand how to get the second import to work instead of the first across all modules of the mylibrary
package:
from src.mylibrary.hello_word import hello_function # <- This works.
from mylibrary.hello_word import hello_function # <- How to get this working?
hello_function()
Using this directory/file structure:
C:\MyProject
│
│ setup.py
│
└───src
│
├──mylibrary
│ hello_word.py
│ module_two.py
│ __init__.py
│
When I use development mode install with pip install -e .
the egg directory is added to the above tree:
│ (...)
│
└──mylibrary.egg-info
dependency_links.txt
PKG-INFO
SOURCES.txt
top_level.txt
With this setup.py
:
from setuptools import setup, find_packages, find_namespace_packages
setup(
name='mylibrary',
version='0.1',
package_dir={'': 'src'},
# packages=find_namespace_packages(where='src'), # <- I suppose this isn't the deciding factor.
packages=find_packages(where='src'),
)
The simple hello_world.py
module that I want to dispense having to write src.
when importing.
def hello_function():
print("hello world")
The __init__.py
is left empty.
I'm using a venv, to my surprise the egg symlink isn't written to the venv sitepackages
but to C:\Users\Name\AppData\Roaming\Python\Python38\site-packages
...
Python console indicates mylibrary
package is found:
>>> from setuptools import find_packages
>>> find_packages(where='src')
['mylibrary']