-
Notifications
You must be signed in to change notification settings - Fork 586
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 loading of charmap from cache file #2166
Fix loading of charmap from cache file #2166
Conversation
Loading the cached charmap from disk always failed because the `GzipFile` was passed to `json.loads`, which expects a string. Use `json.load` instead, which accepts a file. This fixes an issue where the first test in a test run that used the charmap would be unexpectedly slow.
|
Wow, that's a pretty serious bug! Thanks heaps for spotting it, and the PR! (with tests 😍) You'll need to add a release file (with thank-you note) and I'd encourage you to add yourself to the list of authors too. See #2162 for a good example of what this looks like. |
Done. Thanks for the help :) |
eb9e7a2
to
6f5412b
Compare
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.
Thanks again Robert 🎉
- Verify that the `os.utime` call to set the mtime succeeded - Only check the mtime of the file, since that is all we care about and the platform may or may not update the atime. - Only require second-level accuracy of mtime. Not all file systems/OSes support the same level of accuracy as `time.time()` returns.
|
I'm looking into the test failure on Travis. I have a related question though about whether we could potentially just bundle a precompiled version of the charmap in the Hypothesis package, along with a script to regenerate it? The only time it changes AFAIK is when new Unicode versions are released. On CI systems, each new branch (or sometimes every build) typically starts out with a fresh build directory, so the first test that triggers a call to |
|
We have considered shipping this as a static data file, but the way that e.g. unicode version can vary by platform makes it fairly tricky to be sure that everything stays in sync (not that the status quo is perfect, either...). Given that we want to address the 'long delay on first run' for other reasons too, we're likely to go with a more general solution. |
|
Hmm, the linux-py35 tests are failing. I'll look into that.
OK. I had a look at optimizing the existing cache generation and was able to find wins of ~2x by reducing the number of hash lookups: https://gist.github.com/robertknight/055d19c61c5dbe2c1169a54e1da7f238. |
Reading from the `GzipFile` returns bytes, but `json.load` only supports string input in Python <= 3.5.
462caef
to
a568035
Compare
Co-Authored-By: robertknight <robertknight@gmail.com>
a568035
to
bd71f6b
Compare
Loading the cached charmap from disk always failed because the
GzipFilewas passed tojson.loads, which expects a string. Usejson.loadinstead, which accepts a file.This fixes an issue where the first test in a test run that used the
charmap would be unexpectedly slow.
For context, see #2108 (comment).