Skip to content

Commit

Permalink
docs: reqfile options are now generated automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gorny committed Mar 26, 2020
1 parent ee874c6 commit 8f00d0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
13 changes: 1 addition & 12 deletions docs/html/reference/pip_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,7 @@ To interpret the requirements file in UTF-8 format add a comment

The following options are supported:

* :ref:`-i, --index-url <install_--index-url>`
* :ref:`--extra-index-url <install_--extra-index-url>`
* :ref:`--no-index <install_--no-index>`
* :ref:`-c, --constraint <install_--constraint>`
* :ref:`-r, --requirement <install_--requirement>`
* :ref:`-e, --editable <install_--editable>`
* :ref:`-f, --find-links <install_--find-links>`
* :ref:`--no-binary <install_--no-binary>`
* :ref:`--only-binary <install_--only-binary>`
* :ref:`--require-hashes <install_--require-hashes>`
* :ref:`--pre <install_--pre>`
* :ref:`--trusted-host <--trusted-host>`
.. pip-reqfile-options-ref::

For example, to specify :ref:`--no-index <install_--no-index>` and two
:ref:`--find-links <install_--find-links>` locations:
Expand Down
32 changes: 32 additions & 0 deletions docs/pip_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from pip._internal.cli import cmdoptions
from pip._internal.commands import create_command
from pip._internal.req.req_file import SUPPORTED_OPTIONS


class PipCommandUsage(rst.Directive):
Expand Down Expand Up @@ -108,9 +109,40 @@ def process_options(self):
)


class PipReqFileOptionsReference(PipOptions):

def process_options(self):
for option in SUPPORTED_OPTIONS:
if getattr(option, 'deprecated', False):
continue

opt = option()
opt_name = opt._long_opts[0]
if opt._short_opts:
short_opt_name = '{}, '.format(opt._short_opts[0])
else:
short_opt_name = ''

from_install = (
'install_'
if option not in cmdoptions.general_group['options'] else
''
)
self.view_list.append(
' * :ref:`{short}{long}<{prefix}{opt_name}>`'.format(
short=short_opt_name,
long=opt_name,
prefix=from_install,
opt_name=opt_name
),
"\n"
)


def setup(app):
app.add_directive('pip-command-usage', PipCommandUsage)
app.add_directive('pip-command-description', PipCommandDescription)
app.add_directive('pip-command-options', PipCommandOptions)
app.add_directive('pip-general-options', PipGeneralOptions)
app.add_directive('pip-index-options', PipIndexOptions)
app.add_directive('pip-reqfile-options-ref', PipReqFileOptionsReference)
2 changes: 2 additions & 0 deletions news/7908.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Requirements file options are now extracted from the code instead
of being maintained manually.

0 comments on commit 8f00d0e

Please sign in to comment.