-
Notifications
You must be signed in to change notification settings - Fork 260
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
chore: Try to download Z3 5 times instead of just once #1835
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c54b95e
Try to download 5 times
MikaelMayer adec859
Removed semicolons
MikaelMayer 4709a87
raise instead of throw
MikaelMayer c343f40
Review comments
MikaelMayer a5f54b3
No parentheses
MikaelMayer e2613ac
Forgot the break... downloading Z3 too many times!
MikaelMayer 5c24b5a
Merge branch 'master' into chore-robustness-in-installation
MikaelMayer 3defd21
Update Release_notes for other PR
MikaelMayer 8416b62
Update RELEASE_NOTES.md
MikaelMayer 1bf3513
Merge branch 'master' into chore-robustness-in-installation
fabiomadge 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
Z3_RELEASES_URL = "https://api.github.com/repos/Z3Prover/z3/releases/tags/Z3-4.8.5" | ||
## How do we extract info from the name of a Z3 release file? | ||
Z3_RELEASE_REGEXP = re.compile(r"^(?P<directory>z3-[0-9a-z\.]+-(?P<platform>x86|x64)-(?P<os>[a-z0-9\.\-]+)).zip$", re.IGNORECASE) | ||
## How many times we allow ourselves to try to download Z3 | ||
Z3_MAX_DOWNLOAD_ATTEMPTS = 5 | ||
|
||
## Allowed Dafny release names | ||
DAFNY_RELEASE_REGEX = re.compile("\\d+\\.\\d+\\.\\d+(-[\w\d_-]+)?$") | ||
|
@@ -106,10 +108,16 @@ def download(self): | |
print("cached!") | ||
else: | ||
flush("downloading {:.2f}MB...".format(self.MB), end=' ') | ||
with request.urlopen(self.url) as reader: | ||
with open(self.z3_zip, mode="wb") as writer: | ||
writer.write(reader.read()) | ||
flush("done!") | ||
for currentAttempt in range(Z3_MAX_DOWNLOAD_ATTEMPTS): | ||
try: | ||
with request.urlopen(self.url) as reader: | ||
with open(self.z3_zip, mode="wb") as writer: | ||
writer.write(reader.read()) | ||
flush("done!") | ||
except (http.client.IncompleteRead) as e: | ||
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. No need for parentheses here |
||
if currentAttempt == Z3_MAX_DOWNLOAD_ATTEMPTS - 1: | ||
raise | ||
fabiomadge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. FWIW, an alternative way to write this kind of loop in Python is something like this ( err = None
for _ in range(NRETRIES):
try:
do_something()
break
except SomeException as e:
err = e
else:
raise err |
||
|
||
@staticmethod | ||
def zipify_path(fpath): | ||
|
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.
urllib.request.urlretrieve
instead ofwrite(read())
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.
The documentation says your particular method has been deprecated.
Moreover, I don't feel comfortable editing what already worked before - for example, it might work today, but if the cache is outdated tomorrow and it does not work, we might not see the error
If you feel comfortable, feel free to contribute to this PR.
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.
Not quite :) But I agree with you that it's fine to keep the current code if it's working (I wrote it, but I'm not sure why I didn't use
shutil.copyfileobj
orurlretrieve
^^)