Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to change root path during build. #1013

Closed
kescobo opened this issue May 7, 2019 · 12 comments
Closed

Add option to change root path during build. #1013

kescobo opened this issue May 7, 2019 · 12 comments
Milestone

Comments

@kescobo
Copy link
Contributor

kescobo commented May 7, 2019

Assuming a standard project layout,

MyPackage
    ├── src
    │   ├── MyPackage.jl
    │   └── functions.jl
    ├── docs
    │   ├── makedocs.jl
    │   └── src
    │       ├── 01-foo.md
    │       ├── 02-bar.md
    │       └── index.md
    ├── test
    │   └── runtests.jl
    ├── Manifest.toml
    ├── Project.toml
    └── README.md

I'd like to be able to set an option such that makedocs() will execute code in MyPackage/docs/src/01-foo.md as if the current working directory is MyPackage/.

I tried

makedocs(
    ...
    root=joinpath(dirname(pathof(MyPackage)), ".."),
    source="docs/src",
    build="build")

thinking that the root option was what I wanted, but pwd() in a code block returns MyProject/build/. I also tried setting the build="."... oops #1012

The reason for this desire is that I'm using the markdown files as interactive data analysis notebooks with Juno, and Juno sets the current working directory as the package root. I'd like to use Documenter to render html versions of the analysis notebooks, but would prefer not to go through and change all of the paths to the input data and output folders.

Is this possible, even with some sort of hacky solution? I'm happy to work on a PR if I this would be useful for others, and if I can get a bit of direction about where to start.

@mortenpi
Copy link
Member

mortenpi commented May 8, 2019

Hmm. How are you building the notebooks in Juno such that you're getting a different working directory? Are you just doing include("docs/makedocs.jl") or something else?

Would an at-setup block in each .md file where you cd to the correct directory work?

@kescobo
Copy link
Contributor Author

kescobo commented May 8, 2019

How are you building the notebooks in Juno such that you're getting a different working directory? Are you just doing include("docs/makedocs.jl") or something else?

Yes, exactly that. Happy to have a different procedure though - this is going to be a manual, not an automated process.

Would an at-setup block in each .md file where you cd to the correct directory work?

Yeah, I thought about this. It's a little messy, but if it works... I was thinking of something simple like

```@example 1
cd(joinpath(dirname(pathof(MyPackage)), "..")) # hide
```

In the first code block of each notebook. Is there a better option?

@kescobo
Copy link
Contributor Author

kescobo commented May 8, 2019

Actually, that doesn't seem to work - during the build, MyPackage is not defined. Do I have to add it to a doc Project.toml or something?

@fredrikekre
Copy link
Member

Yes, but most importantly you need to using MyPackage before using it.

@kescobo
Copy link
Contributor Author

kescobo commented May 8, 2019

In fact - that doesn't actually work. MyPackage is not defined during the build. I tried adding it to the [deps] in a Project.toml file inside docs/, but that did not help (guessing that only matters for travis??).

But I also tried something a bit more cloodgy and it didn't work either. I can't seem to get out of the build directory no mater what:

```@example 1
cd("../../../")# hide
pwd()
```

```@example 1
cd("..")
pwd()
```

Screen Shot 2019-05-08 at 12 49 46 PM

@kescobo
Copy link
Contributor Author

kescobo commented May 8, 2019

@fredrikekre Sorry - missed your comment because my other comment is staying at the bottom of the thread for some reason...

Screen Shot 2019-05-08 at 12 51 04 PM

@kescobo
Copy link
Contributor Author

kescobo commented May 8, 2019

@fredrikekre Your suggestion allows the code to evaluate, but still doesn't let me out of the build directory:

```@example
using ECHOAnalysis # hide
cd(joinpath(dirname(pathof(ECHOAnalysis)), "..")) # hide
pwd()
```

Screen Shot 2019-05-08 at 12 56 53 PM

@fredrikekre
Copy link
Member

The problem is that we cd to the build page for every evaluation:

cd(dirname(page.build)) do

You can probably workaround it with

cd(...) do
    # stuff
end

@kescobo
Copy link
Contributor Author

kescobo commented May 9, 2019

That would have to wrap every code block right? Might be too heavy-handed for me. Would there be any interest in a PR that allows this to be user specified? Eg something like

makdocs(
    ...
    eval_dir=:build # or user-specified path
)

?

@mortenpi
Copy link
Member

Yes, I think we could have an option like that. Bikeshed: maybe call it working_directory or something along those lines?

One thing to think about though: currently, if I am not mistaken, we cd into a subdirectory of build/ (e.g. docs/src/foo/bar.md cds into docs/build/foo/bar/). Would have to think how to handle that. I guess though, if you are overriding the working directory, you probably always want to be there.

Another idea would be to have a per-file at-meta block option for this?

@kescobo
Copy link
Contributor Author

kescobo commented May 15, 2019

Bikeshed: maybe call it working_directory or something along those lines?

Agree - that's much clearer :-)

Another idea would be to have a per-file at-meta block option for this?

I like this idea. Would this be instead of or in addition to an argument in makedocs()? Presumably, if both, the meta block would override what's in makedocs() (or maybe have the path defined in a metablock be relative to whatever is specified in working_directory)?

I can dig around in the source code to get started on a PR, but is there a good place to start to understand the processing pipeline? I read through the contributing page, and my plan was to start here at the source for Document and start looking around, but if you have any suggestions to make me more efficient, I'd be happy to hear them,.

@mortenpi
Copy link
Member

#1025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants