-
Notifications
You must be signed in to change notification settings - Fork 131
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 dev tool to build themes #379
Conversation
Also |
Thanks, this is great! I'm wondering why I would expect this to work on whatever branch (it even works with uncommitted changes, which is great!), regardless where the It worked very nicely when I tried it yesterday, but I had the feeling that it might break when the |
self.update_theme_conf(branch_ref) | ||
dest_dir = os.path.join(TEMP_BUILD_ROOT_DIR, branch_name) | ||
build_args = [TEMP_DOC_DIR, dest_dir] + self.build_args | ||
# the theme "guzzle" and "press" need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the problem with those themes?
Is this something that can be solved upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guzzle
did trigger a rebuild instead of just using the cache and press
did throw an exception.
I didn't look into why it does behave like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why guzzle
wants to re-build is because it wants to add itself to the extensions
variable.
I've removed this in the theme branch, now it should work without re-build.
This is now disabling special table formatting (and probably some other stuff) and building sitemap.xml
.
I've created a PR to fix this: guzzle/guzzle_sphinx_theme#46.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created schettino72/sphinx_press_theme#36 for the press
problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just removed the press-theme
branch. Now no more special cases should be necessary.
…ache and reduce build time considerably, props go to spatialaudio#376 (comment)
e115f83
to
04c8603
Compare
The tool assumes that the theme branches only differ from master, in the theme relevant lines of
The significance of master is, that it is assumed as base branch for the theme branches.
Note that the diffing only concerns the branches as they are on github, not the local copy. So as long as there are no changes to
Due to the changes in master at the end of the generated 'sphinx_copybutton', which causes the syntax error. |
I don't think that's good.
I don't really want to run this after each commit to Typically, I only run this script after each release. I think a better assumption (if necessary) would be that each theme branch only contains one diverging commit. |
from, theme branch differs to master, to theme branch has only one commit differing to its base
Ok, my assumption was that you run it each time The 'theme branch has only one commit' assumption, sounds solid to me. IMHO an assumption is needed to get the diff, since actions like merging to the current |
Thanks for the update! This works really well, and it is surprisingly fast! However, I have the feeling that it is much more complicated than necessary. The script has 358 lines, which seems a lot to me. That's like 20% of I didn't completely absorb all the details (yet), but there are already a few things that I'm wondering about:
I would think that something like this is simpler:
Wouldn't this be simpler? I'm not sure if Sphinx would re-execute everything if the |
I played around a bit with But now I understand I think this should work:
|
Since this is my first time using I also made As for Concerning the size of the tool:If you remove all docstrings, it is only 236 lines, with 55 lines only for the Concerning mentioning specific files in the code :
Concerning manual copying:IMHO, this is a more straightforward approach, than stashing, unstashing, resetting hard and possibly messing up git on keyboard interrupt. If I understood it right, the |
Thanks for the update. It's already a bit simpler, but I think we can go much further!
OK, that's good. But we could even make this "out of scope" for the script. Isn't it the typical case that a collaborator has an "upstream" remote already set up? I don't think we need a script to make the necessary setup, I think it would be better to simply add the required Git commands to the developer docs.
Are you sure? I tried this: repo.git.branch('my-branch')
repo.git.worktree('add', 'my-worktree', 'my-branch') ... and it seems to work.
That's still a lot. I still didn't read the whole thing, but I guess it would take hours to fully understand it. I would prefer something that only takes a few minutes to understand (assuming good knowledge of Git).
But probably that feature isn't needed at all? It sure is a fun exercise to create a script for that, but I'm not sure if I want to maintain such a script. What about just adding the list of packages to the docs and being done with it? Sure, then we have to change the docs whenever we add a theme branch, but that's probably less maintenance burden.
I agree. What about removing this feature for now and if you really think it would be great to have it, adding it in a separate PR at a later time? In general, I think it's a good idea to start small and add non-essential features later.
I don't really see a "problem" either. All necessary information should be in the theme commits, including which files have to be modified. I haven't yet read all the code (even less understood it), so I don't really know if it's good to have this hard-coded or not.
I'm not talking about stashing and unstashing. But I chose this exact command for exactly this reason.
I don't believe that any of the commands I mentioned above can be messed up. The only thing that can be messed up is the working branch. Only one branch is ever created ( But even that can probably be avoided by always working with a "detached head". This command would not need a named branch: repo.git.worktree('add', 'my-other-worktree', '--detach') (I don't know if that's the proper way to add the
True, the possibility of messing up And if the worktree is broken, you can remove it with |
Guess I didn't fully understand the whole
I personally only set up "upstream" for a forked repo, when I contribute a second time and need to update the main branch, the PR is based on.
Good to know, when I searched GitPython API ref, I mostly found things concerning exceptions. So I'm not sure if this is an intended feature or a side effect of how they implemented the git functionality?
Since you need the theme dependency in
IMHO it would be a code smell if it was a general purpose tool, with none configureable parameters, but this tool is already very specific. Only considering branches that end in I should read up on how to use P.S.: I opened an issue for the broken link from the |
TBH, I've never used I've just played around a bit in the context of this PR and it is really nice! You should manually try the commands I mentioned in #379 (comment), this should clear up things. And as an improvement, you can also try it in "detached" mode, without ever creating a new branch.
OK, that sounds reasonable. Either way, at some point you will have an "upstream" remote, but the name might not be the same for everyone.
I agree.
That's right. I still think we can get a meaningful behavior with very few assumptions.
This way, if I would run the script right now, I would get an error because It would be the responsibility of the user (at least for now) to update the remote whenever needed.
I think that's the wrong question. I can use: import git
g = git.Git()
g.nonsense('whatever') ... and this will simply be converted to a call to the
So it looks like you can use anything you want as long as But GitPython definitely knows something about worktrees, because the word appears in their code.
Nothing is maintenance free. The mere existence of the code makes it harder to understand the whole script. We can talk about adding such a feature later, but I wouldn't add it in the beginning.
Yes, sure. A code smell doesn't necessarily mean we should change it, just that we should think about it. I think the Removing hard-coded file names is a good thing, as long as it doesn't make anything else worse. Removing the
Sure, some assumptions are needed if we want to keep it simple.
Cool. I've also seen the test failure and have created #383, which changes the broken link to https://docs.readthedocs.io/en/latest/config-file/. |
I had another idea how we could reduce the number of assumptions regarding remotes. What about adding this condition?
This would not require a decision on a remote name like This way we wouldn't even need the |
I did play around a bit with
If I didn't miss something, you can't have the same branch checked out multiple times, which means that you would need to create a temporary branch. $ git checkout my-working-branch
fatal: 'my-working-branch' is already checked out at 'my-worktree' If the user changes the branch, the branch of the worktree would need to be changed (or a temp one newly created) too, which adds an extra checks.
I had to first run
The big problem I see is, how merge conflicts are handled when cherrypicking. To ensure that the theme builds and doesn't hang at a conflict, we could use: $ git cherry-pick <theme commit hash> --strategy=recursive -X theirs But that could potentially overwrite important changes. Is there something like an append merge strategy? To handle the 'one commit assumption' we could use $ git cherry -v upstream/master upstream/rtd-theme I don't think that this is the proper usecase for And sure we could add a |
I didn't know that you can't check out the same branch on different workdirs, that's good to know! But I was assuming anyway that the script uses one branch (
Of course, the user would not be allowed to use this branch in any way. But you are right, that's an ugly situation. That's why I was suggesting to use "detached head" instead. If the script only uses "detached head" in its worktree, there are no limits to what the user can do in the main worktree. I don't think a temporary branch has ever to be created (but of course I didn't fully implement anything, so I don't really know for sure).
This would of course be bad, because it changes the state of the repo without the user's consent. It worked for me for untracked changes of existing files. According to the manpage, there is the Probably we have to use But this didn't work either when I tried it just now. I don't know what we can do here. Alternatively, we could just ignore the problem. At some point, we'll have to add new files to the index anyway, so I think this might not even be a big deal?
I think we should raise an error at a conflict. I guess it would be useful to still continue with the remaining branches, but in the end the script should fail and print an error message containing the names of the broken branches.
I don't know.
I didn't know the But we already know the relevant commit by name (it's the name of the theme branch), so it doesn't sound like we need to "find" any commits. What would
I think elegance is subjective. But I don't insist at all on using
OK, but probably we should postpone this feature in the interest of simplicity. |
Yap, just a quick and dirty
So as I understand it, $ git cherry -v upstream/master upstream/rtd-theme
+ 9081d20775cbe4a08c78f0e26d9fa87fd983b566 DOC: Switch to readthedocs theme
That is definitely true, especially since we have a great example of it right here 😛. At the end of the day, the job of this tool is to allow contributers, to quickly build all example themes and check if they look fine. And IMHO: What do you think about copying the whole repo and using the
Since the conflict (most likely) arises from 'which line was changed' and not from an 'actual problem' (i.e. building the docs would break), I don't think this should raise an error. As a user, my first thought on such an error would be: |
OK, I see. I'm fine with the one-commit-assumption, since it seems to reduce complexity quite a bit. If we want to give up this assumption, we can do it at a later point.
Yes, the line above is indeed simple.
That's a good reason to learn more about Git, then! I think the steps that I've suggested in #379 (comment) are also quite simple. And I have the feeling that they can be implemented with less code. But I didn't do it, so I don't really know.
Well it only depends on how much the code can be simplified by using more powerful Git commands. If it's really just a copy, I'm fine with it, but your current proposal does much more than a simple copy, right?
I think that's a valid concern. I guess whether that's worth it also depends on how much simplification it brings. And how much risk there is of messing it up.
I don't see a problem with that. On the contrary, I think it's better to explicitly require them to have a certain remote instead of silently downloading it behind their backs. And it is only the matter of copying one command from the docs (or from the error message) and running it.
If the resulting code is simple enough, I'm totally OK with it. But to me it sounds quite complicated to copy the repo (without the This is exactly what
I would rather raise an error than silently providing a probably broken result.
If the theme branch doesn't apply cleanly that's an error that should be fixed. And I'd prefer if the error surfaces earlier rather than later. But in reality, this will happen very rarely. |
I thought that instead of always talking hypothetically, I'd quickly try if the "git worktree" approach even works. |
I wanted to compare my experiment from #387 with your script, but it doesn't seem to work anymore! I've made some changes to the theme branches in the meantime, but I don't think anything too wild. The error is in |
Hmmmm it works fine for me. Maybe try |
Sure.
My Git checkout is completely clean and I have no local changes. If I comment out the requirements thingy, I get a very similar error:
|
Did you update your upstream remote? |
Very strange. Does the git command itself work? $ git diff-tree --output-indicator-new= --unified=0 aad12aa16c379300ba2cc99a9efcb432a1aaf2e6 00ac96a45f4174cde5424f3e2172240ec0f 7fab7 -r --abbrev=40 --full-index -M -p --no-color -- doc/conf.py
diff --git a/doc/conf.py b/doc/conf.py
index 33fad3fdb94c4fe5561e985108e886af8710c58e..e2565fd6b4c19613e8be1580c6f4533e1c89277f 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -104,0 +105,6 @@ html_title = project + ' version ' + release
html_theme = 'agogo'
html_theme_options = {
'navigation_with_keys': True,
#'rightsidebar': False,
#'sidebarwidth': 300,
} |
Ok I got the reason (tested on ubuntu 18.4). |
I'm using Git 2.25.0. The problem seems to be that something is missing after My error message is:
|
The intention was to strip the '+' char for added content, so it can just be appended. Anyway looking at the availability for I'm using Git 2.24.1
|
Thanks for the fix! I just compared this PR with #387 with regards to what happens if only a small change is made (or no change at all) and the script is executed again. Both detect the change to the "environment" correctly and only re-parse the modified source files (avoiding notebook execution if not necessary). However, this PR is much faster because it also avoids re-building the HTML files unnecessarily. It only rebuilds HTML files where the source files have changed. Any idea why this could be the case? |
After a quick test, looks like this is due to the change |
Thanks for checking this out! Sphinx definitely uses The only files that are typically updated are So it must be something else? If I use |
Never mind, I found the problem! There was still one option that depended on the Git hash: I just fixed this (e7cfb70) and now everything is fine. There is no unnecessary re-building of HTML files anymore! |
I still owe you a few answers (from #379 (comment)):
I think it would be best to rename Then we don't need a
Sure. We could e.g. have And next to that, we could have the auto-generated |
@s-weigand Are you planning to continue working on this? In the meantime, I have added a few more features to #387. |
Sorry for the delayed answer, when I got more time, I will give it another try. |
I have merged #387, which obsoletes this PR, but which wouldn't have been possible without the work in this PR. Thanks @s-weigand! |
As discussed in #376 I added a small commandline tool to more conveniently build themes.
How it works:
[email protected]:spatialaudio/nbsphinx.git
as remote. This prevents messing with the actual gitdev_utils/requirements_themes.txt
containing all requirements to build all themes. This is generated from the diff indoc/requirements.txt
from the different theme branches and master remote.doc/
,README.rst
,CONTRIBUTING.rst
, to a temp folder once.doc/conf.py
to the one in the temp folder (in contrast to merge, this prevents possible merge conflicts) .dev_util/_build
with with the branch name.Other features:
dev_utils/requirements_themes.txt
sphinx-build -a
)Open Questions:
doc/_build
, thandev_util/_build
?ImportError
and tells the user to runpip install GitPython
. In my projects I prefer to have arequirements_dev.txt
with all dev dependencies in it (doc/requirements.txt
can be referenced so no duplication). Would that be an option for you as well? This would also open the option to automatically test if new releases of dependencies break the code, using pyup.