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

Make primer work on Windows again #99

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

AlexWaygood
Copy link
Contributor

I set out to figure out why the changes I made in #97 caused primer to hang in typeshed's CI, but quickly realised that I couldn't run primer locally at all any more! This is because shlex.quote() does the wrong thing on Windows when you pass it a path. All you actually need to do on Windows to quote a path is to do some basic validation and then surround it with "", so there's a pretty simple workaround.

Copy link
Owner

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Huh, TIL. Is the issue that shlex.quote prefers single quotes instead of double quotes?

@AlexWaygood
Copy link
Contributor Author

AlexWaygood commented Sep 11, 2023

Is the issue that shlex.quote prefers single quotes instead of double quotes?

I think that's the main issue, yeah, though I don't really know much more than what the warning in the docs tells me.

This solution is derived from Eryk Sun's comments on a Stack Overflow question that suggest that this should always do the right thing if all you need to do is to quote a Windows path, and it was the quoting of paths that was causing me grief locally.

An alternative solution would be to use subprocess.list2cmdline, which I think tries harder to capture all the semantics of the Windows command line. I didn't go for that because:

  1. Not sure we need it here
  2. It's undocumented
  3. There was some scepticism recently when people suggested documenting it that makes me nervous about using it: https://discuss.python.org/t/why-is-subprocess-list2cmdline-not-documented/25044/1

Copy link
Owner

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks for the links!

@hauntsaninja hauntsaninja merged commit d3a8fb2 into hauntsaninja:master Sep 13, 2023
1 check passed
@AlexWaygood AlexWaygood deleted the windows branch September 13, 2023 08:02
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.

2 participants