I am writing a Python package mypackage
in which I have to include Fortran executable binaries that I have precompiled for Linux, Mac and Windows. I want to upload them all, but then when the User does pip install my package
, it should only download the relevant binaries and add them to $PATH such that I can run subprocess.call(bin1)
later, to call the binary.
The package looks like
Project/
|-- bin/
| |-- mac/
| | |--bin1
| | |--bin2
| |-- windows/
| | |--bin1
| | |--bin2
| | |--dllfile_1
| | |--dllfile_2
| |-- linux/
| |--bin1
| |--bin2
|
|-- src/
| |
| |-- __init__.py
| |-- main.py
|
|-- setup.py
|-- README
and in my setup.py I have tried something like:
import system
if system == 'Linux':
bin1 = 'bin/linux/bin1'
bin2 = 'bin/linux/bin2'
os='linux'
if system == 'Windows':
bin1 = 'bin/win/bin1.exe'
bin2 = 'bin/win/bin2.exe'
os='win'
if system == 'Darwin':
bin1 = 'bin/mac/bin1'
bin2 = 'bin/mac/bin2'
os='mac'
Then, if in my setuptools.setup()
I include data_files = [('bin',[bin1,bin2])]
. When I upload the package from Mac, that seems to only work on Mac as it only uploads the Mac binaries (so better than nothing, but even that is insufficient). However, I will need to do something like data_files = [('bin',glob(f'{os}/*'))],
(to include the dll files for win) which doesn't seem to work at all (i.e. pip show -f my package
doesn't include any of the binaries, whereas it does for the former case). What is the best solution to this? Do I need to specify all paths to all binaries in data_files (if so, how, because the glob() thing doesn't seem to work) - and then how are only the os-specific binaries (and also dll files if win) downloaded upon pip install my package
.
All other questions that I found similar to this are either too different or don't do exactly what I want.