Skip to content

Commit

Permalink
Raise the minimum Julia version to 1.3 (#361)
Browse files Browse the repository at this point in the history
Co-authored-by: Curtis Vogt <[email protected]>
  • Loading branch information
oxinabox and omus authored Oct 12, 2021
1 parent 22a32d4 commit 482f3b7
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: true
matrix:
version:
- "1.0" # LTS
- "1.3" # oldest supported version
- "1" # Latest release
- nightly
os:
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
fail-fast: true
matrix:
version:
- "1.0"
- "1.3"
- nightly
os:
- ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "TimeZones"
uuid = "f269a46b-ccf7-5d73-abea-4c690281aa53"
authors = ["Curtis Vogt <[email protected]>"]
version = "1.5.9"
version = "1.6.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Future = "9fa8497b-333b-5362-9e8d-4d0656e87820"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Mocking = "78c3b35d-d492-501b-9361-3d52fe80e533"
Expand All @@ -15,9 +16,10 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
Downloads = "1"
Mocking = "0.7"
RecipesBase = "0.7, 0.8, 1"
julia = "1"
julia = "1.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
8 changes: 0 additions & 8 deletions src/types/timezone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,3 @@ function istimezone(str::AbstractString, mask::Class=Class(:DEFAULT))

return tz !== nothing && mask & class != Class(:NONE)
end

# After `broadcastable` was defined but before this was addressed in the `Dates` stdlib
# - Broadcastable introduction: https://github.com/JuliaLang/julia/pull/26601
# - Fixed in Dates: https://github.com/JuliaLang/julia/pull/30159
# Note: The change was backported to 1.1 as well.
if v"0.7.0-DEV.4743" <= VERSION < v"1.1.0-DEV.722" || v"1.2-" <= VERSION < v"1.2.0-DEV.114"
Base.broadcastable(tz::TimeZone) = Ref(tz)
end
6 changes: 2 additions & 4 deletions src/tzdata/TZData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ module TZData

using Printf
using ...TimeZones: DEPS_DIR
using ...TimeZones: @artifact_str

import Pkg
using Pkg.Artifacts: artifact_hash

if VERSION >= v"1.3"
using ...TimeZones: @artifact_str
using Pkg.Artifacts: artifact_hash
end

# Note: The tz database is made up of two parts: code and data. TimeZones.jl only requires
# the "tzdata" archive or more specifically the "tz source" files within the archive
Expand Down
81 changes: 21 additions & 60 deletions src/tzdata/build.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using ...TimeZones: Class
if VERSION >= v"1.3"
# Artifacts introduced in Pkg v1.3
# Using Pkg instead of using LazyArtifacts is deprecated on 1.6.0-beta1.15 and 1.7.0-DEV.302
# LazyArtifacts.jl available for v1.3 and up
using LazyArtifacts
end
using LazyArtifacts

# The default tz source files we care about. See "ftp://ftp.iana.org/tz/data/Makefile"
# "PRIMARY_YDATA" for listing of tz source files to include.
Expand Down Expand Up @@ -34,70 +29,36 @@ function build(
compiled_dir::AbstractString="";
verbose::Bool=false,
)
@static if VERSION >= v"1.3"
# Determine the current "latest" version but limit how often we check with remote
# servers.
if version == "latest"
latest_version = latest_cached()

# Retrieve the current latest version the cached latest has expired
if latest_version === nothing
latest_version = last(tzdata_versions())
tzdata_hash = artifact_hash("tzdata$latest_version", ARTIFACT_TOML)

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

set_latest_cached(latest_version)
end

version = latest_version
end
# Determine the current "latest" version but limit how often we check with remote
# servers.
if version == "latest"
latest_version = latest_cached()

artifact_dir = @artifact_str "tzdata$version"
# Retrieve the current latest version the cached latest has expired
if latest_version === nothing
latest_version = last(tzdata_versions())
tzdata_hash = artifact_hash("tzdata$latest_version", ARTIFACT_TOML)

if !isempty(tz_source_dir)
@info "Installing $version tzdata region data"
regions = union!(intersect(regions, readdir(artifact_dir)), CUSTOM_REGIONS)
for region in setdiff(regions, CUSTOM_REGIONS)
cp(joinpath(artifact_dir, region), joinpath(tz_source_dir, region), force=true)
if tzdata_hash === nothing
error("Latest tzdata is $latest_version which is not present in the Artifacts.toml")
end
end
else
# Avoids spamming remote servers requesting the latest version
if version == "latest"
v = latest_cached()

if v !== nothing
version = v
@info "Latest tzdata is $version"
end
end

archive = joinpath(archive_dir, "tzdata$version.tar.gz")
set_latest_cached(latest_version)
end

# Avoid downloading a tzdata archive if we already have a local copy
if version == "latest" || !isfile(archive)
@info "Downloading $version tzdata"
archive = tzdata_download(version, archive_dir)
version = latest_version
end

if version == "latest"
m = match(TZDATA_VERSION_REGEX, basename(archive))
if m !== nothing
version = m.match
@info "Latest tzdata is $version"
end
end
end
artifact_dir = @artifact_str "tzdata$version"

if !isempty(tz_source_dir)
@info "Extracting $version tzdata archive"
regions = union!(intersect(regions, readarchive(archive)), CUSTOM_REGIONS)
extract(archive, tz_source_dir, setdiff(regions, CUSTOM_REGIONS), verbose=verbose)
if !isempty(tz_source_dir)
@info "Installing $version tzdata region data"
regions = union!(intersect(regions, readdir(artifact_dir)), CUSTOM_REGIONS)
for region in setdiff(regions, CUSTOM_REGIONS)
cp(joinpath(artifact_dir, region), joinpath(tz_source_dir, region), force=true)
end
end

if !isempty(compiled_dir)
@info "Converting tz source files into TimeZone data"
tz_source = TZSource(joinpath.(tz_source_dir, regions))
Expand Down
8 changes: 1 addition & 7 deletions src/tzdata/download.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using Dates
using Downloads: download
using TimeZones: DEPS_DIR

if VERSION >= v"1.6.0-DEV.923"
# Use Downloads.jl once TimeZones.jl drops support for Julia versions < 1.3
download(args...) = Base.invokelatest(Base.Downloads().download, args...)
else
using Base: download
end

const LATEST_FILE = joinpath(DEPS_DIR, "latest")
const LATEST_FORMAT = Dates.DateFormat("yyyy-mm-ddTHH:MM:SS")
const LATEST_DELAY = Hour(1) # In 1996 a correction to a release was made an hour later
Expand Down
15 changes: 3 additions & 12 deletions src/winzone/WindowsTimeZoneIDs.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
module WindowsTimeZoneIDs

using ...TimeZones: DEPS_DIR
using LazyArtifacts
using ...TimeZones: DEPS_DIR, @artifact_str
using Future: copy!

if VERSION >= v"1.3"
using LazyArtifacts
using ...TimeZones: @artifact_str
end

const UNICODE_CLDR_VERSION = "release-39"

# A mapping of Windows timezone names to Olson timezone names.
Expand Down Expand Up @@ -53,12 +49,7 @@ end
function build(xml_file::AbstractString=WINDOWS_XML_FILE; force::Bool=false)
if !isfile(xml_file) || force
@info "Downloading Windows to POSIX timezone ID XML version: $UNICODE_CLDR_VERSION"
@static if VERSION >= v"1.3"
artifact_dir = @artifact_str "unicode-cldr-$UNICODE_CLDR_VERSION"
cp(joinpath(artifact_dir, WINDOWS_ZONE_FILE), xml_file, force=true)
else
download(WINDOWS_ZONE_URL, xml_file)
end
download(WINDOWS_ZONE_URL, xml_file)
end

@info "Compiling Windows time zone name translation"
Expand Down
7 changes: 1 addition & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const TZ_SOURCE_DIR = get(ENV, "TZ_SOURCE_DIR", joinpath(PKG_DIR, "test", "tzsou
const TZFILE_DIR = joinpath(PKG_DIR, "test", "tzfile")
const TEST_REGIONS = ["asia", "australasia", "europe", "northamerica"]

# https://github.com/JuliaLang/julia/pull/27900
if VERSION < v"1.2.0-DEV.642"
const ProcessFailedException = ErrorException
end

isdir(ARCHIVE_DIR) || mkdir(ARCHIVE_DIR)
isdir(TZ_SOURCE_DIR) || mkdir(TZ_SOURCE_DIR)

Expand Down Expand Up @@ -72,7 +67,7 @@ include("helpers.jl")
include("rounding.jl")
include("parse.jl")
include("plotting.jl")
VERSION >= v"1.3" && include("thread-safety.jl")
include("thread-safety.jl")

# Note: Run the build tests last to ensure that re-compiling the time zones files
# doesn't interfere with other tests.
Expand Down
4 changes: 3 additions & 1 deletion test/thread-safety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ end

@info "Running Thread Safety tests"
@testset "Multithreaded TimeZone construction" begin
run(`$(Base.julia_cmd()) -t8 --proj -E $(program)`)
withenv("JULIA_NUM_THREADS" => "8") do
run(`$(Base.julia_cmd()) --proj -E $(program)`)
end
end
13 changes: 2 additions & 11 deletions test/tzdata/archive.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
using TimeZones.TZData: ARCHIVE_DIR, isarchive, readarchive, extract, tzdata_download

const ARCHIVE_PATH = let
if VERSION < v"1.3"
archives = filter(file -> endswith(file, "tar.gz"), readdir(ARCHIVE_DIR))
isempty(archives) && error("Unable to run archive tests without first running Pkg.build(\"TimeZones\")")
joinpath(ARCHIVE_DIR, first(archives))
else
# For Julia versions that use artifacts we'll need to retrieve an archive only for
# testing purposes.
tzdata_download(TZDATA_VERSION, ARCHIVE_DIR)
end
end
# Retrieve an archive only for testing purposes.
const ARCHIVE_PATH = tzdata_download(TZDATA_VERSION, ARCHIVE_DIR)

@test isarchive(ARCHIVE_PATH)
@test !isarchive(@__FILE__)
Expand Down
32 changes: 3 additions & 29 deletions test/tzdata/version.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using TimeZones: @artifact_str
using TimeZones.TZData: ARCHIVE_DIR, TZDATA_VERSION_REGEX, TZDATA_NEWS_REGEX
using TimeZones.TZData: read_news, extract, tzdata_version_dir, tzdata_version_archive
using TimeZones.TZData: active_version, active_archive

use_artifacts = VERSION >= v"1.3"

if use_artifacts
using TimeZones: @artifact_str
end

for year = ("12", "1234"), letter = ("", "z")
version = year * letter
Expand Down Expand Up @@ -34,20 +30,10 @@ end
@test match(TZDATA_NEWS_REGEX, "Release 199") === nothing
@test match(TZDATA_NEWS_REGEX, "Release 19999") === nothing


@static if use_artifacts
artifact_dir = @artifact_str "tzdata$TZDATA_VERSION"
else
archive = joinpath(ARCHIVE_DIR, "tzdata$TZDATA_VERSION.tar.gz")
end

artifact_dir = @artifact_str "tzdata$TZDATA_VERSION"
mktempdir() do temp_dir
# Read the first tzdata version
if use_artifacts
cp(joinpath(artifact_dir, "NEWS"), joinpath(temp_dir, "NEWS"))
else
extract(archive, temp_dir, "NEWS")
end
cp(joinpath(artifact_dir, "NEWS"), joinpath(temp_dir, "NEWS"))

versions = read_news(joinpath(temp_dir, "NEWS"), 1)
@test versions == [TZDATA_VERSION]
Expand All @@ -66,19 +52,7 @@ mktempdir() do temp_dir
@test_throws ErrorException tzdata_version_dir(dirname(@__FILE__))
end

if !use_artifacts
@test tzdata_version_archive(archive) == TZDATA_VERSION
@test_throws ProcessFailedException tzdata_version_archive(@__FILE__) == TZDATA_VERSION
end

# Active/built tzdata version
version = active_version()
@test version != "latest" # Could happen if the logic to resolve the version fails
@test match(TZDATA_VERSION_REGEX, version) !== nothing

if !use_artifacts
archive = active_archive()
@test isfile(archive)
@test dirname(archive) == ARCHIVE_DIR
@test basename(archive) == "tzdata$version.tar.gz"
end
1 change: 0 additions & 1 deletion test/utcoffset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ end
# - https://github.com/JuliaLang/julia/issues/30901
# - https://github.com/JuliaLang/julia/pull/33178
if (
v"1.2.0-DEV.223" <= VERSION < v"1.2.0-pre.39" ||
v"1.3-DEV" <= VERSION < v"1.3.0-rc1.33" ||
v"1.4-DEV" <= VERSION < v"1.4.0-DEV.620" ||
v"1.5.0-DEV.163" <= VERSION
Expand Down

0 comments on commit 482f3b7

Please sign in to comment.