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

Fix nested contexts duplicating commands #691

Merged
merged 1 commit into from
Aug 7, 2023

Conversation

johntrimble
Copy link
Contributor

@johntrimble johntrimble commented Jul 29, 2023

This PR fixes an issue where using nested command contexts would duplicate commands upon execution. This comes about because all created commands are prepended by any containing commands used as a with-context. Since commands used as a with-context also get prepended, we end up getting duplicated commands when are contexts are nested.

We solve the problem by simply not prepending to commands used as a context.

Resolves #690

@johntrimble
Copy link
Contributor Author

I had some difficulty getting the test docker image to work, but with some fiddling, I did get the test runner working for python 3.8 and all the tests for that at least passed.

Got these errors trying to run the test docker image:

 => ERROR [ 7/12] RUN apt-get -y install    python3.8    python3.9    python3.10    python3  2.2s
------                                                                                            
 > [ 7/12] RUN apt-get -y install    python3.8    python3.9    python3.10    python3.11:          
#10 0.326 Reading package lists...                                                                
#10 1.707 Building dependency tree...                                                             
#10 1.901 Reading state information...
#10 2.154 E: Unable to locate package python3.9
#10 2.154 E: Couldn't find any package by glob 'python3.9'
#10 2.154 E: Couldn't find any package by regex 'python3.9'
#10 2.154 E: Unable to locate package python3.11
#10 2.154 E: Couldn't find any package by glob 'python3.11'
#10 2.154 E: Couldn't find any package by regex 'python3.11'

After temporarily updating the image to just use 3.8, I got this error when running the tests:

docker run -it --rm amoffat/shtest tox -p
py38-locale-utf8-poller-poll: FAIL ✖ in 4.26 seconds
py38-locale-utf8-poller-poll: commands[0]> python test.py
py38-locale-utf8-poller-poll: exit 1 (0.23 seconds) /home/shtest> python test.py pid=40
py38-locale-c-poller-poll: FAIL ✖ in 4.3 seconds
Traceback (most recent call last):
  File "test.py", line 27, in <module>
    import sh
  File "/home/shtest/sh.py", line 70, in <module>
    __version__ = metadata.version("sh")
  File "/usr/lib/python3.8/importlib/metadata.py", line 472, in version
    return distribution(distribution_name).version
  File "/usr/lib/python3.8/importlib/metadata.py", line 445, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.8/importlib/metadata.py", line 169, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: sh

@johntrimble johntrimble marked this pull request as ready for review July 29, 2023 23:19
@amoffat
Copy link
Owner

amoffat commented Aug 1, 2023 via email

Copy link
Owner

@amoffat amoffat left a comment

Choose a reason for hiding this comment

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

Good work

@amoffat amoffat merged commit 8512ec8 into amoffat:develop Aug 7, 2023
19 checks passed
@johntrimble
Copy link
Contributor Author

Thanks for reviewing and merging this. Also, thanks for writing and maintaining this library! I use it all the time and it saves me an incredible amount of time and frustration.

@amoffat
Copy link
Owner

amoffat commented Aug 7, 2023

That is great to hear John :)

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.

Nested contexts duplicate commands
2 participants