Skip to content

Commit 14f5298

Browse files
committed
remove preview command
1 parent 6477615 commit 14f5298

File tree

13 files changed

+52
-198
lines changed

13 files changed

+52
-198
lines changed

docs/src/managing-packages.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ from that local repo are pulled when packages are updated.
123123
Note that changes to files in the local package repository will not immediately be reflected when loading that package.
124124
The changes would have to be committed and the packages updated in order to pull in the changes.
125125

126-
In addition, it is possible to add packages relatively to the `Manifest.toml` file, see [Developing Packages](@ref) for an example.
126+
In addition, it is possible to add packages relatively to the `Manifest.toml` file, see [Developing Packages](@ref) for an example.
127127

128128
### Developing packages
129129

@@ -300,22 +300,3 @@ To run a typical garbage collection with default arguments, simply use the `gc`
300300
```
301301

302302
Note that only packages in `~/.julia/packages` are deleted.
303-
304-
305-
## Preview mode
306-
307-
If you just want to see the effects of running a command, but not change your state you can `preview` a command.
308-
For example:
309-
310-
```
311-
(HelloWorld) pkg> preview add Plots
312-
```
313-
314-
or
315-
316-
```
317-
(HelloWorld) pkg> preview up
318-
```
319-
320-
will show you the effects that `add Plots`, or `up`, respectively, would have on your project.
321-
However, nothing will be installed and your `Project.toml` and `Manifest.toml` files will remain untouched.

src/API.jl

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ using Pkg.Types: VersionTypes
1515
using ..BinaryPlatforms
1616
using ..Artifacts: artifact_paths
1717

18-
19-
function preview_info(ctx::Context)
20-
if ctx.preview
21-
printstyled(ctx.io, "───── Preview mode ─────\n"; color=Base.info_color(), bold=true)
22-
end
23-
end
24-
2518
include("generate.jl")
2619

2720
dependencies() = dependencies(Context())
@@ -75,15 +68,12 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
7568
pkgerror("Can not specify version when tracking a repo.")
7669
end
7770

78-
preview_info(ctx)
79-
8071
new_git = handle_repos_develop!(ctx, pkgs, shared)
8172

8273
any(pkg -> Types.collides_with_project(ctx, pkg), pkgs) &&
8374
pkgerror("Cannot `develop` package with the same name or uuid as the project")
8475

8576
Operations.develop(ctx, pkgs, new_git; strict=strict, platform=platform)
86-
preview_info(ctx)
8777
return
8878
end
8979

@@ -107,7 +97,6 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; strict::Bool=false,
10797
end
10898
end
10999

110-
preview_info(ctx)
111100
Types.update_registries(ctx)
112101

113102
repo_pkgs = [pkg for pkg in pkgs if (pkg.repo.url !== nothing || pkg.repo.rev !== nothing)]
@@ -124,7 +113,6 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; strict::Bool=false,
124113
pkgerror("Cannot add package with the same name or uuid as the project")
125114

126115
Operations.add(ctx, pkgs, new_git; strict=strict, platform=platform)
127-
preview_info(ctx)
128116
return
129117
end
130118

@@ -147,14 +135,12 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode=PKGMODE_PROJECT, kwarg
147135
end
148136

149137
Context!(ctx; kwargs...)
150-
preview_info(ctx)
151138

152139
project_deps_resolve!(ctx, pkgs)
153140
manifest_resolve!(ctx, pkgs)
154141
ensure_resolved(ctx, pkgs)
155142

156143
Operations.rm(ctx, pkgs)
157-
preview_info(ctx)
158144
return
159145
end
160146

@@ -171,7 +157,6 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
171157
foreach(pkg -> pkg.mode = mode, pkgs)
172158

173159
Context!(ctx; kwargs...)
174-
preview_info(ctx)
175160
if update_registry
176161
Types.clone_default_registries(ctx)
177162
Types.update_registries(ctx; force=true)
@@ -192,7 +177,6 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
192177
ensure_resolved(ctx, pkgs)
193178
end
194179
Operations.up(ctx, pkgs, level)
195-
preview_info(ctx)
196180
return
197181
end
198182

@@ -206,7 +190,6 @@ pin(pkgs::Vector{PackageSpec}; kwargs...) = pin(Context(), pkgs; k
206190
function pin(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
207191
pkgs = deepcopy(pkgs) # deepcopy for avoid mutating PackageSpec members
208192
Context!(ctx; kwargs...)
209-
preview_info(ctx)
210193

211194
for pkg in pkgs
212195
pkg.name !== nothing || pkg.uuid !== nothing ||
@@ -230,7 +213,6 @@ free(pkgs::Vector{PackageSpec}; kwargs...) = free(Context(), pkgs;
230213
function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
231214
pkgs = deepcopy(pkgs) # deepcopy for avoid mutating PackageSpec members
232215
Context!(ctx; kwargs...)
233-
preview_info(ctx)
234216

235217
for pkg in pkgs
236218
pkg.name !== nothing || pkg.uuid !== nothing ||
@@ -264,7 +246,6 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
264246
test_args = Cmd(test_args)
265247
pkgs = deepcopy(pkgs) # deepcopy for avoid mutating PackageSpec members
266248
Context!(ctx; kwargs...)
267-
preview_info(ctx)
268249
if isempty(pkgs)
269250
ctx.env.pkg === nothing && pkgerror("trying to test unnamed project") #TODO Allow this?
270251
push!(pkgs, ctx.env.pkg)
@@ -289,7 +270,6 @@ for a period of `collect_delay`; which defaults to thirty days.
289270
"""
290271
function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
291272
Context!(ctx; kwargs...)
292-
preview_info(ctx)
293273
env = ctx.env
294274

295275
# First, we load in our `manifest_usage.toml` files which will tell us when our
@@ -349,27 +329,25 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
349329
all_index_files = Set(filter(isfile, all_index_files))
350330

351331
# Immediately write this back as condensed manifest_usage.toml files
352-
if !ctx.preview
353-
function write_condensed_usage(usage_by_depot, fname)
354-
for (depot, usage) in usage_by_depot
355-
# Keep only the keys of the files that are still extant
356-
usage = filter(p -> p[1] in all_index_files, usage)
357-
358-
# Expand it back into a dict of arrays-of-dicts
359-
usage = Dict(k => [Dict("time" => v)] for (k, v) in usage)
360-
361-
# Write it out to disk within this depot
362-
usage_path = joinpath(logdir(depot), fname)
363-
if !isempty(usage) || isfile(usage_path)
364-
open(usage_path, "w") do io
365-
TOML.print(io, usage, sorted=true)
366-
end
332+
function write_condensed_usage(usage_by_depot, fname)
333+
for (depot, usage) in usage_by_depot
334+
# Keep only the keys of the files that are still extant
335+
usage = filter(p -> p[1] in all_index_files, usage)
336+
337+
# Expand it back into a dict of arrays-of-dicts
338+
usage = Dict(k => [Dict("time" => v)] for (k, v) in usage)
339+
340+
# Write it out to disk within this depot
341+
usage_path = joinpath(logdir(depot), fname)
342+
if !isempty(usage) || isfile(usage_path)
343+
open(usage_path, "w") do io
344+
TOML.print(io, usage, sorted=true)
367345
end
368346
end
369347
end
370-
write_condensed_usage(manifest_usage_by_depot, "manifest_usage.toml")
371-
write_condensed_usage(artifact_usage_by_depot, "artifact_usage.toml")
372348
end
349+
write_condensed_usage(manifest_usage_by_depot, "manifest_usage.toml")
350+
write_condensed_usage(artifact_usage_by_depot, "artifact_usage.toml")
373351

374352
# Next, we will process the manifest.toml and artifacts.toml files separately,
375353
# extracting from them the paths of the packages and artifacts that they reference.
@@ -553,8 +531,8 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
553531
merge_orphanages!(new_orphanage, depot_orphaned_packages, packages_to_delete, old_orphanage)
554532
merge_orphanages!(new_orphanage, depot_orphaned_artifacts, artifacts_to_delete, old_orphanage)
555533

556-
# Write out the `new_orphanage` for this depot, if we're not in preview mode.
557-
if !ctx.preview && (!isempty(new_orphanage) || isfile(orphanage_file))
534+
# Write out the `new_orphanage` for this depot
535+
if !isempty(new_orphanage) || isfile(orphanage_file)
558536
mkpath(dirname(orphanage_file))
559537
open(orphanage_file, "w") do io
560538
TOML.print(io, new_orphanage, sorted=true)
@@ -586,12 +564,10 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
586564
# Delete paths for unreachable package versions and artifacts, and computing size saved
587565
function delete_path(path)
588566
path_size = recursive_dir_size(path)
589-
if !ctx.preview
590-
try
591-
Base.rm(path; recursive=true)
592-
catch
593-
@warn "Failed to delete $path"
594-
end
567+
try
568+
Base.rm(path; recursive=true)
569+
catch
570+
@warn "Failed to delete $path"
595571
end
596572
printpkgstyle(ctx, :Deleted, Types.pathrepr(path) * " (" * pretty_byte_str(path_size) * ")")
597573
return path_size
@@ -607,18 +583,16 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
607583
end
608584

609585
# Prune package paths that are now empty
610-
if !ctx.preview
611-
for depot in depots()
612-
packagedir = abspath(depot, "packages")
613-
!isdir(packagedir) && continue
586+
for depot in depots()
587+
packagedir = abspath(depot, "packages")
588+
!isdir(packagedir) && continue
614589

615-
for name in readdir(packagedir)
616-
name_path = joinpath(packagedir, name)
617-
!isdir(name_path) && continue
618-
!isempty(readdir(name_path)) && continue
590+
for name in readdir(packagedir)
591+
name_path = joinpath(packagedir, name)
592+
!isdir(name_path) && continue
593+
!isempty(readdir(name_path)) && continue
619594

620-
Base.rm(name_path)
621-
end
595+
Base.rm(name_path)
622596
end
623597
end
624598

@@ -639,8 +613,6 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(30), kwargs...)
639613
printpkgstyle(ctx, :Deleted, "no artifacts or packages")
640614
end
641615

642-
preview_info(ctx)
643-
644616
return
645617
end
646618

@@ -652,7 +624,6 @@ function build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, kwargs...
652624
pkgs = deepcopy(pkgs) # deepcopy for avoid mutating PackageSpec members
653625
Context!(ctx; kwargs...)
654626

655-
preview_info(ctx)
656627
if isempty(pkgs)
657628
if ctx.env.pkg !== nothing
658629
push!(pkgs, ctx.env.pkg)
@@ -667,7 +638,6 @@ function build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, kwargs...
667638
manifest_resolve!(ctx, pkgs)
668639
ensure_resolved(ctx, pkgs)
669640
Operations.build(ctx, pkgs, verbose)
670-
preview_info(ctx)
671641
end
672642

673643
precompile() = precompile(Context())

src/Operations.jl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,6 @@ function download_source(ctx::Context, pkgs::Vector{PackageSpec},
581581
for i in 1:ctx.num_concurrent_downloads
582582
@async begin
583583
for (pkg, path) in jobs
584-
if ctx.preview
585-
put!(results, (pkg, true, path))
586-
continue
587-
end
588584
if ctx.use_libgit2_for_all_downloads
589585
put!(results, (pkg, false, path))
590586
continue
@@ -624,10 +620,8 @@ function download_source(ctx::Context, pkgs::Vector{PackageSpec},
624620
##################################################
625621
for (pkg, path) in missed_packages
626622
uuid = pkg.uuid
627-
if !ctx.preview
628-
install_git(ctx, pkg.uuid, pkg.name, pkg.tree_hash, urls[uuid], pkg.version::VersionNumber, path)
629-
readonly && set_readonly(path)
630-
end
623+
install_git(ctx, pkg.uuid, pkg.name, pkg.tree_hash, urls[uuid], pkg.version::VersionNumber, path)
624+
readonly && set_readonly(path)
631625
vstr = pkg.version != nothing ? "v$(pkg.version)" : "[$h]"
632626
printpkgstyle(ctx, :Installed, string(rpad(pkg.name * " ", max_name + 2, ""), " ", vstr))
633627
end
@@ -694,7 +688,7 @@ function _get_deps!(ctx::Context, pkgs::Vector{PackageSpec}, uuids::Vector{UUID}
694688
end
695689

696690
function build(ctx::Context, pkgs::Vector{PackageSpec}, verbose::Bool)
697-
if !ctx.preview && (any_package_not_installed(ctx) || !isfile(ctx.env.manifest_file))
691+
if any_package_not_installed(ctx) || !isfile(ctx.env.manifest_file)
698692
Pkg.instantiate(ctx)
699693
end
700694
uuids = UUID[]
@@ -745,7 +739,6 @@ builddir(source_path::String) = joinpath(source_path, "deps")
745739
buildfile(source_path::String) = joinpath(builddir(source_path), "build.jl")
746740
function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve=false, verbose=false)
747741
# collect builds for UUIDs with `deps/build.jl` files
748-
ctx.preview && (printpkgstyle(ctx, :Building, "skipping building in preview mode"); return)
749742
builds = Tuple{UUID,String,String,VersionNumber}[]
750743
for uuid in uuids
751744
uuid in keys(ctx.stdlibs) && continue
@@ -1252,7 +1245,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
12521245
coverage=false, test_fn=nothing,
12531246
julia_args::Cmd=``,
12541247
test_args::Cmd=``)
1255-
ctx.preview || Pkg.instantiate(ctx)
1248+
Pkg.instantiate(ctx)
12561249

12571250
# load manifest data
12581251
for pkg in pkgs
@@ -1289,10 +1282,6 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
12891282
end
12901283

12911284
printpkgstyle(ctx, :Testing, pkg.name)
1292-
if ctx.preview
1293-
println(ctx.io, "In preview mode, skipping tests for $(pkg.name)")
1294-
continue
1295-
end
12961285
sandbox(ctx, pkg, source_path, testdir(source_path)) do
12971286
println(ctx.io, "Running sandbox")
12981287
test_fn !== nothing && test_fn()

src/REPLMode/REPLMode.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ Base.@kwdef mutable struct Statement
158158
spec::Union{Nothing,CommandSpec} = nothing
159159
options::Union{Vector{Option},Vector{String}} = String[]
160160
arguments::Vector{QString} = QString[]
161-
preview::Bool = false
162161
end
163162

164163
function lex(cmd::String)::Vector{QString}
@@ -242,10 +241,6 @@ function core_parse(words::Vector{QString}; only_cmd=false)
242241

243242
# begin parsing
244243
next_word!() || return statement, ((word === nothing) ? nothing : word.raw)
245-
if word.raw == "preview"
246-
statement.preview = true
247-
next_word!() || return statement, word.raw
248-
end
249244
# handle `?` alias for help
250245
# It is special in that it requires no space between command and args
251246
if word.raw[1]=='?' && !word.isquoted
@@ -314,7 +309,6 @@ Base.@kwdef struct Command
314309
spec::Union{Nothing,CommandSpec} = nothing
315310
options::APIOptions = APIOptions()
316311
arguments::Vector = []
317-
preview::Bool = false
318312
end
319313

320314
function enforce_option(option::Option, specs::Dict{String,OptionSpec})
@@ -369,7 +363,7 @@ function Command(statement::Statement)::Command
369363
opt_spec = statement.spec.option_specs
370364
enforce_option(statement.options, opt_spec)
371365
options = APIOptions(statement.options, opt_spec)
372-
return Command(statement.spec, options, arguments, statement.preview)
366+
return Command(statement.spec, options, arguments)
373367
end
374368

375369
#############
@@ -393,7 +387,7 @@ function do_cmd(repl::REPL.AbstractREPL, input::String; do_rethrow=false)
393387
end
394388

395389
function do_cmd!(command::Command, repl)
396-
context = Dict{Symbol,Any}(:preview => command.preview)
390+
context = Dict{Symbol,Any}()
397391

398392
# REPL specific commands
399393
command.spec === SPECS[]["package"]["help"] && return Base.invokelatest(do_help!, command, repl)

src/REPLMode/command_declarations.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,6 @@ the output to the difference as compared to the last git commit.
304304
305305
Deletes packages that cannot be reached from any existing environment.
306306
""",
307-
],[ # preview is not a regular command.
308-
# this is here so that preview appears as a registered command to users
309-
:name => "preview",
310-
:description => "previews a subsequent command without affecting the current state",
311-
:help => md"""
312-
preview cmd
313-
314-
Runs the command `cmd` in preview mode. This is defined such that no side effects
315-
will take place i.e. no packages are downloaded and neither the project nor manifest
316-
is modified.
317-
""",
318307
],
319308
], #package
320309
"registry" => CommandDeclaration[

0 commit comments

Comments
 (0)