Python setup.py configuration to install files in user directories

I want to create setup.py that installs my files in user directories. I have a specific prefix where I would like to get the following result:

/my/prefix/ bin/ script.sh libexec/ one.py two.py ... lib/pythonX.Y/site-packages/ package/... 

My initial design is as follows:

 / script.sh one.py two.py ... setup.py package/... __init__.py ... 

What would be the best way to achieve this? I would like to be able to install it later with something like:

 python setup.py install --prefix=/my/prefix 

I can get a "package" installed perfectly in the correct directory, since lib / pythonX.Y / site-packages in the -prefix section is the default location. But is there a clean way to get script.sh in "bin" and other python files in "libexec"? The only way to achieve this is to manually copy these files into my setup.py script. Maybe there is a cleaner and more standard way to do this?

(edit)

Decision

I ended up with setup.py like this:

 setup(name='mylib', scripts=['script.sh'], data_files=[('libexec', ['one.py', 'two.py'])] ) 

Of course, you can iterate over all python files for libexec, but I only have 2-3 python files that I need.

(edit2)

Alternatively, I can have setup.cfg with the following:

 [install] prefix=/my/prefix 

and instead of python setup.py install --prefix=/my/prefix I can just do:

 python setup.py install 
+12
python installation setup.py configuration
May 5 '12 at 1:57
source share
1 answer

Scripts are processed using the scripts parameter for the configuration function. For libexec, you can treat them as data files and use data parameters.

 setup(... scripts=glob("bin/*"), data_files=[(os.path.join(sys.prefix, 'libexec', 'mypackage'), glob("libexec/*"))], ... ) 

I'm not sure how this works with the --prefix option, I have never tried this.

+8
May 05 '12 at 3:35 a.m.
source share
— -



All Articles