Skip to content
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

[question] Packaging python pyc files #5404

Closed
keithrob91 opened this issue Jun 26, 2019 · 8 comments
Closed

[question] Packaging python pyc files #5404

keithrob91 opened this issue Jun 26, 2019 · 8 comments
Assignees

Comments

@keithrob91
Copy link

I've just discovered that packaging of pyc files (within __pycache__ directories) doesn't seem to work.

I believe its because of the checks within discarded_file() and gather_file() within manifest.py that deliberately exclude files called .pyc and directories called __pycache__

Is there anyway to make this work or is it a feature request?

@memsharded
Copy link
Member

This is deliberate. .pyc files are not intended to be portable, as they depend on the python version, etc. which is something not possible to control with Conan, as Conan itself could be running under different python versions, and that is not controlled.

https://stackoverflow.com/questions/11368304/what-are-the-limitations-of-distributing-pyc-files

@memsharded
Copy link
Member

quick question: what would be the use case? Even for pretty large python codebases, it is not a big issue to distribute .py and let python bytecompile them the first run.

@keithrob91
Copy link
Author

quick question: what would be the use case? Even for pretty large python codebases, it is not a big issue to distribute .py and let python bytecompile them the first run.

We create 'secure appliances' which means we lock down the application and O/S in certain ways to protect it from attack. One of these protection mechanisms is to use Advanced Intrusion Detection Environment (AIDE) to protect files and directories from being changed maliciously.

This causes a problem when .pyc files are generated as this would be a change to a directory we monitor, which would trigger AIDE, which would shut the system down! Also, as it is the .pyc file that would subsequently be used by Python, not the original .py file, we would want to protect both the .py and .pyc files from modification.

In short, we want to distribute the .pyc files on install so that AIDE can (1) protect them and (2) not have to care about them suddenly appearing.

@keithrob91
Copy link
Author

There are of course ways we can get around this without using Conan, but, we liked the idea of using Conan!

@keithrob91
Copy link
Author

One last thing! If you look at Redhat supplied Python RPMs, they ship the .pyc files, so it isn't a totally crazy thing to do.

@memsharded
Copy link
Member

Ok, thanks for the clarification. It doesn't seem possible, it is too deep in conan code, and distributed in different places, it would be too breaking. I am having a look, but it seems you would need some kind of workaround, like zipping them first or something like that.

I don't know if it could be another type of workaround, but if generating .pyc files is the thing breaking in the target, then maybe sys.dont_write_bytecode = True would avoid that completely and could help too?

@memsharded
Copy link
Member

memsharded commented Jun 26, 2019

Also, this would be a duplicate of: #4961. I am closing this one, please follow up there. Thanks!

@keithrob91
Copy link
Author

I don't know if it could be another type of workaround, but if generating .pyc files is the thing breaking in the target, then maybe sys.dont_write_bytecode = True would avoid that completely and could help too?

Thank you for the suggestion, we considered that, but have discounted it. I'm now following #4961 with interest! For now we will go with a workaround like the zip option or something similar.

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

No branches or pull requests

2 participants