Setup.py inside the installed module

For a directory structure like the following, I was unable to make an xy import package.

 xy ├── __init__.py ├── z │  ├── __init__.py │  └── stuff.py └── setup.py 

If setup.py was a directory up, I could use

 from setuptools import setup setup(name='xy', packages=['xy']) 

but also, no combination of package_dir and packages allowed me import xy , only import z . Unfortunately, moving setup.py in the directory up is not an option due to the excessive number of hard-coded paths.

+3
source share
2 answers

I stumbled upon the same problem and could not find a suitable solution (read "using predefined settings").

In the end, I created an ugly patch: I move everything to a new subdirectory called the package, and then move everything again.

 import os, errno # create directory directory = 'xy/' try: os.makedirs(directory) except OSError as e: if e.errno != errno.EEXIST: raise # move important files move = [ ... ] for fname in move: os.rename(fname, directory + fname) setup( ... package_dir = {'': '.'}, ... ) # move back for fname in move: os.rename(directory + fname, fname) 
0
source

The following answer provides ideas on how to use package_dir and packages to help with such projects: fooobar.com/questions/1492403 / ...

Briefly for this case here:

 #!/usr/bin/env python3 import setuptools setuptools.setup( # ... packages=['xy', 'xy.z'], #packages=setuptools.find_packages('..') # only if parent directory is otherwise empty package_dir={ 'xy': '.', }, ) 
0
source

Source: https://habr.com/ru/post/1492405/


All Articles