X Tutup
Skip to content

feat: add transparent Python CLI wrapper#62

Open
sarr266 wants to merge 1 commit intoUniversalPython:mainfrom
sarr266:feature/wrap-python-cli
Open

feat: add transparent Python CLI wrapper#62
sarr266 wants to merge 1 commit intoUniversalPython:mainfrom
sarr266:feature/wrap-python-cli

Conversation

@sarr266
Copy link
Contributor

@sarr266 sarr266 commented Feb 24, 2026

Lightly wrap the Python CLI so that UniversalPython behaves as a transparent superset, UP-specific flags are handled by UP, everything else (e.g. -c, -m, unknown flags) is forwarded directly to the real Python interpreter.

image

@SaadBazaz
Copy link
Collaborator

Hey @sarr266 , will test this over the weekend

Copy link
Collaborator

@SaadBazaz SaadBazaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes / explanations needed

" -k, --keep Save compiled .en.py file and run\n"
" -ko, --keep-only Save compiled .en.py file without running\n"
"\n"
"Anything else (e.g. -c, -m, script.py) is forwarded to Python as-is."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run python --help and append its output here (filtering out the ones which conflict with UniversalPython's flags, instead of writing 'anything else'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D:\UniversalPython>universalpython --help
UniversalPython — Python, but in your native language.

Usage:
universalpython Compile & run a UniversalPython file
universalpython --options Compile & run a UP file (explicit)
universalpython --version | -V Show UP + Python version
universalpython --help | -h Show this help message

UP compile options:
-o, --options Compile & run a UniversalPython file
-t, --translate [engine] Translate identifiers (unidecode | argostranslate)
-d, --dictionary Path to language dictionary YAML
-sl, --source-language Source language code (e.g. fr, de)
-r, --reverse Reverse-translate (English → target language)
-re, --return Return compiled code instead of executing
-k, --keep Save compiled .en.py file and run
-ko, --keep-only Save compiled .en.py file without running

The following Python flags are passed through directly:
Options (and corresponding environment variables):
-b : issue warnings about str(bytes_instance), str(bytearray_instance)
and comparing bytes/bytearray with str. (-bb: issue errors)
-B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I : isolate Python from the user's environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O : remove assert and debug-dependent statements; add .opt-1 before
.pyc extension; also PYTHONOPTIMIZE=x
-OO : do -O changes and also discard docstrings; add .opt-2 before
.pyc extension
-P : don't prepend a potentially unsafe path to sys.path
-q : don't print version and copyright messages on interactive startup
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S : don't imply 'import site' on initialization
-u : force the stdout and stderr streams to be unbuffered;
this option has no effect on stdin; also PYTHONUNBUFFERED=x
-v : verbose (trace import statements); also PYTHONVERBOSE=x
can be supplied multiple times to increase verbosity
-W arg : warning control; arg is action:message:category:module:lineno
also PYTHONWARNINGS=arg
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
-X opt : set implementation-specific option
--check-hash-based-pycs always|default|never:
control how Python invalidates hash-based .pyc files
--help-env : print help about Python environment variables and exit
--help-xoptions : print help about implementation-specific -X options and exit
--help-all : print complete help information and exit
Arguments:
file : program read from script file

  •  : program read from stdin (default; interactive mode if a tty)
    

arg ...: arguments passed to program in sys.argv[1:]

Is this the output you were expecting?


ap.add_argument("-re", "--return",
action='store_false',
action='store_true',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... why was this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, this must stay store_false, i must have been experimenting with something


args = vars(ap.parse_args())

if args['dictionary']:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed this time? It seems like it might affect compilation ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting this error: D:\UniversalPython>universalpython test\samples\de\hello.de.py --dictionary languages\de\default.yaml
D:\UniversalPython\universalpython\modes\lex.py:23: RuntimeWarning: Could not load language dictionary file. Defaulting to English Python.
Documentation: https://universalpython.github.io
warnings.warn(
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\Sarah\AppData\Local\Programs\Python\Python311\Scripts\universalpython.exe_main
.py", line 6, in
File "D:\UniversalPython\universalpython\universalpython.py", line 308, in main
return run_module(mode, code, args)
File "D:\UniversalPython\universalpython\universalpython.py", line 160, in run_module
return mod.run(args, code)
File "D:\UniversalPython\universalpython\modes\lex.py", line 39, in run
return code if args.get("return") else exec(code)
NameError: name 'ausgeben' is not defined

Before the fix, languages\de\default.yaml was passed as-is to lex.py (a relative path). After the fix, os.path.abspath('languages\de\default.yaml') converts it to D:\UniversalPython\universalpython\languages\de\default.yaml (the actual location of the file) before it reaches lex.py. So lex.py gets a full path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup