Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

feat: implement bytecode/pyc compilation - #103

Merged
wolfv merged 5 commits into
prefix-dev:mainfrom
baszalmstra:feat/bytecode_compilation
Dec 4, 2023
Merged

wolfv merged 5 commits into
prefix-dev:mainfrom
baszalmstra:feat/bytecode_compilation

Conversation

@baszalmstra

Copy link
Copy Markdown
Contributor

Adds pyc compilation.

Since most of the time we want to install multiple wheels at the same time and since starting the Python interpreter has a non-negligable amount of overhead, a compilation daemon is spawned as a subprocess.

Closes #60


// The file that contains the python source code of the compilation host. We keep this around
// to make sure the file is not accidentally deleted while the compilation host is still using
// it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is actually only potentially a problem on Windows, right? On macOS and Linux it shouldn't matter if the file is deleted while Python is running.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We need to make sure the file exists when python is still initializing. The new method starts the executable but there is no way to be certain that python already read the source code. To that end, I just keep the file around as long as the process is alive but in theory it could also just be deleted somewhere earlier.

let compiler = ByteCodeCompiler::new(&python_path).unwrap();
compiler
.compile_and_wait(compiler_source.path())
.unwrap_err();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this mean the process will fail when it can't compile a file? I think usually we should ignore failures – it can happen that some Python file can only be compiled with a newer version, or has some template variables in it etc. so we should silently fail (or with a trace::warn or so).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes! I will change the unpack behavior to just ignore these errors.

@wolfv
wolfv merged commit ae6e1cb into prefix-dev:main Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bytecode compilation

2 participants