Skip to content

Commit ae1d520

Browse files
test2
1 parent f9d6578 commit ae1d520

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

docs/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = "docs"
2+
uuid = "6854bdac-4683-567a-be4f-b22094e82ce7"
3+
4+
[deps]
5+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
6+
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"

docs/gen_project.jl

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import Pkg
2+
import Pkg.Types: VersionSpec, VersionRange, VersionBound, semver_spec
3+
import Base: thismajor, thisminor, thispatch, nextmajor, nextminor, nextpatch
4+
5+
const STDLIBS = [
6+
"Base64"
7+
"CRC32c"
8+
"Dates"
9+
"DelimitedFiles"
10+
"Distributed"
11+
"FileWatching"
12+
"Future"
13+
"InteractiveUtils"
14+
"Libdl"
15+
"LibGit2"
16+
"LinearAlgebra"
17+
"Logging"
18+
"Markdown"
19+
"Mmap"
20+
"Pkg"
21+
"Printf"
22+
"Profile"
23+
"Random"
24+
"REPL"
25+
"Serialization"
26+
"SHA"
27+
"SharedArrays"
28+
"Sockets"
29+
"SparseArrays"
30+
"Statistics"
31+
"SuiteSparse"
32+
"Test"
33+
"Unicode"
34+
"UUIDs"
35+
]
36+
37+
function uuid(name::AbstractString)
38+
if name == "Pkg"
39+
return "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
40+
elseif name == "Statistics"
41+
return "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
42+
else
43+
string(Pkg.METADATA_compatible_uuid(String(name)))
44+
end
45+
end
46+
47+
function uses(repo::AbstractString, lib::AbstractString)
48+
pattern = string(raw"\b(import|using)\s+((\w|\.)+\s*,\s*)*", lib, raw"\b")
49+
success(`git -C $repo grep -Eq $pattern -- '*.jl'`)
50+
end
51+
52+
function semver(intervals)
53+
spec = String[]
54+
for ival in intervals
55+
if ival.upper == v""
56+
push!(spec, "$(thispatch(ival.lower))")
57+
else
58+
lo, hi = ival.lower, ival.upper
59+
if lo.major < hi.major
60+
push!(spec, "^$(lo.major).$(lo.minor).$(lo.patch)")
61+
for major = lo.major+1:hi.major-1
62+
push!(spec, "~$major")
63+
end
64+
for minor = 0:hi.minor-1
65+
push!(spec, "~$(hi.major).$minor")
66+
end
67+
for patch = 0:hi.patch-1
68+
push!(spec, "=$(hi.major).$(hi.minor).$patch")
69+
end
70+
elseif lo.minor < hi.minor
71+
push!(spec, "~$(lo.major).$(lo.minor).$(lo.patch)")
72+
for minor = lo.minor+1:hi.minor-1
73+
push!(spec, "~$(hi.major).$minor")
74+
end
75+
for patch = 0:hi.patch-1
76+
push!(spec, "=$(hi.major).$(hi.minor).$patch")
77+
end
78+
else
79+
for patch = lo.patch:hi.patch-1
80+
push!(spec, "=$(hi.major).$(hi.minor).$patch")
81+
end
82+
end
83+
end
84+
end
85+
return join(spec, ", ")
86+
end
87+
88+
if !isempty(ARGS) && ARGS[1] == "-f"
89+
const force = true
90+
popfirst!(ARGS)
91+
else
92+
const force = false
93+
end
94+
isempty(ARGS) && (push!(ARGS, pwd()))
95+
96+
for arg in ARGS
97+
dir = abspath(expanduser(arg))
98+
isdir(dir) ||
99+
error("$arg does not appear to be a package (not a directory)")
100+
101+
name = basename(dir)
102+
if isempty(name)
103+
dir = dirname(dir)
104+
name = basename(dir)
105+
end
106+
endswith(name, ".jl") && (name = chop(name, tail=3))
107+
108+
project_file = joinpath(dir, "Project.toml")
109+
!force && isfile(project_file) &&
110+
error("$arg already has a project file")
111+
112+
require_file = joinpath(dir, "REQUIRE")
113+
isfile(require_file) ||
114+
error("$arg does not appear to be a package (no REQUIRE file)")
115+
116+
project = Dict(
117+
"name" => name,
118+
"uuid" => uuid(name),
119+
"deps" => Dict{String,String}(),
120+
"compat" => Dict{String,String}(),
121+
"extras" => Dict{String,String}(),
122+
)
123+
124+
test_require_file = joinpath(dir, "test", "REQUIRE")
125+
126+
for (file, section) in ((require_file, "deps"),
127+
(test_require_file, "extras"))
128+
isfile(file) || continue
129+
reqs = Pkg.Pkg2.Reqs.read(file)
130+
for req in reqs
131+
req isa Pkg.Pkg2.Reqs.Requirement || continue
132+
dep = String(req.package)
133+
if dep != "julia"
134+
project[section][dep] = uuid(dep)
135+
end
136+
if req.versions != Pkg.Pkg2.Pkg2Types.VersionSet()
137+
project["compat"][dep] = semver(req.versions.intervals)
138+
end
139+
end
140+
end
141+
142+
for (srcdir, section) in (("src" => "deps"), ("test", "extras"))
143+
for stdlib in STDLIBS
144+
if uses(joinpath(dir, srcdir), stdlib)
145+
project[section][stdlib] = uuid(stdlib)
146+
end
147+
end
148+
end
149+
150+
if !isempty(project["extras"])
151+
project["targets"] = Dict("test" => collect(keys(project["extras"])))
152+
haskey(project["deps"], "Test") && delete!(project["deps"], "Test")
153+
end
154+
155+
println(stderr, "Generating project file for $name: $project_file")
156+
open(project_file, "w") do io
157+
Pkg.TOML.print(io, project, sorted=true)
158+
end
159+
project = Pkg.Types.read_project(project_file)
160+
Pkg.Types.write_project(project, project_file)
161+
end

docs/mkdocs.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
site_name: PACKAGE_NAME.jl
2+
repo_url: https://github.com/USER_NAME/PACKAGE_NAME.jl
3+
site_description: Description...
4+
site_author: USER_NAME
5+
6+
theme: readthedocs
7+
8+
extra_css:
9+
- assets/Documenter.css
10+
11+
extra_javascript:
12+
- https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
13+
- assets/mathjaxhelper.js
14+
15+
markdown_extensions:
16+
- extra
17+
- tables
18+
- fenced_code
19+
- mdx_math
20+
21+
docs_dir: 'build'
22+
23+
pages:
24+
- Home: index.md

0 commit comments

Comments
 (0)