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 sphinx-tabs + use it for OS-specific "py[thon] -m pip" #8589

Merged
merged 17 commits into from
Sep 24, 2020
Merged

Add sphinx-tabs + use it for OS-specific "py[thon] -m pip" #8589

merged 17 commits into from
Sep 24, 2020

Conversation

shireenrao
Copy link
Contributor

@shireenrao shireenrao commented Jul 16, 2020

This PR is to resolve #7311. I will change a few pages at a time and submit them to this PR.

(Edit by @uranusjr so a merge would auto-close to issue.)



On Windows [4]_::
On Windows, Linux or macOS::
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this doesn't categorize anything (and implies that on other OSes the method would be different), I suggest replacing this by a filler, e.g. in a shell or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to "In a shell". Thank you.

Copy link
Member

Choose a reason for hiding this comment

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

Do we anywhere make the point that you don't always invoke Python using the python command? I feel as though we should clarify this somewhere if we're going to make python -m pip be the canonical way we say "run pip"...

(This is arguably off-topic for this PR, and honestly, arguably not even pip's problem to address, but I feel that without some such clarification, this change is attacking a symptom, rather than the cause, of the problem people have invoking pip).

Copy link
Contributor Author

@shireenrao shireenrao Jul 16, 2020

Choose a reason for hiding this comment

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

Adding some context on why we should use python -m pip should help. Should I create a new page or add it to an existing page? We can reference Brett Cannon's article https://snarky.ca/why-you-should-use-python-m-pip/ there.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I wasn't clear. I'm fine with the -m pip bit. The problem is that on Windows, python probably isn't on PATH, you should use py. On Unix, you should often use python3 rather than python. Unless you're in a virtual environment. Etc.

Using -m pip means that you don't need to think about how the pip command relates to whatever way you run Python. But it leaves you still needing to know how to invoke Python. We're using python as a shortcut for "whatever command you use to run Python" and I don't see anything explaining that (specifically "we don't necessarily mean you should type python literally")...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's also a need to mention that on Windows Python version is specified via py -<major>.<minor> instead of python<major>.<minor>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pfmoore - Please let me know how to proceed? Does this change need further discussion before I proceed to making more changes?

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to know what other @pypa/pip-committers think.

Copy link
Member

Choose a reason for hiding this comment

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

We can have a box on top of each page to tell the user they should use pythonX.Y or py -X.Y depending on the platform. But I don’t know how is best to annotate each code block to make it obvious to the user they should not copy-paste the command verbatim and must read the block at the top.

@pradyunsg
Copy link
Member

Bah, I'm not super keen on this.

I really think what we need is better capabilities in our documentation, to provide more platform specific instructions in our documentation overall without looking ugly/tacked-on (see https://squidfunk.github.io/mkdocs-material/getting-started/#with-docker-recommended for a good example).

@shireenrao
Copy link
Contributor Author

@pradyunsg - that will be really cool!!

@shireenrao
Copy link
Contributor Author

Looking around I found sphinx-tabs. This might be helpful to add to the documentation.

@pradyunsg
Copy link
Member

Looking around I found sphinx-tabs. This might be helpful to add to the documentation.

Yeap -- that's the ideal thing for us to be using. I don't like the out-of-the-box styling of it TBH, so I'm gonna defer to others on the how of this. :)

@pfmoore
Copy link
Member

pfmoore commented Jul 17, 2020

Agreed sphinx-tabs looks like a good way to go (if we could add some browser detection to default to the tab for the reader's OS, then even better!). And I also agree that the default style isn't ideal. But I'm no css expert so I'm not going to be the one to change it 🤷

Also, on the importance of giving a correct command for the user's situation, we're seeing more and more reports of "python setup.py did nothing" on packaging-problems, which are caused by the default "python" command on Windows being the Store hook, which silently does nothing if given arguments¹. We don't want pip users hitting that issue of we can avoid it.

¹ Don't get me started on my opinion of that particular bit of behaviour 🙁

@shireenrao
Copy link
Contributor Author

Here is another sphinx extension which I think looks better- https://sphinxcontrib-contentui.readthedocs.io/en/latest/index.html
The examples look promising!

@shireenrao
Copy link
Contributor Author

shireenrao commented Jul 18, 2020

@pradyunsg - Should I close this PR and open a new issue to add tabs to the documentation?

@shireenrao
Copy link
Contributor Author

I added the sphinxcontrib-contentui extension and built the docs locally. I then changed the Upgrading pip section to use tabs and it looks like this:
image
and
image
I uploaded the sphinx generated docs in https://github.com/shireenrao/pip-docs. Once you clone it, just go into the docs folder and then run python -m http.server. Then go to http://localhost:8000/installing.html#upgrading-pip to see it in action.
I was hoping that it could be visible on github pages at https://shireenrao.github.io/pip-docs/ but the site is not rendering properly.

Let me know what you guys think.

@pfmoore
Copy link
Member

pfmoore commented Jul 19, 2020

My expectation was that the Unix instructions would be python -m pip install -U pip (or maybe python3?) and the Windows instructions would be py -m pip install -U pip. Is that not the point here? Also, I don't have the time to build my own copy to check, but does the display adapt to the user's OS (so that, as I use Windows, I'd see the Windows instructions by default)? Otherwise I can imagine people not realising they could click on the buttons, and assuming the default version applies everywhere.

On a more subjective note, I find the style you posted in the screenshot too distracting. Is there an alternative style that's more unobtrusive?

@pradyunsg
Copy link
Member

Can we stick to sphinx-tabs? I'm happy to add a tiny bit of CSS myself to make things look better.

@shireenrao
Copy link
Contributor Author

shireenrao commented Jul 19, 2020

My expectation was that the Unix instructions would be python -m pip install -U pip (or maybe python3?) and the Windows instructions would be py -m pip install -U pip.

Oops.. I was trying to showcase the tabs. Sorry for missing the real point. Detecting the User's OS is not there and I don't see any options to customize the look. The only way to change the look would be to change the css.

@pradyunsg
Copy link
Member

Also, I don't have the time to build my own copy to check, but does the display adapt to the user's OS (so that, as I use Windows, I'd see the Windows instructions by default)?

We deploy the documentation for each PR: https://pip--8589.org.readthedocs.build/en/8589/

@shireenrao
Copy link
Contributor Author

shireenrao commented Jul 19, 2020

I run the docs build using tox -e docs. I can see that the sphinxcontrib.contentui package does not get installed. The section in the logs showing all the packages does not show it. Eventually the build fails..

GLOB sdist-make: /home/srao/projects/pipdev/dev/setup.py docs inst-nodeps: /home/srao/projects/pipdev/dev/.tox/.tmp/package/1/pip-20.2.dev1.zip docs installed: alabaster==0.7.12,Babel==2.8.0,certifi==2020.6.20,chardet==3.0.4,docutils==0.16,idna==2.10,imagesize==1.2.0,Jinja2==2.11.2,MarkupSafe==1.1.1,packaging==20.4,pip @ file:///home/srao/projects/pipdev/dev/.tox/.tmp/package/1/pip-20.2.dev1.zip,Pygments==2.6.1,pypa-docs-theme @ git+https://github.com/pypa/pypa-docs-theme.git@d2e63fbfc62af3b7050f619b2f5bb8658985b931,pyparsing==2.4.7,python-docs-theme @ git+https://github.com/python/python-docs-theme.git@628a66466589ba42037d4aad3d676cb7d81fb6e6,pytz==2020.1,requests==2.24.0,setuptools==49.2.0,six==1.15.0,snowballstemmer==2.0.0,Sphinx==2.4.3,sphinxcontrib-applehelp==1.0.2,sphinxcontrib-devhelp==1.0.2,sphinxcontrib-htmlhelp==1.0.3,sphinxcontrib-jsmath==1.0.1,sphinxcontrib-qthelp==1.0.3,sphinxcontrib-serializinghtml==1.1.4,urllib3==1.25.9,wheel==0.34.2 docs run-test-pre: PYTHONHASHSEED='3354392635'

.......

Extension error: Could not import extension sphinxcontrib.contentui (exception: No module named 'sphinxcontrib.contentui') ERROR: InvocationError for command /home/srao/projects/pipdev/dev/.tox/docs/bin/sphinx-build -W -d /home/srao/projects/pipdev/dev/.tox/docs/tmp/doctrees/html -b html docs/html docs/build/html (exited with code 2) _______________________________________________________ summary ________________________________________________________ ERROR: docs: commands failed

Thats why I havn't pushed this change yet. I have edited docs/html/conf.py to add the sphinxcontrib.contentui extension in the extensions list at the end. I also added this as a docs build requirement under tools/requirements/docs.txt. What else am I missing?

@shireenrao
Copy link
Contributor Author

Can we stick to sphinx-tabs? I'm happy to add a tiny bit of CSS myself to make things look better.

Sure. I will try and add it.

@pradyunsg
Copy link
Member

If you're changing dependencies for the tox job, you'll have to pass -r as well, to tell it to recreate the environment.

@shireenrao
Copy link
Contributor Author

If you're changing dependencies for the tox job, you'll have to pass -r as well, to tell it to recreate the environment.

Thats it!! That Solved the issue! 🙏

@shireenrao
Copy link
Contributor Author

shireenrao commented Jul 20, 2020

You can now see the tabbed version based on sphinx-tabs here - https://pip--8589.org.readthedocs.build/en/8589/installing/#upgrading-pip

I am not sure what is causing the man pages build to fail. As you can see, the html pages get built fine. Here is the log for man pages section -

docs run-test: commands[1] | sphinx-build -W -d /home/srao/projects/pipdev/pip/.tox/docs/tmp/doctrees/man -b man docs/man docs/build/man -c docs/html
Running Sphinx v2.4.3
20.2
loading intersphinx inventory from https://packaging.python.org/objects.inv...
loading intersphinx inventory from https://www.pypa.io/en/latest/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [man]: all manpages
updating environment: [new config] 15 added, 0 changed, 0 removed
reading sources... [ 6%] commands/cache
reading sources... [ 13%] commands/check
reading sources... [ 20%] commands/config
reading sources... [ 26%] commands/debug
reading sources... [ 33%] commands/download
reading sources... [ 40%] commands/freeze
reading sources... [ 46%] commands/hash
reading sources... [ 53%] commands/help
reading sources... [ 60%] commands/install
reading sources... [ 66%] commands/list
reading sources... [ 73%] commands/search
reading sources... [ 80%] commands/show
reading sources... [ 86%] commands/uninstall
reading sources... [ 93%] commands/wheel
reading sources... [100%] index

looking for now-outdated files... none found
pickling environment... done
checking consistency... done
writing... pip.1 { } pip-help.1 { } pip-show.1 { } pip-freeze.1 { } pip-wheel.1 { } pip-debug.1 { } pip-cache.1 { } pip-config.1 { } pip-list.1 { } pip-check.1 { } pip-download.1 { } pip-uninstall.1 { } pip-search.1 { } pip-install.1 { } pip-hash.1 { } done
build succeeded.

The manual pages are in docs/build/man.

Warning, treated as error:
Not copying tabs assets! Not compatible with man builder
ERROR: InvocationError for command /home/srao/projects/pipdev/pip/.tox/docs/bin/sphinx-build -W -d /home/srao/projects/pipdev/pip/.tox/docs/tmp/doctrees/man -b man docs/man docs/build/man -c docs/html (exited with code 2)
_______________________________________________________ summary ________________________________________________________
ERROR: docs: commands failed

Any thoughts?

@shireenrao
Copy link
Contributor Author

shireenrao commented Jul 20, 2020

I found the issue in the sphinx-tabs extension. I have requested a PR there to fix this issue. Man pages are not setup to be a build target in that project and is setup to throw a warning when a new target is used. Currently they have the following targets -
['html', 'singlehtml', 'dirhtml', 'readthedocs', 'readthedocsdirhtml', 'readthedocssinglehtml', 'readthedocssinglehtmllocalmedia', 'spelling']. I have requested man be added to this list with this PR.

@shireenrao
Copy link
Contributor Author

@pradyunsg - is it ok for the sake of moving forward that I forked the sphinx-tabs project and make the necessary changes and reference my forked version in this PR temporarily? This will also let me play with the css/js to fine tune the look of the tabs.

@pradyunsg
Copy link
Member

is it ok for the sake of moving forward that I forked the sphinx-tabs project and make the necessary changes and reference my forked version in this PR temporarily?

I'm not sure I follow -- what issue are you working around?

To answer your question more directly, no, I don't it'd make sense to have a fork to this. It's possible to add/override a CSS file with html_css_files in Sphinx (and similar for js) so I'm not sure we need a fork to tweak the JS/CSS behaviors.

@shireenrao
Copy link
Contributor Author

I have requested man be added to this list with this PR.

As suggest in the sphinx-tabs PR, I have closed it. Looking at the history of the sphinx-tabs project, the warning is thrown on purpose to only support platforms the tabs work on.

I am not sure if one of the two is possible

  • have two different sphinx conf.py files one for html build and one for man pages build
  • have conf.py be aware of what kind of build is being executed and enable the appropriate extension based on type of build

@shireenrao
Copy link
Contributor Author

To answer your question more directly, no, I don't it'd make sense to have a fork to this. It's possible to add/override a CSS file with html_css_files in Sphinx (and similar for js) so I'm not sure we need a fork to tweak the JS/CSS behaviors.

Cool. I wasn't aware of it.

@shireenrao
Copy link
Contributor Author

Thank you for being patient with my changes as I am still learning the ropes. If what I did by creating a new conf.py for man pages is acceptable, then I can trim the config files even more to be specific to each type of build. Please let me know if I am going in the right direction.

@shireenrao
Copy link
Contributor Author

I was reading the documentation for sphinx-build and saw that I can override settings using the -D option. so I will undo the last changes I made and just resubmit with just the tox.ini changes to use the -D for man build.

@shireenrao
Copy link
Contributor Author

Here are some designs I came up with -
1.
image
2.
image
3. Default -
image

Any preferences?

@pfmoore
Copy link
Member

pfmoore commented Jul 21, 2020

Personally I prefer (3).

@pradyunsg pradyunsg added type: docs Documentation related type: enhancement Improvements to functionality labels Sep 14, 2020
@shireenrao shireenrao closed this Sep 14, 2020
@shireenrao shireenrao reopened this Sep 14, 2020
@pradyunsg
Copy link
Member

It's fine -- Travis CI is acting up.

@pradyunsg
Copy link
Member

pradyunsg commented Sep 16, 2020

At the cost of being a little/very annoying... I'd like us to defer adding sphinx-tabs to our current docs, since sphinx-panels added the same functionality (and I recently added a bug there!). That approach to tabs can be stylized to look real nice much more easily!

Example from Furo's documentation:

2020-09-16 18 23 56

@McSinyx
Copy link
Contributor

McSinyx commented Sep 16, 2020

Personally I'd favor sphinx-tabs though, for the reason mentioned in the docs @pradyunsg linked:

The key difference is that, whereas sphinx-tabs uses JavaScript to implement this functionality, sphinx-panels only uses CSS. A CSS only solution has the benefit of faster load-times, and working when JS is disabled, although JS allows sphinx-tabs to implement some extended functionality (like synchronized selections).

Regarding the look, I think we can work with upstream to see if there's some option, but I'd consider being able to select the OS just one a must-have feature.

@pradyunsg
Copy link
Member

I think we can work with upstream

I'm an upstream maintainer/collaborator on both of those packages. :)

@McSinyx
Copy link
Contributor

McSinyx commented Sep 19, 2020

Is there any technical hindrance preventing sphinx-tabs to be styled (TBH I'm fine with the way it looks ATM)? Also the entry point invocation issue has caused quite many issues since I started watching this repo that I think it'd be really nice to have this merged as soon as possible, especially when @shireenrao has put a lot of effort following up on the patch.

Edit: to clarify, by really nice, I meant being nice for the users to not run into confusing situations. Of course it'd be nice for us too that we will spend less time helping troubleshooting those 😈

Regarding furo, as much as I like it and expecting it to hit stable ASAP, let's be realistic that you're a quite busy person and usually over-work yourself. Tying this with furo would lead to one of the following situations

  • We delay the change indefinitely waiting for furo to be well-documented
  • We rely on undocumented features that only you're aware of, and that'll put all the work on you

@pfmoore
Copy link
Member

pfmoore commented Sep 19, 2020

I'd consider being able to select the OS just one a must-have feature.

I'm not 100% sure what you meant here, but the current version lets you select the OS once per page, but if you go from (for example) "Installing" to "User Guide", you need to re-select your preferred OS. For Unix users not such a big deal (as it's the default) but annoying for Windows.

Two possibilities here:

  1. Remember the user's preference (via a cookie).
  2. Detect the user's OS via browser sniffing.

Currently, this PR feels like it's "nearly there". The defaulting isn't perfect, and we can argue styling all day (I'm not massively keen on the current choice of style for example, but 🤷 ) If the OS selection/persistence issue can be corrected, I'd like to see that. If it's hard, then I'd like to see a follow-up issue raised saying that it needs fixing, so it doesn't get forgotten.

But let's not make perfect be the enemy of good. I'd be fine with merging this and doing subsequent work (including something like switching the implementation to sphinx-panels) in follow-up PRs. I agree that @shireenrao has done a lot of good work here, so it would be nice to see that merged so users can benefit.

@McSinyx
Copy link
Contributor

McSinyx commented Sep 19, 2020

Thank you for the correction, I was arguing that design-wise sphinx-panels wouldn't support tab-group equivalence. I'll file the issue on site-wise persistence just in case it is forgotten a few days after this getting merged.

@pradyunsg
Copy link
Member

Let's merge this in. This PR is an improvement over status quo, and any potential future changes should likely build up on top of this one. :)

@shireenrao
Copy link
Contributor Author

I was playing around with the look and had posted some styles earlier here.
The look can be adjusted easily.

As for the issue with remembering the tabs across pages.. there was an issue opened a few weeks ago which should bring this feature in.

@pradyunsg
Copy link
Member

The issue you've linked to is blocked on me doing a rewrite of the sphinx-tabs package, and I certainly plan to have better styling by default when I get to it.

It might just end up being that I do a rewrite that fixes all these issues for us. 🤷🏻‍♂️

@pradyunsg pradyunsg merged commit 75befb5 into pypa:master Sep 24, 2020
@pradyunsg
Copy link
Member

Thanks @shireenrao! ^>^

@uranusjr
Copy link
Member

Thanks so much for pushing this through @shireenrao!

@shireenrao
Copy link
Contributor Author

shireenrao commented Sep 24, 2020

I am glad this worked out.

@shireenrao
Copy link
Contributor Author

There seems to be a problem on the Quickstart guide. For some reason the tabs are not rendering on that page. The PR build version is showing it.

@hugovk
Copy link
Contributor

hugovk commented Sep 24, 2020

Good work!


I see the tabs on the Quickstart page.

image

You could try clearing your browser cache or using Incognito?

@shireenrao
Copy link
Contributor Author

Its working now. What was weird was that the tabs were fine in the other pages except the quickstart page. I had tried it on multiple browsers and devices.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: docs Documentation related type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use python -m to run pip.
10 participants