-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add support for reading .pyc
files
#565
Conversation
I've started working on the PR but I would need some help increasing the test coverage. Even with the added tests, it's currently at 96.34% (with a perplexing reverse line number range in the missing column).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks very promising!
The coverage is also a 100% now as some unnecessary (and unreachable) code paths were removed! It's still in draft because point 1 of my issue remains to be addressed in a clean idiomatic way. I am thinking of defining a new wrapper (over That way one could write the following snippet: include(
chain(
"source_code.py",
compiled("byte_code.pyc"),
),
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
tests/settings/merged/__init__.py
Outdated
@@ -16,6 +16,9 @@ | |||
# Missing file: | |||
optional('components/missing_file.py'), | |||
|
|||
# Missing compiled file | |||
optional(compiled("components/missing_file.pyc")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we need to test this more. Can you please create a new test with existing optional(compiled('file'))
and compiled(optional('file'))
?
What do you think: should we allow arbitary nesting? Or should we only use one way? Or maybe optional_compiled
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think optional(compiled())
makes sense because it indicates that a compiled-file may optionally be present.
The opposite nesting compiled(optional())
seems to imply that a file may or may not be present but has to be compiled? That's not making sense to me.
It seems to me here that enabling the former nesting order covers the possible need and it becomes a question of having adequate documentation to discourage any accidental use of the latter nesting order.
Also compiled(optional(())
doesn't work (in the current implementation) because it loses the wrapping of _Optional
once it is wrapped by _Compiled
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't forget to document that.
@sobolevn I have been thinking more about the Building on the example in the |
I don't think that it is safe to include both source and compiled in wildcards. I would suggest to only support explicit compiled files. |
So would we filter the output of the |
Yes, we should raise an error when |
Okay, so there are a few issues with the docs that I will look into in a bit. I have to write some new docs about the additions here anyway. But does the code approach taken here look good to you @sobolevn? I also added a bunch of test cases for all supported nesting of |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #565 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 3 +2
Lines 41 121 +80
Branches 7 23 +16
=========================================
+ Hits 41 121 +80 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that OneOf
adds some other feature we didn't discuss ;)
It also feels like a very complex solution. Please, remove it.
I also think that Entry
should not be used, because str
worked just fine. Let's keep things as simple as possible :)
I am going to have to bail on this PR.
I'm really sorry that I could not complete this, but deepest thanks for your time and your continuous advice on improving the code. It has been incredibly helpful. Additionally, please feel free to close #563 if you too feel like it is adds complexity with little utility. |
THANK YOU FOR YOUR WORK 👏 |
Fixes
Fixes #563 by @dhruvkb
Description
This PR adds support for reading settings from
.pyc
files. It does so by usingmarshal.load
instead ofcompile
when the file extension is.pyc
.To verify that this works, it intentionally compiles an existing
.py
file into its.pyc
before running the tests, checks that the contents of the file are still read into settings as expected, and then restores the.py
file back.