-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
Fixing old sh(...) non-documented method to define special args defaults #271
Conversation
Cool, I'll try to find time this week to review. The one thing that stands out, and you'll want to verify this for yourself, is I believe this |
Good catch, I'll fix that asap. Also, the |
Yeah don't worry about it. Those Travis machines have very unpredictable timing. |
The semantics of the context manager are confusing. When a context manager is instantiated, typically it is used to use it explicitly to manage state. The problem I have with this context manager is there is no explicit state: with sh.defaults(_out=out):
from sh import echo
with sh.defaults(_out=out) as sh2:
from sh2 import echo # new echo
from sh import echo # old echo If the state is implicit, we still run into the old problem I am trying to avoid of globally changing the behavior of with sh.defaults(_out=out):
anothermodule.some_function() Where I want to continue in the direction of explicit state management, so I cannot merge this PR at the moment. |
Strange, I have this strange behaviour where some
Or
They pass Any idea why ?? |
I haven't tried it yet, but I'm going to guess that there is state bleeding between the tests. I would look into removing the module from |
Despite the Travis checks failing (because of Python 3+ installation issues I think), |
@Lucas-C lots of tests, that is great to see :) It will take me awhile to review this..there's quite a bit of code and magic going on, but thanks for the effort you put into the PR. After I finish reviews, I can see this landing in the 1.2 branch |
I'm glad to read this ! |
|
||
def __setattr__(self, name, value): | ||
if hasattr(self, "__env"): | ||
self.__env[name] = value |
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.
What was the reason for removing the __env
stuff?
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 did not remove the __env
, just the __setattr__
magic method.
The reason is that I did not find any use case for it, and all the tests passed ok without it.
So I just removed it to simplify the code.
Apologies for being so slow on this. I actually have some really bad news about this PR. The last few days, I was tinkering with it (just to understand it better), and I noticed the tests fail on python3.3 and python3.4 (but work in 3.2, 3.1 and 3). It turns out that in python3.3 and later, the internal import code requires any module that you load with a fancy importer (like we've done here) be put into However, as your docstring on import sh
sh1 = sh(_out="/dev/null")
from sh1 import ls
print(ls()) # shouldn't print
sh1 = sh()
from sh1 import ls
print(ls()) # SHOULD print, but doesn't!
There really doesn't seem to be a way around this. Python 3.3 and up require the module in |
Glad you found the time to get back to this PR ! ^^ |
It will, yes. I am aiming for some time next week if I can make it through all the issues and PRs by then |
This pull request is an implementation of the changes discussed in #269.
I ended up defining a context manager as its seemed to me the safest and most elegant solution.
Note that this commit removes the old, non-documented, usage to set defaults for all
sh
commands, and its only related test: https://github.com/amoffat/sh/blob/7a4e296/test.py#L1502The reason beeing that it created a very confusing edge case:
I tried many things to work around this issue, but in the end I don't think we can safely allow the
from sh import ...
mecanism AND provide a way to reassignsh
. It is fundamentally incompatible, due to Pythonsys.modules
caching system.As for the documentation, I couldn't find the source anywhere than on http://amoffat.github.io/sh/, so I generated a patch:
https://gist.github.com/Lucas-C/4f466b14061c5fbfbbd8