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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b59055
Extract the logic of finding interpreters to a method
frostming ecce6ee
add news entry
frostming 31c370b
use pythonfinder to find when short name is given
frostming 6b01cc7
Deduplicate the found interpreters
frostming 2955a8d
make find_python_in_path return path
frostming 1261139
fix the test failure
frostming File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor: Extract the logic of finding interpreters to method for the sake of subclass overriding. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
cached_property, | ||
cd, | ||
find_project_root, | ||
find_python_in_path, | ||
get_venv_python, | ||
is_venv_python, | ||
setdefault, | ||
|
@@ -515,3 +516,27 @@ 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]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why return a |
||
"""Return an iterable of interpreter paths that matches the given specifier, | ||
which can be: | ||
1. a version specifier like 3.7 | ||
2. an absolute path | ||
3. a short name like python3 | ||
""" | ||
import pythonfinder | ||
|
||
if python_spec and not all(c.isdigit() for c in python_spec.split(".")): | ||
if Path(python_spec).exists(): | ||
python_path = find_python_in_path(python_spec) | ||
if python_path: | ||
yield os.path.abspath(python_path) | ||
else: | ||
python_path = shutil.which(python_spec) | ||
if python_path: | ||
yield python_path | ||
return | ||
args = [int(v) for v in python_spec.split(".") if v != ""] | ||
finder = pythonfinder.Finder() | ||
for entry in finder.find_all_python_versions(*args): | ||
yield entry.path.as_posix() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
found_interpreters = set(project.find_interpreters(python))
?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.
Nope, the difference is
dict.fromkeys()
preserves the order whileset
doesn't.