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

Extract the logic of finding interpreters to a method #326

Merged
merged 6 commits into from Mar 22, 2021

Conversation

frostming
Copy link
Collaborator

@frostming frostming commented Mar 22, 2021

Pull Request Check List

  • A news fragment is added in news/ describing what is new.
  • Test cases added for changed code.

Describe what you have changed in this PR.

As title

@@ -515,3 +516,25 @@ def make_candidate_info_cache(self) -> CandidateInfoCache:

def make_hash_cache(self) -> HashCache:
return HashCache(directory=self.cache("hashes").as_posix())

def find_interpreters(self, python_spec: str) -> Iterable[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

why return a str here instead of a Path?

pdm/utils.py Outdated Show resolved Hide resolved
pdm/utils.py Outdated Show resolved Hide resolved
pdm/project/core.py Outdated Show resolved Hide resolved
@@ -417,7 +417,7 @@ def do_use(project: Project, python: str, first: bool = False) -> None:
The python can be a version string or interpreter path.
"""
python = python.strip()
found_interpreters = list(project.find_interpreters(python))
found_interpreters = list(dict.fromkeys(project.find_interpreters(python)))
Copy link
Contributor

Choose a reason for hiding this comment

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

found_interpreters = set(project.find_interpreters(python))?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, the difference is dict.fromkeys() preserves the order while set doesn't.

@frostming frostming merged commit e98f9df into master Mar 22, 2021
@frostming frostming deleted the refactor/find_interpreters branch March 22, 2021 10:40
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.

None yet

2 participants