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

Use Scratch for cached timezone data. #347

Closed
wants to merge 9 commits into from

Conversation

MichaelHatherly
Copy link

Fixes #338, based on #343 (comment) by KristofferC.

At module init runs the current build to generate
the cached data, and stores it in a scratchspace instead of the
deps folder. Associated globals that were defined at top-level are
now set in __init__ (and _init for submodules) to allow for
PackageCompiler support. Scratchspace is linked to the Julia and
package version so should rebuild when those change for users.

The deps/build.jl now just imports the package which triggers
a build of the cache if needed so this shouldn't really impact
using TimeZones much as far as I could tell.

A required PR for Scratch to expand it's version support is at
JuliaPackaging/Scratch.jl#24. I've enabled
support going back to 1.0 for that package to match what TimeZones
says it supports, but it turns out EzXML is bounded at 1.3 so
I couldn't test down to 1.0-1.2.

Fixes JuliaTime#338. At module init runs the current `build` to generate
the cached data, and stores it in a scratchspace instead of the
deps folder. Associated globals that were defined at top-level are
now set in `__init__` (and `_init` for submodules) to allow for
`PackageCompiler` support. Scratchspace is linked to the Julia and
package version so should rebuild when those change for users.

The `deps/build.jl` now just imports the package which triggers
a build of the cache if needed so this shouldn't really impact
`using TimeZones` much as far as I could tell.

A required PR for `Scratch` to expand it's version support is at
JuliaPackaging/Scratch.jl#24. I've enabled
support going back to 1.0 for that package to match what `TimeZones`
says it supports, but it turns out `EzXML` is bounded at `1.3` so
I couldn't test down to 1.0-1.2.
Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

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

Thanks for this!

src/TimeZones.jl Outdated Show resolved Hide resolved
src/TimeZones.jl Outdated
Comment on lines 55 to 63
if isempty(readdir(DEPS_DIR))
cd(DEPS_DIR) do
for (path, contents) in DEPS_CONTENTS
mkpath(dirname(path))
write(path, contents)
end
end
build()
end
Copy link
Member

Choose a reason for hiding this comment

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

I suspect it would be cleaner to just have the build process write the scratch directory?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I'll move it into build() instead.

src/TimeZones.jl Outdated Show resolved Hide resolved
src/TimeZones.jl Outdated
function __init__()
global DEPS_DIR = @get_scratch!("timezones-$VERSION-$pkg_version")
Copy link
Member

Choose a reason for hiding this comment

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

May be able to use the tzdata version

Copy link
Author

Choose a reason for hiding this comment

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

Can do, is the cache folder structure likely to remain the same between package versions? If not then using just tzdata_version as the scratch key may cause issues, perhaps.

Copy link
Member

Choose a reason for hiding this comment

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

It's probably safest to include Julia version, package version, and tzdata version. It also just occurred to me that users are allowed to re-compile the time zones to support dates in the far future. I'll need to think more about this.

@omus
Copy link
Member

omus commented Jun 9, 2021

This change will require us to drop support for Julia versions below 1.5. That's not a deal breaker but annoying as I want to continue to support the 1.0 LTS while it's the official LTS. The changes for dropping 1.0 support can be done in another PR. We'll need to at least disable the 1.0 CI jobs though so we can validate the changes. Ref: #340

@MichaelHatherly
Copy link
Author

I'd like to retain LTS support as well, hence JuliaPackaging/Scratch.jl#24 should be completed before finishing off this one, so that we can just use a version of Scratch that supports Julia 1+.

@MichaelHatherly
Copy link
Author

@omus the CI failure is a bit of a mystery to me.. I've adjusted some paths and checks so maybe it'll get by this time.

@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2021

Codecov Report

Merging #347 (fb1824b) into master (71178fe) will decrease coverage by 0.41%.
The diff coverage is 82.60%.

❗ Current head fb1824b differs from pull request most recent head b2c8022. Consider uploading reports for the commit b2c8022 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
- Coverage   93.60%   93.18%   -0.42%     
==========================================
  Files          32       33       +1     
  Lines        1532     1555      +23     
==========================================
+ Hits         1434     1449      +15     
- Misses         98      106       +8     
Impacted Files Coverage Δ
src/tzdata/build.jl 66.66% <0.00%> (+3.03%) ⬆️
src/tzdata/download.jl 96.22% <ø> (+0.22%) ⬆️
src/tzdata/version.jl 91.42% <ø> (ø)
src/TimeZones.jl 84.61% <71.42%> (-15.39%) ⬇️
src/tzdata/TZData.jl 87.50% <87.50%> (ø)
src/winzone/WindowsTimeZoneIDs.jl 83.87% <100.00%> (+4.70%) ⬆️
src/tzdata/compile.jl 93.07% <0.00%> (-2.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 71178fe...b2c8022. Read the comment docs.

Comment on lines 18 to 22
global ARCHIVE_DIR = joinpath(TimeZones.DEPS_DIR, "tzarchive")
global TZ_SOURCE_DIR = joinpath(TimeZones.DEPS_DIR, "tzsource")
global COMPILED_DIR = joinpath(TimeZones.DEPS_DIR, "compiled", string(VERSION))
global ACTIVE_VERSION_FILE = joinpath(TimeZones.DEPS_DIR, "active_version")
global LATEST_FILE = joinpath(TimeZones.DEPS_DIR, "latest")
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer if these were all global constants and we used Ref{String}()

Copy link
Author

Choose a reason for hiding this comment

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

Are any of these constants regarded as public? It'll of course be a breaking change if that's the case unfortunately.

if tzdata_hash === nothing
error("Latest tzdata is $latest_version which is not present in the Artifacts.toml")
end
@artifact_str "tzdata$latest_version"
Copy link
Member

Choose a reason for hiding this comment

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

Did this need to be changed?

Copy link
Author

Choose a reason for hiding this comment

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

It should have the same effect of throwing an error when the particular artifact does not exist, but by using @artifact_str the Artifact.toml contents gets embedded rather than looked up at runtime in the file, which may not exist if it's been relocated.

deps/build.jl Outdated
using TimeZones: build

build()
using TimeZones
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, if someone manually runs ] build we should probably re-build the scratch directory.

Not too sure why the cache isn't being found when running the
benchmarks, but manually rebuilding seems to help locally. It's not
particularly ideal, and is probably being caused by some other
underlying issue with this change.
@andreasnoack
Copy link

Are there any unaddressed comments here or is this good to go?

@MichaelHatherly
Copy link
Author

Are there any unaddressed comments here or is this good to go?

The failure in benchmarks is the current blocker here, still trying to pin it down.

@MichaelHatherly
Copy link
Author

Closing in favour of #348.

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.

Avoid defining paths at compile time
4 participants