Skip to content

Allow stdlib freeze #1159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 24, 2019
Merged

Allow stdlib freeze #1159

merged 7 commits into from
Jul 24, 2019

Conversation

palaviv
Copy link
Contributor

@palaviv palaviv commented Jul 20, 2019

As discussed in #1142.
Adding the current Lib folder increase the executable by 5MB. I would like to add this to the demo so it will support python stdlib.
I wanted to allow specifying the location of the stdlib dir with a compilation flag but could not find out how to do that. @coolreader18 any suggestions?

@palaviv palaviv requested a review from coolreader18 July 20, 2019 15:25
Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

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

LGTM. An idea for allowing specifying the stdlib dir, you could maybe allow a DirFromEnv CompilationSourceKind?


fn compile_dir(
&self,
path: &PathBuf,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
path: &PathBuf,
path: &Path,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is this better?

Copy link
Member

Choose a reason for hiding this comment

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

PathBuf vs Path is akin to String vs str - an owned, allocated buffer vs a slice. Like you should (almost) always prefer &str over &String, so should you for &Path over &PathBuf.


let output = quote! {
({
use ::rustpython_vm::__exports::bincode;
bincode::deserialize::<::rustpython_vm::bytecode::CodeObject>(#bytes)
.expect("Deserializing CodeObject failed")
hashmap! {
Copy link
Member

Choose a reason for hiding this comment

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

You should probably add hashmap to __exports and use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the purpose of the __exports? This is my first time using procedural macro

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 think I understand what __exports do. Added hashmap

@windelbouwman
Copy link
Contributor

Btw, I opened this issue in pyckitup: pickitup247/pyckitup#4 they might be interested in this.

@palaviv
Copy link
Contributor Author

palaviv commented Jul 20, 2019

Btw, I opened this issue in pyckitup: pickitup247/pyckitup#4 they might be interested in this.

We should probably add the ability to freeze any directory.

LGTM. An idea for allowing specifying the stdlib dir, you could maybe allow a DirFromEnv CompilationSourceKind?

I can get the directory from an environment variable but I hoped for something easier.

@coolreader18
Copy link
Member

Ah yeah, I think that's the best way to go for configuration, as Rust doesn't have anything like that built in. We've done similar configuration in env variables before, e.g. BUILDTIME_RUSTPYTHONPATH

@coolreader18
Copy link
Member

I sorta glazed over this when I reviewed earlier, but I don't think that it should always return a HashMap, it should only do that when the source is Dir.

@palaviv
Copy link
Contributor Author

palaviv commented Jul 22, 2019

I sorta glazed over this when I reviewed earlier, but I don't think that it should always return a HashMap, it should only do that when the source is Dir.

I am not sure about that... I prefer that py_compile_bytecode will return the same type on all cases. I think it will be confusing otherwise.

@palaviv palaviv merged commit 6ca979e into RustPython:master Jul 24, 2019
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.

3 participants