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: pass through unexpected format strings #884
Conversation
cibuildwheel/util.py
Outdated
|
||
|
||
class SafeDict(Dict[str, PathOrStr]): | ||
def __missing__(self, key: str) -> LimitedExpandStr: |
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.
def __missing__(self, key: str) -> LimitedExpandStr: | |
def __missing__(self, key: PathOrStr) -> LimitedExpandStr: |
Will commit this after review, just to possibly save a CI run.
cibuildwheel/util.py
Outdated
def __format__(self, fmt: str) -> str: | ||
return str(self.__class__(self.inner + (f":{fmt}" if fmt else ""))) | ||
|
||
def __getitem__(self: T, item: int) -> T: |
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.
def __getitem__(self: T, item: int) -> T: | |
def __getitem__(self: T, item: Any) -> T: |
cibuildwheel/util.py
Outdated
T = TypeVar("T", bound="LimitedExpandStr") | ||
|
||
|
||
class LimitedExpandStr: |
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 can't honestly say I understand what's happening in this class... I'd have expected that
def __missing__(self, key):
return "{" + key + "}"
would have done the job. what extra is this class doing? (might be nice to add this as a docstring, too)
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.
It's because valid Bash syntax will trip this up otherwise. This makes it slightly less brittle. Colons and especially brackets are valid in Bash, but would trip up our expansion if we didn't have this little class.
Ahhh. Been playing with this some more and just noticed another gotcha with prepare_command: >>> import cibuildwheel.util
>>> cibuildwheel.util.prepare_command('find . -exec echo {} \;')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/joerick/Projects/cibuildwheel/cibuildwheel/util.py", line 88, in prepare_command
return format_safe(command, python="python", pip="pip", **kwargs)
File "/Users/joerick/Projects/cibuildwheel/cibuildwheel/util.py", line 78, in format_safe
return template.format_map(FormatSafeDict(**kwargs))
ValueError: Format string contains positional fields This format_map solution can't passthrough |
But... I remember the logic... that isn't a problem because users can do |
Closes #840.