Skip to content

Commit 1e75341

Browse files
author
Noah Gorny
committed
docs: reqfile options are now generated automatically
1 parent ee874c6 commit 1e75341

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

docs/html/reference/pip_install.rst

+1-12
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,7 @@ To interpret the requirements file in UTF-8 format add a comment
156156

157157
The following options are supported:
158158

159-
* :ref:`-i, --index-url <install_--index-url>`
160-
* :ref:`--extra-index-url <install_--extra-index-url>`
161-
* :ref:`--no-index <install_--no-index>`
162-
* :ref:`-c, --constraint <install_--constraint>`
163-
* :ref:`-r, --requirement <install_--requirement>`
164-
* :ref:`-e, --editable <install_--editable>`
165-
* :ref:`-f, --find-links <install_--find-links>`
166-
* :ref:`--no-binary <install_--no-binary>`
167-
* :ref:`--only-binary <install_--only-binary>`
168-
* :ref:`--require-hashes <install_--require-hashes>`
169-
* :ref:`--pre <install_--pre>`
170-
* :ref:`--trusted-host <--trusted-host>`
159+
.. pip-reqfile-options-ref::
171160

172161
For example, to specify :ref:`--no-index <install_--no-index>` and two
173162
:ref:`--find-links <install_--find-links>` locations:

docs/pip_sphinxext.py

+32
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from pip._internal.cli import cmdoptions
1212
from pip._internal.commands import create_command
13+
from pip._internal.req.req_file import SUPPORTED_OPTIONS
1314

1415

1516
class PipCommandUsage(rst.Directive):
@@ -108,9 +109,40 @@ def process_options(self):
108109
)
109110

110111

112+
class PipReqFileOptionsReference(PipOptions):
113+
114+
def process_options(self):
115+
for option in SUPPORTED_OPTIONS:
116+
if getattr(option, 'deprecated', False):
117+
continue
118+
119+
opt = option()
120+
opt_name = opt._long_opts[0]
121+
if opt._short_opts:
122+
short_opt_name = '{}, '.format(opt._short_opts[0])
123+
else:
124+
short_opt_name = ''
125+
126+
from_install = (
127+
'install_'
128+
if option not in cmdoptions.general_group['options'] else
129+
''
130+
)
131+
self.view_list.append(
132+
' * :ref:`{short}{long}<{prefix}{opt_name}>`'.format(
133+
short=short_opt_name,
134+
long=opt_name,
135+
prefix=from_install,
136+
opt_name=opt_name
137+
),
138+
"\n"
139+
)
140+
141+
111142
def setup(app):
112143
app.add_directive('pip-command-usage', PipCommandUsage)
113144
app.add_directive('pip-command-description', PipCommandDescription)
114145
app.add_directive('pip-command-options', PipCommandOptions)
115146
app.add_directive('pip-general-options', PipGeneralOptions)
116147
app.add_directive('pip-index-options', PipIndexOptions)
148+
app.add_directive('pip-reqfile-options-ref', PipReqFileOptionsReference)

0 commit comments

Comments
 (0)