1

I have a program, that performs (in logical terms) 3 different operations. So far i've written a module and a main.py script that imports module's files and executes. Structure:

── jasper
│   ├── crispr.py
│   ├── database.py
│   ├── __init__.py
│   ├── io.py
│   ├── __pycache__
│   ├── trna.py
│   └── utils.py
├── lib
│   └── python3.8
├── lib64 -> lib
├── LICENSE
├── main.py
├── pyvenv.cfg
├── README.md
├── requirements.txt

I call it like that python main.py --args. What I would like to be able is to do something like this python jasper.database --args, python jasper.crispr --args etc. Every single file would have it's own argparse and would perform different task. I would like to do it also after setuptools installation, so the part python jasper.database --args would be executed without python part, like this: $ jasper crispr --args or $ jasper.crispr --args

777moneymaker
  • 697
  • 4
  • 15
  • Do you need to call the functions from CLI or would it be acceptable to call them from within a python shell? – Dschoni Jan 14 '21 at 12:53
  • @Dschoni I have to run the files from CLI. The program will be configured with setuptools and so it has to work like this `$ jasper.crispr --args` after installation. – 777moneymaker Jan 14 '21 at 12:56
  • 1
    To execute without python, you need to make an executable out of the module, which is in most cases platform dependend. So which OS are you on? – Dschoni Jan 14 '21 at 12:56
  • 1
    Instead a workaround would be to register an alias for each call so e.g. `python main.py --jasper.crispr` becomes `jasper-crisper --args` – Dschoni Jan 14 '21 at 13:04
  • @Dschoni platfrom is mainly linux (Ubuntu 18.04 LTS), with optional MacOS. – 777moneymaker Jan 14 '21 at 13:36
  • So, making a executable on *nix can be done like this: https://stackoverflow.com/questions/304883/what-do-i-use-on-linux-to-make-a-python-program-executable or https://stackoverflow.com/questions/193077/standalone-python-applications-in-linux . I'm still not 100% sure if this is the correct solution to your problem. Do you want to distribute the program so that it can be run without having python installed or do you just want to run shortcuts locally? In the later your solution will be aliasses. – Dschoni Jan 14 '21 at 13:51
  • 1
    I think you really want to distribute your module as a package instead of producing an executable for every sub-module. You should define an entry-point that makes sense and probably define an API that is a little more transparent then calling python modules. – Dschoni Jan 14 '21 at 14:02

0 Answers0