Turn your Python script into a command-line application

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,567
Reaction score
1,284
Credits
11,462


I find python easier than bash so i turned to it when i wanted a gui and associated backend to sort mirror list for pacman and then write it to /etc/pacman.d/mirrorlist

will have to check out article when brain is more switched on
 
I find python easier than bash
I'm the opposite; I find bash easier than python, but yeah, among the few languages I played with, python is one of the easiest to learn, tho I do struggle with a few concepts and that's why I've never managed to completely learned it but just a little beyond the basics ... just a little.
 
Hmm, seems like a lot of extra hassle! I usually just bung my scripts into somewhere in $PATH and viola - instant command line application!

Be they Bash, Python, Ruby, Lua, or Perl, as long as any main scripts have a shebang with a path to the appropriate interpreter and have executable permissions, once they’re in $PATH, they will run as if they are normal system applications.

No additional frameworks required!
If any of my scripts use graphical modules, e.g. Python scripts/applications using pyqt, or OpenGL - they will run graphically on the desktop (as long as X is running!).

You can easily add your personal/custom scripts/applications to your desktops launcher/menu too, by adding appropriate .desktop files for them.
 
Hmm, seems like a lot of extra hassle! I usually just bung my scripts into somewhere in $PATH and viola - instant command line application!
Aside from managing the dependencies manually, which you can solve with some other tools, why don’t just put #!/path/to/python at the beginning, and done?
Well, I'm not an expert by any means, but ...
PyScaffold is a project generator for bootstrapping high quality Python packages, ready to be shared on PyPI and installable via pip. It is easy to use and encourages the adoption of the best tools and practices of the Python ecosystem, helping you and your team to stay sane, happy and productive. The best part? It is stable and has been used by thousands of developers for over half a decade!
I think, this procedure is more like for when you plan to share your "CLI app/tool" with other people as stated in the quote above from here https://pypi.org/project/PyScaffold/, and to make sure it not only "works for you", but everyone else.
 
That's a bit more than creating a CLI, yes. Seems similar to Poetry, which is the one I used to tinker with, alongside with other development utilities.

Check this repo if you're also into dealing with unit tests, linters/checkstyle, and coverage https://github.com/gvisoc/python-project-template. Those may be a good addition to PyScaffold if you want to publish some apps.
 
Ah, I see! So this is about packaging your Python scripts/applications for distribution?!
I must have somehow missed that.

Saying that - I only skimmed over the article in the link in the original post whilst waiting for a debug build to finish at work.
I wrote my response during another debug build!
 
I might be wrong but isn't turning a script into an application just a matter of: saving the script as a .sh file, making it executable and then creating a .desktop file for it? That's how I use my scripts as applications whenever I need them. Sure, they're bash scripts but scripts nonetheless.
 
I might be wrong but isn't turning a script into an application just a matter of: saving the script as a .sh file, making it executable and then creating a .desktop file for it? That's how I use my scripts as applications whenever I need them. Sure, they're bash scripts but scripts nonetheless.
That's what I said - but I only skimmed through the article without reading it properly.

It's actually talking about using a framework called Scaffold, in order to package your python scripts/applications, so they can be installed on other systems via pip, or shared on pyPI.
 
It's actually talking about using a framework called Scaffold, in order to package your python scripts/applications, so they can be installed on other systems via pip, or shared on pyPI.
If the script has commands specific to a certain distro only, that might be useful. But if the script has commands common for all distros, it's pointless to waste time using that framework. But in the past 7 years I haven't seen a single distro-specific script.
 
my python is only applicable to Arch and those that like a gui
 

Members online


Top