I would like to craft a setup.py for a package with an unusual folder structure.
The usual structure is
topfolder (e.g. git folder name)
- setup.py
- pkgname/
- __init__.py
- file1.py
- folder1/
- file2.py
The usual setup.py would be
from setuptools import setup
PACKAGES = ["pkgname",]
setup(packages=PACKAGES)
Upon installation the folder name pkgname/ is copied into miniconda3/lib/python3.8/site-packages/. As a user you can import this as
import pkgname
import pkgname.folder1
import pkgname.folder1.file2
import pkgname.file1
etc...
Now, for reasons that don't matter I can't/am not allowed to change the unusual folder structure. Instead, I'm stuck with this:
topfolder (which is also the pkgname)
- __init__.py
- file1.py
- folder1/
- file2.py
So as you can see, setup.py doesn't exist, the top folder is named after the package name, and everything that should be under pkgname/ is one level down.
I have actually managed to craft a setup.py that installs this. Just call the package ".":
from setuptools import setup
PACKAGES = [".",]
setup(packages=PACKAGES)
Now the problem is that upon installation the contents of topfolder get dumped directly into miniconda3/lib/python3.8/site-packages/ (as opposed to a folder being created there and the contents dumped into that folder). As a consequence, as a user I have to import as:
import folder1
import folder1.file2
import file1
I.e. because of how the installation is working, I lost the namespace.
Question: how do I craft a setup.py such that the unusual folder structure can be installed and used in the usual way?