The Python OS (an OS to run python scripts)

I was bored in class when I came up with a brilliant idea, the Python OS. PyOS. I’ve already started working on it, but I might need some help from the experts on how to make some parts of the interpreter, like how to make it understand the import statements, or if I have to write a compiler for the python code. I want it to be pretty straightforward without the user having to jump a bunch of hoops, but I dont know how to do that.

Other information about it:
The Python OS is simply meant to run python scripts, so that the user can sort of paint off the canvas and expand what they make, since some people might not know much C or assembly. It gives them the base tools to make the bootable drive, they do the rest.

Do you have practical experiences with existing OSes? Stuff like hardware management, program-multitasking management, file system IO are all things that the OS should contain (among many, many other things). Are those going to be written in python? If so, how? If not, why not just make a linux distribution with a python shell as the default interface?

Your description isn’t very clear on what you want, or that you
understand what an operating system actually is.

Most people who lack an intimate familiarity with operating system
internals are usually talking about user interfaces when they say
operating system, so maybe give something like
xonsh · PyPI a try first and see if it’s what you
had in mind (a Python-oriented system shell, like BASH but with
Pythonesque syntax).

If you just want a minimal install of a popular operating system
that has the necessary bits to run the CPython interpreter on, maybe
with a version of the interpreter and stdlib already installed,
Docker is basically lots and lots of
examples of that.

If what you really mean is an operating system written in Python,
that’s a tall order, especially if you want a kernel and
hardware-facing drivers all created from scratch. These are things
that normally have hundreds or thousands of experienced developers
working on them, unless you decide to scope it to just one very
specific set of hardware or only want it to be able to run in a
particular virtual machine, and even then it’s going to prove
challenging. Doing that in Python also doesn’t really make a lot of
sense from a performance or efficiency perspective, which is why
it’s not common to find. Red Hat used to maintain a lot of their
system tools in Python, but embarked on a years-long effort to
rewrite many of them in C for similar reasons.

Just remember that whatever awesome idea you came up with has
probably already been made 10 times over, so a more fruitful
starting point is often to look for something similar to what you
want and then help improve it to suit your needs rather than spend
time making an 11th one from scratch. Or you might even find
something that’s exactly what you were thinking of making, and you
can just use it without needing to do any work yourself. And if it
really hasn’t been made, there are often good reasons why, so doing
a bit more research can save you a lot of time you’d otherwise spend
reaching the same conclusions.

…unless what you really want is just the experience of making it,
and don’t care whether anyone else will (or even can) actually use
it. That can be fun, but so can helping other people with something
that already exists and is more likely to teach you useful skills
than going it yourself ever will.

1 Like

Lets change the question, because I think I should have a compiler system. How do I make a compiler that includes the dependencies like the import statements?

Also, tn answer the question of will I make this all in python, no I will not. That is not possible, as python does not have any good interaction with the actual hardware itself.

You’ve probably got to parse the Python code itself. Fortunately, Python
can do this for you :slight_smile: Use the compile() function:

which gets you an Abstract Syntax Tree (AST) (with the right flag).

See the ast module for how to work with an AST:

1 Like