-
-
Notifications
You must be signed in to change notification settings - Fork 658
python.com
The third_party/python
folder in the repo contains a copy of the CPython
3.6.14 source code, with several patches to improve performance and make use of
all the goodies offered by Cosmopolitan Libc, which include: loading pure-python
packages from within the executable, backports from Python 3.7, tab-completions
in the REPL (read-eval-print-loop) via bestline
, size optimization tricks and
more!
git clone https://github.com/jart/cosmopolitan
cd cosmopolitan
make o//third_party/python/python.com # this will build python.com only
make o//third_party/python # this will run CPython stdlib tests as well
./o/third_party/python/python.com
As part of the repo, python.com
can be built as a Makefile
target. The
configuration and build requirements for python.com
are specified in
o//third_party/python/python.mk
-- no need to run ./configure
.
-
The files comprising the CPython 3.6.14 standard library are stored within the executable itself, which you can view by:
unzip -vl python.com
to add your own files to
python.com
, just:mkdir ./.python cp /your/package.py ./.python zip -r ./python.com ./.python
now you can import your own package within
python.com
. -
.args
support: if you wantedpython.com
to run a specific script on startup instead of opening the REPL, you can create a file called.args
and add it topython.com
. This is very useful if you want to renamepython.com
into your own executable and perform only some specific behavior. See the example below:
The .args
file should have one argument per line. These arguments are
inserted before other CLI arguments. The ...
indicates that arguments from
the command line should be accepted.
-
python.com
has been modified to usebestline
, enhancing the REPL experience across operating systems:
see the copy
typed, and the right
being suggested in the background?
That's bestline
in action. It helps a ton when typing in the REPL.
-
python.com
provides a special module calledcosmo
, which provides access to some low-level utilities from the Cosmopolitan Libc library. For example, you could:
import cosmo
# view number of CPU cycles
# since the program started
print(cosmo.rdtsc() - cosmo.kStartTsc)
def foo(a, b):
return a+b
# trace C function calls in a block
# (needs python.com.dbg, output logged to stderr)
with cosmo.ftrace() as f:
foo(2,3)
Reading through some of the issues/PRs related to the development of
python.com
in the Cosmopolitan Libc repo would help understand how python.com
came
to be: