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 run with nested quotes #17487

Merged
merged 9 commits into from
Dec 18, 2024
Merged

fix run with nested quotes #17487

merged 9 commits into from
Dec 18, 2024

Conversation

Todiq
Copy link
Contributor

@Todiq Todiq commented Dec 17, 2024

Changelog: Bugfix: Fix running commands in powershell with single quotes.
Docs: Omit

Closes #17486

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

@CLAassistant
Copy link

CLAassistant commented Dec 17, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Hi @Todiq

Thanks very much for your contribution.
It would be great (mostly necessary to guarantee that this keeps working fine in the future) to add some unittest. You might be able to copy&paste some existing test from test_virtualenv_powershell.py and use it as inspiration and start point?

If you can't don't worry, we can help and add the test. But it would be great to have some code or instructions to reproduce the original issue fixed by this. Thanks!

@Todiq
Copy link
Contributor Author

Todiq commented Dec 18, 2024

I'll try first to fix the tests that I have broken, then I'll add some, sure 👌

@@ -59,6 +59,7 @@ def environment_wrap_command(conanfile, env_filenames, env_folder, cmd, subsyste
launchers = " && ".join('"{}"'.format(b) for b in bats)
if ps1s:
ps1_launchers = f'{powershell} -Command "' + " ; ".join('&\'{}\''.format(f) for f in ps1s)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @czoido

I am pretty sure the .join('&\'{}\''.format(f) for f in ps1s) could be changed as well to .join('{}'.format(f) for f in ps1s)
The minimal local tests I have run seem to go well with this change and it does improve readability in my opinion
I think the & syntax is not necessary with the -Command anymore. Am I mistaken?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @Todiq,
Removing the & when invoking the scripts causes that the environment variables that should be injected from the ps1 files will not be applied correctly in the execution contexts, so I'm afraid those are necessary.
Is it possible to give us an small reproducible example to be able to add a test to check what this PR is fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added some tests.
Reproducible case is here : conan-io/conan-center-index#26187

Copy link
Contributor

@czoido czoido Dec 18, 2024

Choose a reason for hiding this comment

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

Thank you so much @Todiq , I could reproduce the issue, let me check what you added and simplify a bit.

@czoido
Copy link
Contributor

czoido commented Dec 18, 2024

Hi @Todiq, I have pushed some changes to your branch, please can you check if those changes solve your issue and the test there represents the original issue?

@czoido czoido added this to the 2.11.0 milestone Dec 18, 2024
@czoido czoido requested a review from memsharded December 18, 2024 16:30
name = "pkg"
version = "0.1"
def build(self):
self.run('python -c "print(\\'Hello World\\')"', scope="build")
Copy link
Contributor

Choose a reason for hiding this comment

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

this tries to replicate what happens when doing:

conan install --requires=boost/1.85.0 --build=boost/* -c:a tools.env.virtualenv:powershell=pwsh -o "boost/*:without_python=False"

Copy link
Contributor

@franramirez688 franramirez688 left a comment

Choose a reason for hiding this comment

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

@Todiq @czoido thanks for contributing this!
LGTM!

@czoido czoido merged commit bd20ea2 into conan-io:develop2 Dec 18, 2024
33 checks passed
@Todiq Todiq deleted the fix-nested-quotes branch December 18, 2024 20:29
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.

[bug] self.run does not work on Windows commands containing single quotes
6 participants