Skip to content

Commit

Permalink
Fix the naming issue when imported from a submodule (#167)
Browse files Browse the repository at this point in the history
* 🩹 prepare for new patch release

* 🟩 test (not passing!) for module import

* 🟩 add code to remove the module name from the strings

* ℹ️ remove the @info from the test
  • Loading branch information
tpoisot authored Apr 16, 2023
1 parent ce74a0a commit 39a871e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
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

2 comments on commit 39a871e

@tpoisot
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir="SimpleSDMDatasets"

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/81699

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a SimpleSDMDatasets-v0.1.1 -m "<description of version>" 39a871ea12b35c3eec099ae32d49c1099446a96f
git push origin SimpleSDMDatasets-v0.1.1

Please sign in to comment.