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

Build: use environment variable $READTHEDOCS_OUTPUT to define output directory #9913

Merged
merged 13 commits into from
Feb 13, 2023

Conversation

humitos
Copy link
Member

@humitos humitos commented Jan 18, 2023

READTHEDOCS_OUTPUT points to the path where the user's repository was cloned plus _readthedocs/ subdirectory. This way we can make the command nicer:

python -m sphinx -T -E -j auto -b singlehtml -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/html

Also, we gives our users a clear contract to where to find those files, even if we change the path of the underlying variable in the future.

This PR is a continuation of #9888. I split it into a different PR because I'm having problems to make the Sphinx command resolving the variable into its real value. The output folders are being saved into $READTHEDOCS_OUTPUT being that string the name of the folder 🤦🏼 . We need to research/debug a little more how to make this work properly.

@ericholscher
Copy link
Member

I played around with this a little bit, and it looks like everything is set properly on docker... just need to figure out how to make it expand it. 🙃

Base automatically changed from humitos/standard-output-directory to main January 19, 2023 10:26
@humitos
Copy link
Member Author

humitos commented Jan 19, 2023

Meh, because this PR was based in another PR that now is "Squashed & Merged" we have a bunch of individual commits in this one. We should rebase it to make it consistent now 😞

humitos and others added 3 commits January 19, 2023 16:51
`READTHEDOCS_OUTPUT` points to the path where the user's repository was clonned
plus `_readthedocs/` subdirectory. This way we can make the command nicer:

```
python -m sphinx -T -E -j auto -b singlehtml -d _build/doctrees -D language=en .
$READTHEDOCS_OUTPUT/html
```

Also, we gives our users a clear contract to where to find those files, even if
we change the path of the underlying variable in the future.
@humitos humitos force-pushed the humitos/output-variable branch from 2246320 to 382d332 Compare January 19, 2023 15:52
@humitos
Copy link
Member Author

humitos commented Jan 19, 2023

I merge main into this branch because it was the easiest way to handle with merge conflicts. Then I rebased this branch to remove all the "duplicated commits" and only leave the ones done in this particular PR. I think everything is fine and cleaner now, I hope.

Add a simple hack to avoid escaping this internal variable since we need it to
determine the output path.
@humitos
Copy link
Member Author

humitos commented Jan 31, 2023

I found why the variable was not working properly and I fixed it in 300d303

Screenshot_2023-01-31_12-03-57

We need to discuss how to do it correctly to avoid that hack that I put there temporary to show the concept.

@ericholscher
Copy link
Member

I found why the variable was not working properly and I fixed it in 300d303

Heh -- that is definitely a hack! Thanks for figuring that out, I really couldn't understand what was happening, but that makes sense.

Not 100% sure the best option here. I actually do think there's some useful cases for using env vars in the build commands. I wish we had a comment explaining why we added the escaping. I'm guessing just to be extra careful when allowing users to start modifying build commands.

@humitos
Copy link
Member Author

humitos commented Feb 1, 2023

I think that "build.jobs" and "build.commands" go over a different workflow because they support environment variables.

I think we added this to protect ourselves, maybe? I don't remember. However, we can simply use "escape=False" argument for these 2 commands

@humitos
Copy link
Member Author

humitos commented Feb 1, 2023

I think we added this to protect ourselves, maybe? I don't remember. However, we can simply use "escape=False" argument for these 2 commands

Yeap, we are using escape=False for build.jobs and build.commands:

for command in commands:
environment.run(*command.split(), escape_command=False, cwd=cwd)

@humitos humitos changed the title Build: use environment variable to define output directory Build: use environment variable $READTHEDOCS_OUTPUT to define output directory Feb 1, 2023
@humitos
Copy link
Member Author

humitos commented Feb 1, 2023

I found why we need the escape_command=True in some of our commands. It's because we are using things like pip install setuptools<58. That < breaks the command otherwise.

I noted that I want to avoid escaping another environment variable from ourselves (in #9971), so I may use this hack for now 😄

It could contain some private data.
There are some commands that are executed from inside the container where
`$READTHEDOCS_OUTPUT` variable is defined and we can use it.

However, there are other commands executed from the host where that variable is
not defined and/or it cannot be used (e.g. as a `cwd=` argument for Docker run
command).
@humitos
Copy link
Member Author

humitos commented Feb 7, 2023

@ericholscher this is ready for another round of review 👍🏼

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels really close. I mainly just have a question on the output dir variables.

readthedocs/doc_builder/backends/sphinx.py Outdated Show resolved Hide resolved
readthedocs/doc_builder/backends/sphinx.py Outdated Show resolved Hide resolved
readthedocs/doc_builder/director.py Show resolved Hide resolved
Use `absolute_container_output_dir` and `absolute_host_output_dir` to
differentiate them in a clear way.
@humitos humitos requested a review from ericholscher February 13, 2023 17:21
@humitos
Copy link
Member Author

humitos commented Feb 13, 2023

@ericholscher please, take a final look and let me know if this is ready to merge and deploy tomorrow 👍🏼

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

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

Successfully merging this pull request may close these issues.

2 participants