• We did not send an email asking for donations - please read this post.

Turn your Python script into a command-line application

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,473
Reaction score
1,196
Credits
10,706


captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,913
Reaction score
1,970
Credits
18,126
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
 
OP
Tolkem

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,473
Reaction score
1,196
Credits
10,706
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.
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,570
Reaction score
2,232
Credits
11,611
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.
 

gvisoc

Well-Known Member
Joined
May 29, 2020
Messages
446
Reaction score
535
Credits
4,570
OP
Tolkem

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,473
Reaction score
1,196
Credits
10,706
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.
 

gvisoc

Well-Known Member
Joined
May 29, 2020
Messages
446
Reaction score
535
Credits
4,570
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.
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,570
Reaction score
2,232
Credits
11,611
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!
 

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
647
Reaction score
518
Credits
3,613
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.
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,570
Reaction score
2,232
Credits
11,611
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.
 

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
647
Reaction score
518
Credits
3,613
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.
 

captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,913
Reaction score
1,970
Credits
18,126
my python is only applicable to Arch and those that like a gui
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Staff online

Members online


Top