Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

Alias "python script" to a specified name so as to present a command for a python cli application

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

python .est.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

question from:https://stackoverflow.com/questions/65643522/alias-python-script-to-a-specified-name-so-as-to-present-a-command-for-a-pytho

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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(...).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...