Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit ee7fcab

Browse files
committed
Replace @import with @require
1 parent 1e3b988 commit ee7fcab

File tree

6 files changed

+62
-440
lines changed

6 files changed

+62
-440
lines changed

docs/src/packages.org

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data transformer, one would come across packages that /may/ be needed.
55

66
Every possibly desired package could be shoved into the list of dependences, but
77
this is a somewhat crude approach. A more granular approach is enabled with two
8-
macros, ~@addpkg~ and ~@import~.
8+
macros, ~@addpkg~ and ~@require~.
99

1010
* Letting DataToolkitBase know about extra packages
1111

@@ -16,7 +16,7 @@ macros, ~@addpkg~ and ~@import~.
1616
* Using extra packages
1717

1818
#+begin_src @docs
19-
@import
19+
@require
2020
#+end_src
2121

2222
* Example
@@ -33,18 +33,45 @@ function __init__()
3333
end
3434

3535
function load(::DataLoader{:csv}, from::IOStream, ::Type{DataFrame})
36-
@import CSV
36+
@require CSV
3737
result = CSV.read(from, DataFrame)
3838
close(from)
3939
result
4040
end
4141

4242
function load(::DataLoader{:delimcsv}, from::IOStream, ::Type{DataFrame})
43-
@import DelimitedFiles
43+
@require DelimitedFiles
4444
result = DelimitedFiles.readdlm(from, ',', DataFrame)
4545
close(from)
4646
result
4747
end
4848

4949
end
5050
#+end_src
51+
52+
Packages that implement loaders with other packages are recommended to use Julia
53+
1.9's [[https://pkgdocs.julialang.org/dev/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)][Package Extensions]], together with the ~@requires~ macro and ~invokelatest~ like so:
54+
55+
#+begin_src julia
56+
# CsvLoaderPkg/src/loader.jl
57+
function load(::DataLoader{:csv}, from::IOStream, t::Type{DataFrame})
58+
@require CSV
59+
invokelatest(_load_csv, from, t)
60+
end
61+
#+end_src
62+
63+
#+begin_src julia
64+
# CsvLoaderPkg/ext/csv.jl
65+
module csv
66+
67+
using CSV
68+
import CsvLoaderPkg: _load_csv
69+
70+
function _load_csv(from::IOStream, ::Type{DataFrame})
71+
result = CSV.read(from, DataFrame)
72+
close(from)
73+
result
74+
end
75+
76+
end
77+
#+end_src

src/DataToolkitBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export IdentifierException, UnresolveableIdentifier, AmbiguousIdentifier,
2020
ReadonlyCollection, TransformerError, UnsatisfyableTransformer,
2121
OrphanDataSet, InvalidParameterType
2222
export STACK, DATA_CONFIG_RESERVED_ATTRIBUTES
23-
export @import, @addpkg, @dataplugin, @advise, @getparam
23+
export @require, @addpkg, @dataplugin, @advise, @getparam
2424

2525
# For plugin packages
2626
export PLUGINS, PLUGINS_DOCUMENTATION, DEFAULT_PLUGINS, Plugin,

src/model/errors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ registered by `mod`, and so cannot be loaded.
204204
# Example occurrence
205205
206206
```julia-repl
207-
julia> @import Foo
207+
julia> @require Foo
208208
ERROR: UnregisteredPackage: Foo has not been registered by Main, see @addpkg for more information
209209
Stacktrace: [...]
210210
```
@@ -258,7 +258,7 @@ current environment.
258258
julia> @addpkg Bar "00000000-0000-0000-0000-000000000000"
259259
Bar [00000000-0000-0000-0000-000000000000]
260260
261-
julia> @import Bar
261+
julia> @require Bar
262262
[ Info: Lazy-loading Bar [00000000-0000-0000-0000-000000000001]
263263
ERROR: MissingPackage: Bar [00000000-0000-0000-0000-000000000001] has been required, but does not seem to be installed.
264264
Stacktrace: [...]

src/model/globals.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ new data collection.
2626
const DEFAULT_PLUGINS = String[]
2727

2828
"""
29-
The set of packages loaded by each module via `@addpkg`, for import with `@import`.
29+
The set of packages loaded by each module via `@addpkg`, for import with `@require`.
3030
3131
More specifically, when a module M invokes `@addpkg pkg id` then
3232
`EXTRA_PACKAGES[M][pkg] = id` is set, and then this information is used
33-
with `@import` to obtain the package from the root module.
33+
with `@require` to obtain the package from the root module.
3434
"""
3535
const EXTRA_PACKAGES = Dict{Module, Dict{Symbol, Base.PkgId}}()
3636

0 commit comments

Comments
 (0)