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

Add 'sshkey' context manager #242

Merged
merged 6 commits into from Jan 22, 2015
Merged

Conversation

@teeberg
Copy link

@teeberg teeberg commented Jan 21, 2015

Proposed implementation for #234

I have done some manual tests, but not set up automated tests yet. I will see how it fits into your suite tomorrow if you haven't implemented it yet. :)

Let me know if something's not quite in the right place.

@teeberg teeberg changed the title Add `sshkey` context manager Add 'sshkey' context manager Jan 21, 2015
@coveralls
Copy link

@coveralls coveralls commented Jan 21, 2015

Coverage Status

Coverage remained the same when pulling 8fbe7ee on teeberg:master into bb0f3d7 on gitpython-developers:master.

git/cmd.py Outdated
self.set_environment(**old_env)

@contextmanager
def sshkey(self, sshkey_file):

This comment has been minimized.

@Byron

Byron Jan 21, 2015
Member

For a moment I thought this method is to specific, but on the other hand, it makes setting ssh-keys (by using key-files) really easy.
Therefore the only thing I will do is see how this works on windows, and possibly put in an assertion to run on non-windows systems only.

@@ -0,0 +1,9 @@
#!/usr/bin/env python

This comment has been minimized.

@Byron

Byron Jan 21, 2015
Member

Possibly the MANIFEST.in file needs adjustment to assure this file also gets distributed when making new releases through setuptools.

git/cmd.py Outdated
@@ -603,6 +610,73 @@ def execute(self, command,
else:
return stdout_value

def set_environment(self, **kwargs):

This comment has been minimized.

@Byron

Byron Jan 21, 2015
Member

From looking at the implementation, I'd be tempted to call this method update_environment. set_environment seems to be more like this:

res = self._environment
self._environment = kwargs
return res
git/cmd.py Outdated
return old_env

@contextmanager
def environment(self, **kwargs):

This comment has been minimized.

@Byron

Byron Jan 21, 2015
Member

This is an interesting one ! When used as with repo.git.environment(FOO='bar'):, the name makes total sense. When I imagine to write a test-case, I'd probably want to query the current state of the custom environment like this too: repo.git.environment(), following the set_foo(), foo() convention.

Can you imagine a better name for environment() to get a context manger ? I know, it's sweet and short already and anything else will make it longer ... with altered_environment(), with changed_environment(), with custom_environment() ?

@Byron
Copy link
Member

@Byron Byron commented Jan 21, 2015

Thank you !
It looks very good already, and is more feature-rich than I would have done it, thanks to your personal interest.

@@ -153,3 +153,23 @@ def test_env_vars_passed_to_git(self):
editor = 'non_existant_editor'
with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}):
assert self.git.var("GIT_EDITOR") == editor

def test_environment(self):

This comment has been minimized.

@teeberg

teeberg Jan 22, 2015
Author

I don't see how I could test the sshkey context manager without accessing an actual repo. Also, how could I check whether the environment is actually passed into the git process? The former would cover the latter. Do you have ideas?

This comment has been minimized.

@Byron

Byron Jan 22, 2015
Member

Something that could work is to adjust the script for the test to actually fail with a distinct error code, and possibly emit something distinctive to STDERR.
That way, you could call the real git process, on a bogus git@server:foo/bar repo URL, and verify that it failed under your conditions. That can proof that the script was actually called.
The cool thing is that this would require you to put in a way to adjust the path the script handling the GIT_SSH, which could be done so that advanced users can either set it, or derive from the Git command implementation.

@coveralls
Copy link

@coveralls coveralls commented Jan 22, 2015

Coverage Status

Coverage remained the same at % when pulling 6f03861 on teeberg:master into d565a87 on gitpython-developers:master.

@Byron
Copy link
Member

@Byron Byron commented Jan 22, 2015

You did it !
The only minor issue I am still choking on is the with repo.git.with_environment(...) notation of the context manager and the seemingly redundant use of with_ .

Note to self: Test this on windows and at least throw saying sshkey doesn't work, if it doesn't work

Also I believe today will be the day, as I should get through my docs review, and prepare a new release.

@Byron Byron merged commit 6f03861 into gitpython-developers:master Jan 22, 2015
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@Byron
Copy link
Member

@Byron Byron commented Jan 24, 2015

Before I forget: I had to remove sshkey from the release, as I was unable to tell setup.py to keep that file where it is after installation, AND keep it executable.
I think I even recorded my futile attempt to beat setuptools in all it's glory and uploaded it on youtube.

@teeberg
Copy link
Author

@teeberg teeberg commented Jan 24, 2015

Thanks for the note, I already saw it! :) I didn't realise it would be such a pain! I'll stick with my local SSH script then in the meantime. :-) Thanks for merging everything else in!

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

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.