Package a python project using batch scripts

681 views Asked by At

Hi I currently have a python project that uses subprocess. Popen to run some batch files.

Is it possible to package the batch file as source. Thus, when some of our other python project use setup.py to include the current python project in install_requires, the other project could install and update those batch files and uses it from source (i.e. run these script with subprocess. Popen as well)?

Anyone have some idea how should I do it?

Thanks in advance!

1

There are 1 answers

0
Billy On

If you have bash scripts that are required to run your python package, you could simply store them within your package folder and they should be included when installing the package using setuptools. Here is an example of a possible folder structure:

/myproject
    /myproject
        __init__.py
        main.py
        batch.sh
    setup.py

In the main.py you could access the batch file by:

import os.path
import subprocess

current_dir = os.path.dirname(os.path.abspath(__file__))
batch_script = os.path.join(current_dir, 'batch.sh')
subprocess.call(batch_script)

UPDATE

Based on other comments, if you instead need a way to make batch scripts accessible to third party packages, you could specify the scripts in the 'scripts' key in setuptools. You can see this available option in setuptools here.