0

I'm writing a package that wraps a non-python program that myself and my team often have to automate. I'm packaging this with setuptools and want to make it available to our other developers OR to our operations team.

Here's what I want to do. The program it wraps obviously needs to be there for my module to work. So, I'm thinking I need setuptools to check to see if it's installed and if it's not, install it.

Is there a way to do this within setup() OR is that step going to need to be manual (or handled by something else)? OR... should this just be something that stays in the module? It's about 50MB, so not horribly huge.

1 Answers1

1

your program needs an installation or you have a portable version?

If it is portable, you can trigger it with relative paths and then recreate the same structure in your compiled python script.

folder/
 main.py
 bin/
   file.exe

Let's say that you want to call you binary from the main.py

# main.py
import os

# get the current directory dynamically
base_dir = os.getcwd()
# create the file path
file_path = os.path.join(base_dir, 'bin',  'file.exe')
# run the file
os.system(file_path)

After compiling the file, you should create the folder bin in the destination and copy inside your file.exe

mabe02
  • 2,676
  • 2
  • 20
  • 35
  • It can be portable. So.. if I understand your response, if it CAN be portable, then I just put it my package.. say under "bin" or something like that, then reference it accordingly. No need to install it. Is that correct? – Thomas Lester Jan 20 '16 at 21:26
  • Yes! I compiled for instance some programs that were using external executables (e.g. phantomjs.exe). I was just referring in my file using a relative path and then I recreate the same path inside the destination folder. It should work fine – mabe02 Jan 20 '16 at 21:29
  • 1
    If you want some tips about how to perform relative imports, you can refer to the first part of [this answer](http://stackoverflow.com/a/34772426/5687152) – mabe02 Jan 20 '16 at 21:30
  • @tomlester I added some example to explain better what I wrote in the comment – mabe02 Jan 20 '16 at 21:54
  • Just for clarification, when the module executes either from an import into another script or from python -m , is the CWD the root of package or directory the script is being called from? – Thomas Lester Jan 21 '16 at 20:00