You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/creating-packages.md
+71-50Lines changed: 71 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -275,79 +275,100 @@ test-specific dependencies, are available, see below.
275
275
276
276
### Test-specific dependencies
277
277
278
-
There are two ways of adding test-specific dependencies (dependencies that are not dependencies of the package but will still be available to
279
-
load when the package is tested).
278
+
Test-specific dependencies are dependencies that are not dependencies of the package itself but are available when the package is tested.
280
279
281
-
#### `target` based test specific dependencies
280
+
#### Recommended approach: Using workspaces with `test/Project.toml`
282
281
283
-
Using this method of adding test-specific dependencies, the packages are added under an `[extras]` section and to a test target,
284
-
e.g. to add `Markdown` and `Test` as test dependencies, add the following to the `Project.toml` file:
285
-
286
-
```toml
287
-
[extras]
288
-
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
289
-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
290
-
291
-
[targets]
292
-
test = ["Markdown", "Test"]
293
-
```
294
-
295
-
Note that the only supported targets are `test` and `build`, the latter of which (not recommended) can be used
296
-
for any `deps/build.jl` scripts.
297
-
298
-
#### Alternative approach: `test/Project.toml` file test specific dependencies
282
+
!!! compat
283
+
Workspaces require Julia 1.12+. For older Julia versions, see the legacy approaches below.
299
284
300
-
!!! note
301
-
The exact interaction between `Project.toml`, `test/Project.toml` and their corresponding
302
-
`Manifest.toml`s are not fully worked out and may be subject to change in future versions.
303
-
The older method of adding test-specific dependencies, described in the previous section,
304
-
will therefore be supported throughout all Julia 1.X releases.
285
+
The recommended way to add test-specific dependencies is to use workspaces. This is done by:
305
286
306
-
In Julia 1.2 and later test dependencies can be declared in `test/Project.toml`. When running
307
-
tests, Pkg will automatically merge this and the package Projects to create the test environment.
287
+
1. Adding a `[workspace]` section to your package's `Project.toml`:
308
288
309
-
!!! note
310
-
If no `test/Project.toml` exists Pkg will use the `target` based test specific dependencies.
289
+
```toml
290
+
[workspace]
291
+
projects = ["test"]
292
+
```
311
293
312
-
To add a test-specific dependency, i.e. a dependency that is available only when testing,
313
-
it is thus enough to add this dependency to the `test/Project.toml` project. This can be
314
-
done from the Pkg REPL by activating this environment, and then use `add` as one normally
315
-
does. Let's add the `Test` standard library as a test dependency:
294
+
2. Creating a `test/Project.toml` file with your test dependencies:
316
295
317
296
```julia-repl
318
297
(HelloWorld) pkg> activate ./test
319
298
[ Info: activating environment at `~/HelloWorld/test/Project.toml`.
320
299
321
-
(test) pkg> add Test
300
+
(HelloWorld/test) pkg> dev . # add current package to test dependencies using its path
301
+
Resolving package versions...
302
+
Updating `~/HelloWorld/test/Project.toml`
303
+
[8dfed614] + HelloWorld v0.1.0 `..`
304
+
305
+
(HelloWorld/test) pkg> add Test # add other test dependencies
322
306
Resolving package versions...
323
307
Updating `~/HelloWorld/test/Project.toml`
324
308
[8dfed614] + Test
325
-
Updating `~/HelloWorld/test/Manifest.toml`
326
-
[...]
327
309
```
328
310
329
-
We can now use `Test` in the test script and we can see that it gets installed when testing:
311
+
When using workspaces, the package manager resolves dependencies for all projects in the workspace together, and creates a single `Manifest.toml` next to the base `Project.toml`. This provides better dependency resolution and makes it easier to manage test-specific dependencies.
312
+
313
+
!!! warning
314
+
Unlike some earlier test dependency workflows, this one explicitly requires adding `HelloWorld` (the parent package) to your `test/Project.toml`.
Workspaces can also be used for other purposes, such as documentation or benchmarks, by adding additional projects to the workspace:
334
+
335
+
```toml
336
+
[workspace]
337
+
projects = ["test", "docs", "benchmarks"]
338
+
```
339
+
340
+
See the section on [Workspaces](@ref) in the `Project.toml` documentation for more details.
341
+
342
+
#### Legacy approach: `target` based test specific dependencies
343
+
344
+
!!! warning
345
+
This approach is legacy and maintained for compatibility. New packages should use workspaces instead.
346
+
347
+
Using this method, test-specific dependencies are added under an `[extras]` section and to a test target:
348
+
349
+
```toml
350
+
[extras]
351
+
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
352
+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
353
+
354
+
[targets]
355
+
test = ["Markdown", "Test"]
356
+
```
357
+
358
+
Note that the only supported targets are `test` and `build`, the latter of which (not recommended) can be used for any `deps/build.jl` scripts.
359
+
360
+
#### Legacy approach: `test/Project.toml` without workspace
361
+
362
+
!!! warning
363
+
This approach is legacy and maintained for compatibility. New packages should use workspaces instead.
364
+
365
+
In Julia 1.2 and later, test dependencies can be declared in `test/Project.toml` without using a workspace. When running tests, Pkg will automatically merge the package and test projects to create the test environment.
366
+
367
+
!!! note
368
+
If no `test/Project.toml` exists, Pkg will use the `target` based test specific dependencies.
369
+
370
+
This approach works similarly to the workspace approach, but without the workspace declaration in the main `Project.toml`.
371
+
351
372
## Compatibility on dependencies
352
373
353
374
Every dependency should in general have a compatibility constraint on it.
@@ -450,9 +471,7 @@ Extensions can have arbitrary names (here `ContourExt`), following the format of
450
471
In `Pkg` output, extension names are always shown together with their parent package name.
451
472
452
473
!!! compat
453
-
Often you will put the extension dependencies into the `test` target so they are loaded when running e.g. `Pkg.test()`. On earlier Julia versions
454
-
this requires you to also put the package in the `[extras]` section. This is unfortunate but the project verifier on older Julia versions will
455
-
complain if this is not done.
474
+
Often you will want to load extension dependencies when testing your package. The recommended approach is to use workspaces and add the extension dependencies to your `test/Project.toml` (see [Test-specific dependencies](@ref adding-tests-to-packages)). For older Julia versions that don't support workspaces, you can put the extension dependencies into the `test` target, which requires you to also put the package in the `[extras]` section. The project verifier on older Julia versions will complain if this is not done.
456
475
457
476
!!! note
458
477
If you use a manifest generated by a Julia version that does not know about extensions with a Julia version that does
@@ -557,12 +576,14 @@ This is done by making the following changes (using the example above):
557
576
558
577
In the case where one wants to use an extension (without worrying about the
559
578
feature of the extension being available on older Julia versions) while still
560
-
supporting older Julia versions the packages under `[weakdeps]` should be
579
+
supporting older Julia versions without workspace support, the packages under `[weakdeps]` should be
561
580
duplicated into `[extras]`. This is an unfortunate duplication, but without
562
581
doing this the project verifier under older Julia versions will throw an error
563
582
if it finds packages under `[compat]` that is not listed in `[extras]`.
564
583
565
-
## Package naming rules
584
+
For Julia 1.12+, using workspaces is recommended and this duplication is not necessary.
Package names should be sensible to most Julia users, *even to those who are not domain experts*.
568
589
The following rules apply to the `General` registry but may be useful for other package
@@ -623,7 +644,7 @@ may fit your package better.
623
644
9. Packages should follow the [Stylistic Conventions](https://docs.julialang.org/en/v1/manual/variables/#Stylistic-Conventions).
624
645
* The package name begin with a capital letter and word separation is shown with upper camel case
625
646
* Packages that provide the functionality of a project from another language should use the Julia convention
626
-
* Packages that [provide pre-built libraries and executables](https://docs.binarybuilder.org/stable/jll/) can keep orignal name, but should get `_jll`as a suffix. For example `pandoc_jll` wraps pandoc. However, note that the generation and release of most JLL packages is handled by the [Yggdrasil](https://github.com/JuliaPackaging/Yggdrasil) system.
647
+
* Packages that [provide pre-built libraries and executables](https://docs.binarybuilder.org/stable/jll/) can keep orignal name, but should get `_jll`as a suffix. For example `pandoc_jll` wraps pandoc. However, note that the generation and release of most JLL packages is handled by the [Yggdrasil](https://github.com/JuliaPackaging/Yggdrasil) system.
This structure is particularly beneficial for developers using a monorepo approach, where a large number of unregistered packages may be involved. It's also useful for adding documentation or benchmarks to a package by including additional dependencies beyond those of the package itself.
155
+
This structure is particularly beneficial for developers using a monorepo approach, where a large number of unregistered packages may be involved. It's also useful for adding test-specific dependencies to a package by including a `test` project in the workspace (see [Test-specific dependencies](@ref adding-tests-to-packages)), or for adding documentation or benchmarks with their own dependencies.
156
156
157
157
Workspace can be nested: a project that itself defines a workspace can also be part of another workspace.
158
158
In this case, the workspaces are "merged" with a single manifest being stored alongside the "root project" (the project that doesn't have another workspace including it).
0 commit comments