-
-
Save spookyahell/2d70ab61030882ed7d528e3770215351 to your computer and use it in GitHub Desktop.
py for Linux - Ever wanted sth like the py launcher but for linux... just copy this do /bin and chmod +x /bin/py to make it executable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3.6 | |
from subprocess import call | |
from shutil import which | |
from sys import exit as sexy_exit, argv | |
from re import fullmatch | |
from os import environ | |
from os.path import join as path_join, isfile | |
command = 'python3.6' | |
PATH = path_join(environ['HOME'],'pydef') | |
if isfile(PATH): | |
with open(PATH) as x: | |
command = x.read() | |
del argv[0] | |
set_def = False | |
for idx,arg in enumerate(argv): | |
if arg == '-sad': | |
arg = '--set-as-default' | |
if arg == '--set-as-default': | |
del argv[idx] | |
set_def = True | |
break | |
for idx,arg in enumerate(argv): | |
x = fullmatch('-(\d).?(\d)?', arg) | |
if x: | |
del argv[idx] | |
vP1 = x.group(1) | |
vP2 = x.group(2) | |
if vP2: | |
if which(f'python{vP1}.{vP2}') is not None: | |
command = f'python{vP1}.{vP2}' | |
else: | |
print('You don\'t have that version of python installed') | |
sexy_exit(100) | |
else: | |
for i in range(0,10): | |
if which(f'python{vP1}.{i}'): | |
command = f'python{vP1}.{i}' | |
break | |
if set_def: | |
print('Setting default...') | |
with open(PATH,'w') as x: | |
x.write(command) | |
x = call([command] + argv) | |
sexy_exit(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this currently does not replicate at any length py on windows for linux... it only gives you the basic features... for development I strongly suggest using the original package name like
python3.6
The probably most important missing feature is traceback, which this does not handle correctly, you will only see the internal tracback from this file....