0

I currently writing a python cli application that takes in a CSV file as an argument and various options from the cli.

python .\test.py data.csv
usage: test.py [-h] [-v | -q] [-o] filepath

I want to alias or replace the python ./test in the cli with another word so as to look like a command like angular or git cli. For example rexona data.csv -o.

I want to do that on both Windows and Linux so as I can publish it as a PyPI distribution.

Thank you

Omar Jarkas
  • 100
  • 5
  • 1
    Are you aware that packaging (what is needed for publishing on PyPI) allows to automatically create such application-like scripts as ``entry_points`` ``console_scripts``? What problem do you have to just *rename* ``test.py`` to the desired name? – MisterMiyagi Jan 09 '21 at 14:07
  • 1
    Recommend watching this: https://www.youtube.com/watch?v=GIF3LaRqgXo&ab_channel=CodingTech – Leemosh Jan 09 '21 at 14:10
  • 1
    + adding the entry points to the setup.py as in the answer. – Leemosh Jan 09 '21 at 14:17
  • 1
    Get out of the habit of just running commands from whatever directory you use for writing the script, and properly *install* your scripts, even if only to `~/bin` or your OS's equivalent. – chepner Jan 09 '21 at 14:17

1 Answers1

3

Aliasing is a very OS and environment-dependent and is not the correct way to achieve what you are looking for.

Instead, you should use the tools offered by the packaging tool you are using to create the distributed package.

For example, if using setup.py then add

entry_points={
        'console_scripts': ['rexona = path.to.module:function_name']
    },

to the call to setup(...).

DeepSpace
  • 78,697
  • 11
  • 109
  • 154