Skip to content

Commit 974ec15

Browse files
author
Noah Gorny
committed
docs: Improve prefix calculation of reqfile option autogeneration
1 parent d554cf9 commit 974ec15

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

docs/pip_sphinxext.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
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
1313
from pip._internal.req.req_file import SUPPORTED_OPTIONS
1414

1515

@@ -111,6 +111,14 @@ def process_options(self):
111111

112112
class PipReqFileOptionsReference(PipOptions):
113113

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+
114122
def process_options(self):
115123
for option in SUPPORTED_OPTIONS:
116124
if getattr(option, 'deprecated', False):
@@ -123,16 +131,16 @@ def process_options(self):
123131
else:
124132
short_opt_name = ''
125133

126-
from_install = (
127-
'install_'
128-
if option not in cmdoptions.general_group['options'] else
129-
''
130-
)
134+
if option in cmdoptions.general_group['options']:
135+
prefix = ''
136+
else:
137+
prefix = '{}_'.format(self.determine_opt_prefix(opt_name))
138+
131139
self.view_list.append(
132140
' * :ref:`{short}{long}<{prefix}{opt_name}>`'.format(
133141
short=short_opt_name,
134142
long=opt_name,
135-
prefix=from_install,
143+
prefix=prefix,
136144
opt_name=opt_name
137145
),
138146
"\n"

0 commit comments

Comments
 (0)