-
-
Notifications
You must be signed in to change notification settings - Fork 632
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
Validate and maybe prune interpreter cache run over run #7225
Merged
CMLivingston
merged 5 commits into
pantsbuild:master
from
CMLivingston:clivingston/PY-135
Feb 11, 2019
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
|
@@ -78,6 +78,9 @@ def execute(self): | |
interpreter_path_file = self._interpreter_path_file(target_set_id) | ||
if not os.path.exists(interpreter_path_file): | ||
self._create_interpreter_path_file(interpreter_path_file, python_tgts) | ||
else: | ||
if self._detect_and_purge_invalid_interpreter(interpreter_path_file): | ||
self._create_interpreter_path_file(interpreter_path_file, python_tgts) | ||
|
||
interpreter = self._get_interpreter(interpreter_path_file) | ||
self.context.products.register_data(PythonInterpreter, interpreter) | ||
|
@@ -95,6 +98,17 @@ def _create_interpreter_path_file(self, interpreter_path_file, targets): | |
def _interpreter_path_file(self, target_set_id): | ||
return os.path.join(self.workdir, target_set_id, 'interpreter.info') | ||
|
||
def _detect_and_purge_invalid_interpreter(self, interpreter_path_file): | ||
with open(interpreter_path_file, 'r') as infile: | ||
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. Instead of re-creating the file reading logic, how about something like: interpreter = self._get_interpreter(interpreter_path_file)
if not os.path.exists(os.readlink(interpreter.binary)):
... |
||
lines = infile.readlines() | ||
binary = lines[0].strip() | ||
if not os.path.exists(binary): | ||
self.context.log.info('Stale interpreter reference detected: {}, removing reference and ' | ||
'selecting a new interpreter.'.format(binary)) | ||
os.remove(interpreter_path_file) | ||
return True | ||
return False | ||
|
||
@staticmethod | ||
def _get_interpreter(interpreter_path_file): | ||
with open(interpreter_path_file, 'r') as infile: | ||
|
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.
This is always
True
in production use from my reading of call-sites in this file. How about re-structuring this private function to allow killing this misleading conditional. Maybe re-name to_interpreter_from_relpath
and do thepath = os.path.joint(self._cache_dir, relpath)
here allowing unambiguous removal of the conditional.