Skip to content

Commit 7019323

Browse files
authored
feat(dev): add the [dev] section to CondaPkg.toml (#198)
* feat(dev): add the [dev] section to CondaPkg.toml * missed some docstrings * test(dev): test that the dev dependencies are installed --------- Co-authored-by: Christopher Doris <github.com/cjdoris>
1 parent 57c7997 commit 7019323

File tree

7 files changed

+210
-88
lines changed

7 files changed

+210
-88
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
* Add `dev` section to CondaPkg.toml, specifying development dependencies which are only
5+
installed for packages being developed/tested.
6+
37
## 0.2.32 (2025-09-17)
48
* Add `editable` property to pip packages, specifying whether to install them in
59
editable mode.

CondaPkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
[dev.deps]
3+
tomli = "==2.2.1"
4+
requests = "==2.32.5"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ version = "~=2.1"
9191
extras = ["email", "timezone"]
9292
binary = "no" # or "only"
9393
editable = true
94+
95+
[dev.deps]
96+
# Development dependencies, only installed for packages being developed/tested.
97+
numpy = "~=2.0"
9498
```
9599

96100
## Access the Conda environment
@@ -317,6 +321,19 @@ For example, to map conda-forge to a corporate mirror:
317321
pkg> preference add CondaPkg channel_mapping=conda-forge->corporate-conda-mirror
318322
```
319323

324+
### Dev dependencies
325+
326+
The `[dev]` section in a CondaPkg.toml is parsed if it is in a package which is
327+
currently being developed (in the sense of `Pkg.develop`) or tested. It can contain
328+
`deps`, `channels` and `pip_deps` that are only required while developing or testing
329+
the package and will not be installed for ordinary users.
330+
331+
You can pass `dev=true` to the `add` and `rm` functions to modify the `dev` section.
332+
333+
Similarly you can pass `--dev` to the `add` and `rm` commands in the Pkg REPL.
334+
335+
Dev dependencies are shown by `status()` in separate sections.
336+
320337
## Frequently Asked Questions
321338

322339
### Can I get my package to use a specific Conda environment?

src/PkgREPL.jl

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $
2626
CondaPkg.PkgSpec(name, version = version, channel = channel, build = build)
2727
end
2828

29-
function parse_pip_pkg(x::String; binary::String = "", editable=false)
29+
function parse_pip_pkg(x::String; binary::String = "", editable = false)
3030
m = match(
3131
r"""
3232
^
@@ -41,7 +41,13 @@ $
4141
name = m.captures[1]
4242
extras = split(something(m.captures[3], ""), ",", keepempty = false)
4343
version = something(m.captures[4], "")
44-
CondaPkg.PipPkgSpec(name, version = version, binary = binary, extras = extras, editable = editable)
44+
CondaPkg.PipPkgSpec(
45+
name,
46+
version = version,
47+
binary = binary,
48+
extras = extras,
49+
editable = editable,
50+
)
4551
end
4652

4753
function parse_channel(x::String)
@@ -69,6 +75,8 @@ const editable_opt = Pkg.REPLMode.OptionDeclaration([
6975
:api => :editable => true,
7076
])
7177

78+
const dev_opt = Pkg.REPLMode.OptionDeclaration([:name => "dev", :api => :dev => true])
79+
7280
### status
7381

7482
function status()
@@ -136,13 +144,13 @@ const update_spec = Pkg.REPLMode.CommandSpec(
136144

137145
### add
138146

139-
function add(args)
140-
CondaPkg.add(parse_pkg.(args))
147+
function add(args; dev = false)
148+
CondaPkg.add(parse_pkg.(args); dev)
141149
end
142150

143151
const add_help = Markdown.parse("""
144152
```
145-
conda add pkg ...
153+
conda add [--dev] pkg ...
146154
```
147155
148156
Add packages to the environment.
@@ -165,17 +173,18 @@ const add_spec = Pkg.REPLMode.CommandSpec(
165173
help = add_help,
166174
description = "add Conda packages",
167175
arg_count = 0 => Inf,
176+
option_spec = [dev_opt],
168177
)
169178

170179
### channel_add
171180

172-
function channel_add(args)
173-
CondaPkg.add(parse_channel.(args))
181+
function channel_add(args; dev = false)
182+
CondaPkg.add(parse_channel.(args); dev)
174183
end
175184

176185
const channel_add_help = Markdown.parse("""
177186
```
178-
conda channel_add channel ...
187+
conda channel_add [--dev] channel ...
179188
```
180189
181190
Add channels to the environment.
@@ -194,17 +203,18 @@ const channel_add_spec = Pkg.REPLMode.CommandSpec(
194203
help = channel_add_help,
195204
description = "add Conda channels",
196205
arg_count = 0 => Inf,
206+
option_spec = [dev_opt],
197207
)
198208

199209
### pip_add
200210

201-
function pip_add(args; binary = "", editable = false)
202-
CondaPkg.add([parse_pip_pkg(arg, binary = binary, editable = editable) for arg in args])
211+
function pip_add(args; binary = "", editable = false, dev = false)
212+
CondaPkg.add([parse_pip_pkg(arg; binary, editable) for arg in args]; dev)
203213
end
204214

205215
const pip_add_help = Markdown.parse("""
206216
```
207-
conda pip_add [--binary={only|no}] [--editable] pkg ...
217+
conda pip_add [--binary={only|no}] [--editable] [--dev] pkg ...
208218
```
209219
210220
Add Pip packages to the environment.
@@ -227,18 +237,18 @@ const pip_add_spec = Pkg.REPLMode.CommandSpec(
227237
help = pip_add_help,
228238
description = "add Pip packages",
229239
arg_count = 0 => Inf,
230-
option_spec = [binary_opt, editable_opt],
240+
option_spec = [binary_opt, editable_opt, dev_opt],
231241
)
232242

233243
### rm
234244

235-
function rm(args)
236-
CondaPkg.rm(parse_pkg.(args))
245+
function rm(args; dev = false)
246+
CondaPkg.rm(parse_pkg.(args); dev)
237247
end
238248

239249
const rm_help = Markdown.parse("""
240250
```
241-
conda rm|remove pkg ...
251+
conda rm|remove [--dev] pkg ...
242252
```
243253
244254
Remove packages from the environment.
@@ -258,17 +268,18 @@ const rm_spec = Pkg.REPLMode.CommandSpec(
258268
help = rm_help,
259269
description = "remove Conda packages",
260270
arg_count = 0 => Inf,
271+
option_spec = [dev_opt],
261272
)
262273

263274
### channel_rm
264275

265-
function channel_rm(args)
266-
CondaPkg.rm(parse_channel.(args))
276+
function channel_rm(args; dev = false)
277+
CondaPkg.rm(parse_channel.(args); dev)
267278
end
268279

269280
const channel_rm_help = Markdown.parse("""
270281
```
271-
conda channel_rm|channel_remove channel ...
282+
conda channel_rm|channel_remove [--dev] channel ...
272283
```
273284
274285
Remove channels from the environment.
@@ -288,17 +299,18 @@ const channel_rm_spec = Pkg.REPLMode.CommandSpec(
288299
help = channel_rm_help,
289300
description = "remove Conda channels",
290301
arg_count = 0 => Inf,
302+
option_spec = [dev_opt],
291303
)
292304

293305
### pip_rm
294306

295-
function pip_rm(args)
296-
CondaPkg.rm(parse_pip_pkg.(args))
307+
function pip_rm(args; dev = false)
308+
CondaPkg.rm(parse_pip_pkg.(args); dev)
297309
end
298310

299311
const pip_rm_help = Markdown.parse("""
300312
```
301-
conda pip_rm|pip_remove pkg ...
313+
conda pip_rm|pip_remove [--dev] pkg ...
302314
```
303315
304316
Remove Pip packages from the environment.
@@ -318,6 +330,7 @@ const pip_rm_spec = Pkg.REPLMode.CommandSpec(
318330
help = pip_rm_help,
319331
description = "remove Pip packages",
320332
arg_count = 0 => Inf,
333+
option_spec = [dev_opt],
321334
)
322335

323336
### gc

0 commit comments

Comments
 (0)