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 globbing files using current path pattern #403

Merged
merged 4 commits into from
May 6, 2024

Conversation

priitlatt
Copy link
Contributor

PathFinderMixin.find_paths generates erroneous iterator when called with path pattern "." as then essentially Path('.').glob('.') happens, which raises an IndexError. For example:

>>> list(Path('.').glob('.'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/priit/.pyenv/versions/3.12.0/lib/python3.12/pathlib.py", line 1094, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour, case_sensitive)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.12.0/lib/python3.12/pathlib.py", line 83, in _make_selector
    pat = pattern_parts[0]
          ~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

More specifically from the context of the tools, this can happen in case of invalid user input from CLI args:

Stacktrace

Traceback (most recent call last):
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/cli/cli_app.py", line 243, in invoke_cli
    CliApp._running_app._invoke_action(args)
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/cli/cli_app.py", line 184, in _invoke_action
    return cli_action(**action_args)
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/cli/action.py", line 83, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/tools/xcode_project.py", line 134, in use_profiles
    profiles = [ProvisioningProfile.from_path(p) for p in profile_paths]
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/tools/xcode_project.py", line 134, in <listcomp>
    profiles = [ProvisioningProfile.from_path(p) for p in profile_paths]
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/mixins/path_finder.py", line 21, in find_paths
    for path in self.glob(pattern.expanduser()):
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/pathlib.py", line 1139, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour)
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/pathlib.py", line 463, in _make_selector
    pat = pattern_parts[0]
IndexError: tuple index out of range

Handle this case by returning explicitly empty iterator instead.

@priitlatt priitlatt added the bug Something isn't working label May 6, 2024
@priitlatt priitlatt merged commit ba69f5a into master May 6, 2024
11 checks passed
@priitlatt priitlatt deleted the bugfix/pathfinder-glob-current-dir branch May 6, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant