Skip to content

Commit 19e739c

Browse files
authored
Merge pull request #7908 from NoahGorny/extract-supported-req-file-option-docs
Extract supported req file option docs
2 parents 3599d7b + 4c8b175 commit 19e739c

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
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-requirements-file-options-ref-list::
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

+43-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from docutils.statemachine import ViewList
1010

1111
from pip._internal.cli import cmdoptions
12-
from pip._internal.commands import create_command
12+
from pip._internal.commands import commands_dict, create_command
13+
from pip._internal.req.req_file import SUPPORTED_OPTIONS
1314

1415

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

110111

112+
class PipReqFileOptionsReference(PipOptions):
113+
114+
def determine_opt_prefix(self, opt_name):
115+
for command in commands_dict:
116+
cmd = create_command(command)
117+
if cmd.cmd_opts.has_option(opt_name):
118+
return command
119+
120+
raise KeyError('Could not identify prefix of opt {}'.format(opt_name))
121+
122+
def process_options(self):
123+
for option in SUPPORTED_OPTIONS:
124+
if getattr(option, 'deprecated', False):
125+
continue
126+
127+
opt = option()
128+
opt_name = opt._long_opts[0]
129+
if opt._short_opts:
130+
short_opt_name = '{}, '.format(opt._short_opts[0])
131+
else:
132+
short_opt_name = ''
133+
134+
if option in cmdoptions.general_group['options']:
135+
prefix = ''
136+
else:
137+
prefix = '{}_'.format(self.determine_opt_prefix(opt_name))
138+
139+
self.view_list.append(
140+
' * :ref:`{short}{long}<{prefix}{opt_name}>`'.format(
141+
short=short_opt_name,
142+
long=opt_name,
143+
prefix=prefix,
144+
opt_name=opt_name
145+
),
146+
"\n"
147+
)
148+
149+
111150
def setup(app):
112151
app.add_directive('pip-command-usage', PipCommandUsage)
113152
app.add_directive('pip-command-description', PipCommandDescription)
114153
app.add_directive('pip-command-options', PipCommandOptions)
115154
app.add_directive('pip-general-options', PipGeneralOptions)
116155
app.add_directive('pip-index-options', PipIndexOptions)
156+
app.add_directive(
157+
'pip-requirements-file-options-ref-list', PipReqFileOptionsReference
158+
)

news/7908.doc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
List of options supported in requirements file are extracted from source of truth,
2+
instead of being maintained manually.

src/pip/_internal/cli/cmdoptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,10 @@ def _handle_no_use_pep517(option, opt, value, parser):
832832
action='store_true',
833833
help=SUPPRESS_HELP,
834834
) # type: Callable[..., Option]
835+
# TODO: Move into a class that inherits from partial, currently does not
836+
# work as mypy complains functools.partial is a generic class.
837+
# This way we know we can ignore this option in docs auto generation
838+
setattr(always_unzip, 'deprecated', True)
835839

836840

837841
def _handle_merge_hash(option, opt_str, value, parser):

0 commit comments

Comments
 (0)