1
- """
2
- Given a remote repo URL and a git tree spec, get a `Project` object
3
- for the project file in that tree and a hash string for the tree.
4
- """
5
- # function get_project(remote_url::AbstractString, tree_spec::AbstractString)
6
- # # TODO ?: use raw file downloads for GitHub/GitLab
7
- # mktempdir(mkpath("packages")) do tmp
8
- # # bare clone the package repo
9
- # @debug("bare clone the package repo")
10
- # repo = LibGit2.clone(remote_url, joinpath(tmp, "repo"), isbare=true)
11
- # tree = try
12
- # LibGit2.GitObject(repo, tree_spec)
13
- # catch err
14
- # err isa LibGit2.GitError && err.code == LibGit2.Error.ENOTFOUND || rethrow(err)
15
- # error("$remote_url: git object $(repr(tree_spec)) could not be found")
16
- # end
17
- # tree isa LibGit2.GitTree || (tree = LibGit2.peel(LibGit2.GitTree, tree))
18
- #
19
- # # check out the requested tree
20
- # @debug("check out the requested tree")
21
- # tree_path = abspath(tmp, "tree")
22
- # GC.@preserve tree_path begin
23
- # opts = LibGit2.CheckoutOptions(
24
- # checkout_strategy = LibGit2.Consts.CHECKOUT_FORCE,
25
- # target_directory = Base.unsafe_convert(Cstring, tree_path)
26
- # )
27
- # LibGit2.checkout_tree(repo, tree, options=opts)
28
- # end
29
- #
30
- # # look for a project file in the tree
31
- # @debug("look for a project file in the tree")
32
- # project_file = Pkg.Types.projectfile_path(tree_path)
33
- # project_file !== nothing && isfile(project_file) ||
34
- # error("$remote_url: git tree $(repr(tree_spec)) has no project file")
35
- #
36
- # # parse the project file
37
- # @debug("parse the project file")
38
- # project = Pkg.Types.read_project(project_file)
39
- # project.name === nothing &&
40
- # error("$remote_url $(repr(tree_spec)): package has no name")
41
- # project.uuid === nothing &&
42
- # error("$remote_url $(repr(tree_spec)): package has no UUID")
43
- # project.version === nothing &&
44
- # error("$remote_url $(repr(tree_spec)): package has no version")
45
- #
46
- # return project, string(LibGit2.GitHash(tree))
47
- # end
48
- # end
49
-
50
- function getdeps (pkg)
51
- if PKG_HAS_WEAK
52
- return merge (pkg. deps, pkg. _deps_weak)
53
- end
54
- return pkg. deps
55
- end
56
-
57
1
# These can compromise the integrity of the registry and cannot be
58
2
# opted out of.
59
3
const mandatory_errors = [:version_exists ,
@@ -105,7 +49,7 @@ struct RegBranch
105
49
106
50
metadata:: Dict{String, Any} # "error", "warning", kind etc.
107
51
108
- function RegBranch (pkg:: Pkg.Types. Project , branch:: AbstractString )
52
+ function RegBranch (pkg:: Project , branch:: AbstractString )
109
53
new (pkg. name, pkg. version, branch, Dict {String,Any} ())
110
54
end
111
55
end
@@ -282,7 +226,7 @@ function versionrange(lo::VersionBound, hi::VersionBound)
282
226
return VersionRange (lo, hi)
283
227
end
284
228
285
- function find_package_in_registry (pkg:: Pkg.Types. Project ,
229
+ function find_package_in_registry (pkg:: Project ,
286
230
registry_file:: AbstractString ,
287
231
registry_path:: AbstractString ,
288
232
registry_data:: RegistryData ,
@@ -346,7 +290,7 @@ function check_package!(package_repo::AbstractString,
346
290
return package_repo
347
291
end
348
292
349
- function update_package_file (pkg:: Pkg.Types. Project ,
293
+ function update_package_file (pkg:: Project ,
350
294
package_repo:: AbstractString ,
351
295
subdir:: AbstractString ,
352
296
package_path:: AbstractString )
@@ -371,15 +315,15 @@ function get_versions_file(package_path::AbstractString)
371
315
return filename, data
372
316
end
373
317
374
- function check_versions! (pkg:: Pkg.Types. Project ,
318
+ function check_versions! (pkg:: Project ,
375
319
versions_data:: Dict{String, Any} ,
376
320
status:: ReturnStatus )
377
321
versions = sort! ([VersionNumber (v) for v in keys (versions_data)])
378
322
check_version! (pkg. version, versions, status)
379
323
return versions
380
324
end
381
325
382
- function update_versions_file (pkg:: Pkg.Types. Project ,
326
+ function update_versions_file (pkg:: Project ,
383
327
versions_file:: AbstractString ,
384
328
versions_data:: Dict{String, Any} ,
385
329
tree_hash:: AbstractString )
@@ -408,12 +352,10 @@ function update_versions_file(pkg::Pkg.Types.Project,
408
352
end
409
353
end
410
354
411
- function check_deps! (pkg:: Pkg.Types. Project ,
355
+ function check_deps! (pkg:: Project ,
412
356
regdata:: Vector{RegistryData} ,
413
357
status:: ReturnStatus )
414
- depses = [getdeps (pkg)]
415
- PKG_HAS_WEAK && push! (depses, pkg. weakdeps)
416
- for deps in depses
358
+ for deps in [pkg. deps, pkg. weakdeps]
417
359
if pkg. name in keys (deps)
418
360
err = :package_self_dep
419
361
@debug (err)
@@ -433,12 +375,10 @@ end
433
375
# Versions.toml after update. This is handled with the `old_versions'
434
376
# argument and the assumption that Versions.toml has been updated with
435
377
# the new version before calling this function.
436
- function update_deps_file (pkg:: Pkg.Types. Project ,
378
+ function update_deps_file (pkg:: Project ,
437
379
package_path:: AbstractString ,
438
380
old_versions:: Vector{VersionNumber} )
439
- file_depses = [(" Deps.toml" , getdeps (pkg))]
440
- PKG_HAS_WEAK && push! (file_depses, (" WeakDeps.toml" , pkg. weakdeps))
441
- for (file, deps) in file_depses
381
+ for (file, deps) in [(" Deps.toml" , pkg. deps), (" WeakDeps.toml" , pkg. weakdeps)]
442
382
deps_file = joinpath (package_path, file)
443
383
if isfile (deps_file)
444
384
deps_data = Compress. load (deps_file, old_versions)
@@ -453,17 +393,12 @@ function update_deps_file(pkg::Pkg.Types.Project,
453
393
end
454
394
end
455
395
456
- function check_compat! (pkg:: Pkg.Types. Project ,
396
+ function check_compat! (pkg:: Project ,
457
397
regdata:: Vector{RegistryData} ,
458
- regpaths:: Vector{String} ,
459
398
status:: ReturnStatus )
460
399
if haskey (pkg. compat, " julia" )
461
- if Base. VERSION >= v " 1.7-"
462
- ver = pkg. compat[" julia" ]. val
463
- else
464
- ver = Pkg. Types. semver_spec (pkg. compat[" julia" ])
465
- end
466
- if any (map (x -> ! isempty (intersect (Pkg. Types. VersionRange (" 0-0.6" ), x)), ver. ranges))
400
+ ver = Pkg. Types. semver_spec (pkg. compat[" julia" ])
401
+ if any (map (x -> ! isempty (intersect (VersionRange (" 0-0.6" ), x)), ver. ranges))
467
402
err = :julia_before_07_in_compat
468
403
@debug (err)
469
404
add! (status, err)
@@ -476,9 +411,9 @@ function check_compat!(pkg::Pkg.Types.Project,
476
411
# entries not mentioned in deps, nor in extras.
477
412
invalid_compats = []
478
413
for name in keys (pkg. compat)
479
- indeps = haskey (getdeps ( pkg), name)
480
- inextras = haskey (pkg. extras, name)
481
- inweaks = PKG_HAS_WEAK ? haskey (pkg. weakdeps, name) : false
414
+ indeps = haskey (pkg. deps, name)
415
+ inextras = haskey (pkg. extras, name)
416
+ inweaks = haskey (pkg. weakdeps, name)
482
417
if ! (indeps || inextras || inweaks || name == " julia" )
483
418
push! (invalid_compats, name)
484
419
end
@@ -500,11 +435,11 @@ function check_compat!(pkg::Pkg.Types.Project,
500
435
# anyway.
501
436
for name in keys (pkg. compat)
502
437
if name != " julia"
503
- indeps = haskey (getdeps ( pkg), name)
438
+ indeps = haskey (pkg. deps, name)
504
439
inextras = haskey (pkg. extras, name)
505
440
506
441
if indeps
507
- uuidofdep = string (getdeps ( pkg) [name])
442
+ uuidofdep = string (pkg. deps [name])
508
443
findpackageerror! (name, uuidofdep, regdata, status)
509
444
elseif inextras
510
445
uuidofdep = string (pkg. extras[name])
@@ -520,14 +455,12 @@ end
520
455
521
456
# See the comments for `update_deps_file` for the rationale for the
522
457
# `old_versions` argument.
523
- function update_compat_file (pkg:: Pkg.Types. Project ,
458
+ function update_compat_file (pkg:: Project ,
524
459
package_path:: AbstractString ,
525
460
old_versions:: Vector{VersionNumber} )
526
461
@debug (" update package data: compat file" )
527
462
528
- file_depses = [(" Compat.toml" , getdeps (pkg))]
529
- PKG_HAS_WEAK && push! (file_depses, (" WeakCompat.toml" , pkg. weakdeps))
530
- for (file, deps) in file_depses
463
+ for (file, deps) in [(" Compat.toml" , pkg. deps), (" WeakCompat.toml" , pkg. weakdeps)]
531
464
compat_file = joinpath (package_path, file)
532
465
if isfile (compat_file)
533
466
compat_data = Compress. load (compat_file, old_versions)
@@ -546,11 +479,8 @@ function update_compat_file(pkg::Pkg.Types.Project,
546
479
continue
547
480
end
548
481
549
- if Base. VERSION >= v " 1.7-"
550
- spec = version. val
551
- else
552
- spec = Pkg. Types. semver_spec (version)
553
- end
482
+ spec = Pkg. Types. semver_spec (version)
483
+
554
484
# The call to `map(versionrange, )` can be removed
555
485
# once Pkg is updated to a version including
556
486
# https://github.com/JuliaLang/Pkg.jl/pull/1181
@@ -568,6 +498,7 @@ function update_compat_file(pkg::Pkg.Types.Project,
568
498
end
569
499
570
500
function get_registrator_tree_sha ()
501
+ # TODO : Rewrite this to not use as much Pkg internals
571
502
# If Registrator is in the manifest, return its tree-sha.
572
503
# Otherwise return the tree-sha for RegistryTools.
573
504
manifest = Pkg. Types. Context (). env. manifest
@@ -581,7 +512,7 @@ function get_registrator_tree_sha()
581
512
return " unknown"
582
513
end
583
514
584
- function check_and_update_registry_files (pkg, package_repo, tree_hash,
515
+ function check_and_update_registry_files (pkg:: Project , package_repo, tree_hash,
585
516
registry_path, registry_deps_paths,
586
517
status; subdir = " " )
587
518
# find package in registry
@@ -617,8 +548,7 @@ function check_and_update_registry_files(pkg, package_repo, tree_hash,
617
548
618
549
# update package data: compat file
619
550
@debug (" check compat section" )
620
- regpaths = [registry_path; registry_deps_paths]
621
- check_compat! (pkg, regdata, regpaths, status)
551
+ check_compat! (pkg, regdata, status)
622
552
haserror (status) && return
623
553
update_compat_file (pkg, package_path, old_versions)
624
554
end
@@ -633,7 +563,7 @@ errors or warnings that occurred.
633
563
# Arguments
634
564
635
565
* `package_repo::AbstractString`: The git repository URL for the package to be registered. If empty, keep the stored repository URL.
636
- * `pkg::Pkg.Types.Project `: the parsed (Julia)Project.toml file for the package to be registered
566
+ * `pkg::String `: the path of the project file for the package to be registered
637
567
* `tree_hash::AbstractString`: the tree hash (not commit hash) of the package revision to be registered
638
568
639
569
# Keyword Arguments
@@ -647,7 +577,7 @@ errors or warnings that occurred.
647
577
* `gitconfig::Dict=Dict()`: dictionary of configuration options for the `git` command
648
578
"""
649
579
function register (
650
- package_repo:: AbstractString , pkg:: Pkg.Types. Project , tree_hash:: AbstractString ;
580
+ package_repo:: AbstractString , pkg:: Union{String, Project} , tree_hash:: AbstractString ;
651
581
registry:: AbstractString = DEFAULT_REGISTRY_URL,
652
582
registry_fork:: AbstractString = registry,
653
583
registry_deps:: Vector{<:AbstractString} = AbstractString[],
@@ -659,6 +589,10 @@ function register(
659
589
cache:: RegistryCache = REGISTRY_CACHE,
660
590
gitconfig:: Dict = Dict ()
661
591
)
592
+ if pkg isa String
593
+ pkg = Project (pkg)
594
+ end
595
+
662
596
# get info from package registry
663
597
@debug (" get info from package registry" )
664
598
if ! isempty (package_repo)
@@ -736,44 +670,14 @@ function register(
736
670
return set_metadata! (regbr, status)
737
671
end
738
672
739
- struct RegisterParams
740
- package_repo:: String
741
- pkg:: Pkg.Types.Project
742
- tree_sha:: String
743
- registry:: String
744
- registry_fork:: String
745
- registry_deps:: Vector{<:String}
746
- subdir:: String
747
- push:: Bool
748
- gitconfig:: Dict
749
-
750
- function RegisterParams (package_repo:: AbstractString ,
751
- pkg:: Pkg.Types.Project ,
752
- tree_sha:: AbstractString ;
753
- registry:: AbstractString = DEFAULT_REGISTRY_URL,
754
- registry_fork:: AbstractString = registry,
755
- registry_deps:: Vector{<:AbstractString} = [],
756
- subdir:: AbstractString = " " ,
757
- push:: Bool = false ,
758
- gitconfig:: Dict = Dict (),)
759
- new (package_repo, pkg, tree_sha, registry, registry_fork,
760
- registry_deps, subdir, push, gitconfig,)
761
- end
762
- end
763
-
764
- register (regp:: RegisterParams ) = register (regp. package_repo, regp. pkg, regp. tree_sha;
765
- registry= regp. registry, registry_fork= regp. registry_fork,
766
- registry_deps= regp. registry_deps,
767
- subdir= regp. subdir, push= regp. push, gitconfig= regp. gitconfig,)
768
-
769
673
"""
770
674
find_registered_version(pkg, registry_path)
771
675
772
676
If the package and version specified by `pkg` exists in the registry
773
677
at `registry_path`, return its tree hash. Otherwise return the empty
774
678
string.
775
679
"""
776
- function find_registered_version (pkg:: Pkg.Types. Project ,
680
+ function find_registered_version (pkg:: Project ,
777
681
registry_path:: AbstractString )
778
682
registry_file = joinpath (registry_path, " Registry.toml" )
779
683
registry_data = parse_registry (registry_file)
0 commit comments