@@ -103,7 +103,7 @@ function build_local_docs(packagespec, buildpath, uri, pkgroot = nothing; gitdir
103103 pkgfile = Base. find_package (pkgname)
104104 pkgroot = normpath (joinpath (pkgfile, " .." , " .." ))
105105 end
106- mod = try_use_package (packagespec)
106+ could_use_pkg = try_use_package (packagespec, envdir )
107107
108108 # actual Documenter docs
109109 try
@@ -119,7 +119,7 @@ function build_local_docs(packagespec, buildpath, uri, pkgroot = nothing; gitdir
119119 " doctype" => gitdirdocs ? " git-repo" : " documenter" ,
120120 " documenter_errored" => documenter_errored,
121121 " installable" => true ,
122- " using_failed" => mod == nothing ,
122+ " using_failed" => ! could_use_pkg ,
123123 " success" => true
124124 )
125125 else
@@ -139,22 +139,22 @@ function build_local_docs(packagespec, buildpath, uri, pkgroot = nothing; gitdir
139139
140140 # fallback docs (readme & docstrings)
141141 return mktempdir () do docsdir
142- output = build_readme_docs (pkgname, pkgroot, docsdir, mod, src_prefix, href_prefix)
142+ output = build_readme_docs (pkgname, pkgroot, docsdir, src_prefix, href_prefix, could_use_pkg )
143143 if output != = nothing
144144 cp (output, buildpath, force = true )
145145 return Dict (
146146 " doctype" => " fallback_autodocs" ,
147147 " documenter_errored" => documenter_errored,
148148 " installable" => true ,
149- " using_failed" => mod == nothing ,
149+ " using_failed" => ! could_use_pkg ,
150150 " success" => true
151151 )
152152 end
153153 return Dict (
154154 " doctype" => " fallback_autodocs" ,
155155 " documenter_errored" => documenter_errored,
156156 " installable" => true ,
157- " using_failed" => mod == nothing ,
157+ " using_failed" => ! could_use_pkg ,
158158 " success" => false
159159 )
160160 end
@@ -206,11 +206,9 @@ function build_documenter(packagespec, docdir)
206206 _, builddir = fix_makefile (makefile)
207207 pkgimagesopt = VERSION >= v " 1.9" ? " --pkgimages=no" : " "
208208 cmd = ```
209- $(first (Base . julia_cmd () ))
209+ $(julia ( ))
210210 --project="$(docdir) "
211- --compiled-modules=no
212211 $(isempty (pkgimagesopt) ? [] : pkgimagesopt)
213- -O0
214212 $(rundcocumenter)
215213 $(pkgdir)
216214 $(makefile)
@@ -231,51 +229,84 @@ function build_documenter(packagespec, docdir)
231229 end
232230end
233231
234- function build_readme_docs (pkgname, pkgroot, docsdir, mod, src_prefix, href_prefix)
232+ function build_readme_docs (pkgname, pkgroot, docsdir, src_prefix, href_prefix, could_use_pkg )
235233 @info (" Generating readme-only fallback docs." )
236234
237235 if pkgroot === nothing || ! ispath (pkgroot)
238236 @error (" Julia could not find the package directory. Aborting." )
239237 return
240238 end
241239
242- pkgloads = mod != = nothing
243-
244240 readme = find_readme (pkgroot)
245241 doc_src = joinpath (docsdir, " src" )
246242 mkpath (doc_src)
247243 index = joinpath (doc_src, " index.md" )
248244
249245 render_html (readme, index, src_prefix, href_prefix; documenter = true )
250246
247+ pages = [" Readme" => " index.md" ]
248+
249+ if could_use_pkg
250+ @info (" Deploying `autodocs`." )
251+ add_autodocs (doc_src, Symbol (pkgname))
252+ push! (pages, " Docstrings" => " autodocs.md" )
253+ end
254+
251255 if ! isfile (index)
252256 open (index, " w" ) do io
253257 println (io, """
254258 # $pkgname
255259 """ )
260+
261+ if ! could_use_pkg
262+ println (io, """
263+ > No documentation or readme found for this package.
264+ """ )
265+ end
256266 end
257267 end
258268
259- pages = [" Readme" => " index.md" ]
260- modules = :(Module[Module ()])
269+ makejl_str = """
270+ using Pkg
271+ Pkg.add(name="Documenter", version="1")
272+ Pkg.develop(path="$(pkgroot) ")
261273
262- if pkgloads
263- @info (" Deploying `autodocs`." )
264- add_autodocs (doc_src, mod)
265- push! (pages, " Docstrings" => " autodocs.md" )
266- modules = :(Module[$ mod])
267- end
268-
269- @eval Module () begin
270- const Documenter = $ Documenter
271- using . Documenter
272- makedocs (
273- format = Documenter. HTML (),
274- sitename = " $($ pkgname) .jl" ,
275- modules = $ (modules),
276- root = $ (docsdir),
277- pages = $ (pages)
278- )
274+ using Documenter
275+ using $(pkgname)
276+
277+ makedocs(
278+ format = Documenter.HTML(),
279+ sitename = "$(pkgname) .jl",
280+ modules = [$(pkgname) ],
281+ root = "$(docsdir) ",
282+ pages = $(pages) ,
283+ remotes = nothing,
284+ repo = "",
285+ doctest = false
286+ )
287+ """
288+
289+ makejl_path = joinpath (docsdir, " make.jl" )
290+
291+ open (makejl_path, " w" ) do io
292+ println (io, makejl_str)
293+ end
294+
295+ cmd = ```
296+ $(julia ())
297+ --project="$(docsdir) "
298+ $(makejl_path)
299+ ```
300+
301+ succeeded = try
302+ success (pipeline (addenv (cmd, " JULIA_LOAD_PATH" => nothing ); stdout = stdout , stderr = stderr ))
303+ catch err
304+ @error " autodocs $pkgname issue" exception= (err, catch_backtrace ())
305+ false
306+ end
307+
308+ if ! succeeded
309+ @error (" Failed to generate readme autodocs for $pkgname " )
279310 end
280311
281312 build_dir = joinpath (docsdir, " build" )
@@ -308,11 +339,10 @@ function find_readme(pkgroot)
308339end
309340
310341function add_autodocs (docsdir, mod)
311- module_list = join ((string (m) for m in submodules (mod)), " , " )
312342 open (joinpath (docsdir, " autodocs.md" ), " w" ) do io
313343 println (io, """
314344 ```@autodocs
315- Modules = [$module_list ]
345+ Modules = [$mod ]
316346 ```
317347 """ )
318348 end
0 commit comments