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

Fix the naming issue when imported from a submodule #167

Merged
merged 4 commits into from
Apr 16, 2023
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
2 changes: 1 addition & 1 deletion SimpleSDMDatasets/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SimpleSDMDatasets"
uuid = "2c7d61d0-5c73-410d-85b2-d2e7fbbdcefa"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.1.0"
version = "0.1.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
5 changes: 2 additions & 3 deletions SimpleSDMDatasets/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# SimpleSDMDatasets

This *will* serve as a replacement for the data system in *SimpleSDMLayers.jl*.
This package serves as the data provisioning system for `SpeciesDistributionToolkit`.

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/PoisotLab/SimpleSDMDatasets.jl/Test%20suite?style=flat-square) ![Codecov](https://img.shields.io/codecov/c/github/PoisotLab/SimpleSDMDatasets.jl?style=flat-square)

![GitHub top language](https://img.shields.io/github/languages/top/PoisotLab/SimpleSDMDatasets.jl?style=flat-square&logo=julia)

This package has a smaller mission statement, namely:
This package has a very small mission statement, namely:

1. provide a simple interface to get access to raster data
2. implement this interface for commonly used data
3. ensure that the raster data are downloaded as needed and stored in a central location
4. provide enough checks that users can build on top of it rapidly (for example,
the wrapper for bioclim in CHELSA2.1 is only about 15 loc)

For now this is a *work in progress*
19 changes: 19 additions & 0 deletions SimpleSDMDatasets/src/downloader.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
function _drop_package_name_from_path(path)
# Module name with a dot
_target = "$(@__MODULE__)."
path = replace(path, _target => "")
path = replace(path, lowercase(_target) => "")
path = replace(path, uppercase(_target) => "")
return path
end

function downloader(
data::RasterData{P, D};
kwargs...,
Expand All @@ -6,6 +15,11 @@ function downloader(

url, fnm, dir = SimpleSDMDatasets.source(data; kwargs...)

# Remove the package name from the path strings if present
url = _drop_package_name_from_path(url)
fnm = _drop_package_name_from_path(fnm)
dir = _drop_package_name_from_path(dir)

# Check for path existence
isdir(dir) || mkpath(dir)

Expand Down Expand Up @@ -45,6 +59,11 @@ function downloader(

url, fnm, dir = SimpleSDMDatasets.source(data, future; kwargs...)

# Remove the package name from the path strings if present
url = _drop_package_name_from_path(url)
fnm = _drop_package_name_from_path(fnm)
dir = _drop_package_name_from_path(dir)

# Check for path existence
isdir(dir) || mkpath(dir)

Expand Down
23 changes: 23 additions & 0 deletions SimpleSDMDatasets/test/moduleimport.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module SSDImportModuleTest
using Test
using SimpleSDMDatasets

# This is not the cleanest test, but it is checking that the module works when called from
# within another module

module TestModule

_prefix = Main.SSDImportModuleTest.SimpleSDMDatasets
using Main.SSDImportModuleTest.SimpleSDMDatasets

function foo()
_prefix.downloader(
RasterData(WorldClim2, BioClim),
layer="BIO7")
end
export foo
end

@test isfile(first(TestModule.foo()))

end
1 change: 1 addition & 0 deletions SimpleSDMDatasets/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ global anyerrors = false

tests = [
"Type basics " => "type_construction.jl",
"Import from within module " => "moduleimport.jl",
"WorldClim2 provider " => "worldclim_v2.jl",
"EarthEnv provider " => "earthenv.jl",
"CHELSA1 provider " => "chelsa_v1.jl",
Expand Down