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

Add test for new dependencies #3278

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NCRegressionTests = "1789bc09-29e6-4c93-9c75-fe2179693664"
NVTX = "5da4648a-3479-48b8-97b9-01cb529c0a1f"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
Expand Down
87 changes: 87 additions & 0 deletions test/dependencies.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Pkg
import Test

# Adding new dependencies to a Julia project has downsides. First, every
# dependency increases the precompilation and import time of a package. For
# complex packages, such as CUDA, this translates in several minutes of
# precompilation time that every single user of ClimaAtmos (including our CI
# runners) always pays. Second, dependencies can increase the cost of
# maintaining ClimaAtmos and the surface area of things that can go wrong (a
# buggy update in a dependency can break ClimaAtmos). Third, dependencies
# increase the complexity of the project's environment, potentially causing
# compatibility issues and restricting the versions we can use.

# This test follows the spirit of the regression tests and tries to capture the
# cost of adding a new dependency by having developers explicitly come here and
# declare their intents.
#
# DO NOT ADD new dependencies if:

# - the feature you need can be easily implemented (e.g., do you need the might
# of Distributions.jl to compute a guassian function?)
# - your dependency is heavy/has lots of dependencies (e.g., DataFrames, CUDA).
# Instead, ask around, someone will help you accomplish what you need
# - your dependency implements code that logically should be implemented elsewhere
# (e.g., if your importing CUDA, maybe we should extend ClimaComms instead).
# Instead, ask around, someone will help you accomplish what you need

atmos_uuid = Pkg.project().dependencies["ClimaAtmos"]
direct_dependencies =
keys(Pkg.dependencies(identity, atmos_uuid).dependencies) |> Set

known_dependencies = Set([
# Adapt is used to generate the spline for Earth topography
"Adapt",
# ArgParse is used to read --config_file and --job_id from command line
"ArgParse",
# ArtifactWrappers is used to topography and gravity wave NetCDF data
"ArtifactWrappers",
"Artifacts",
"AtmosphericProfilesLibrary",
"ClimaComms",
"ClimaCore",
"ClimaDiagnostics",
"ClimaParams",
"ClimaTimeSteppers",
"ClimaUtilities",
"CloudMicrophysics",
"Dates",
"DiffEqBase",
"FastGaussQuadrature",
"Insolation",
"Interpolations",
"LazyArtifacts",
"LinearAlgebra",
"Logging",
# NCDatasets is used to read Earth topography, GCM driven initial conditions, orographic gravity wave data
"NCDatasets",
"NVTX",
"RRTMGP",
"SciMLBase",
"StaticArrays",
# Statistics is used to call 'mean' on ClimaCore Fields
"Statistics",
"SurfaceFluxes",
"Thermodynamics",
# UnrolledUtilities is used to make some loops and maps in the gravity-wave code type-stable
"UnrolledUtilities",
"YAML",
])

diff = setdiff(direct_dependencies, known_dependencies)

if !isempty(diff)
println("Detected new dependencies: $diff")
println("Please, double check if you really need the new dependencies")
println(
"If you do, edit the dependencies.jl file adding a note about where the packages are used",
)
end

otherdiff = setdiff(known_dependencies, direct_dependencies)
if !isempty(otherdiff)
println("Detected stale dependencies: $otherdiff")
println("Please, edit the dependencies.jl file")
end

Test.@test direct_dependencies == known_dependencies
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Test

#! format: off
@safetestset "Aqua" begin @time include("aqua.jl") end
@safetestset "Dependencies" begin @time include("dependencies.jl") end
@safetestset "Callbacks" begin @time include("callbacks.jl") end
@safetestset "Utilities" begin @time include("utilities.jl") end
@safetestset "Parameter tests" begin @time include("parameters/parameter_tests.jl") end
Expand Down
Loading