Skip to content

Commit

Permalink
docs: Improve prefix calculation of reqfile option autogeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gorny committed Apr 27, 2020
1 parent b079c3f commit 1e51a70
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions docs/pip_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from docutils.statemachine import ViewList

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


Expand Down Expand Up @@ -111,6 +111,14 @@ def process_options(self):

class PipReqFileOptionsReference(PipOptions):

def determine_opt_prefix(self, opt_name):
for command in commands_dict:
cmd = create_command(command)
if cmd.cmd_opts.has_option(opt_name):
return command

raise KeyError('Could not identify prefix of opt {}'.format(opt_name))

def process_options(self):
for option in SUPPORTED_OPTIONS:
if getattr(option, 'deprecated', False):
Expand All @@ -123,16 +131,16 @@ def process_options(self):
else:
short_opt_name = ''

from_install = (
'install_'
if option not in cmdoptions.general_group['options'] else
''
)
if option in cmdoptions.general_group['options']:
prefix = ''
else:
prefix = '{}_'.format(self.determine_opt_prefix(opt_name))

self.view_list.append(
' * :ref:`{short}{long}<{prefix}{opt_name}>`'.format(
short=short_opt_name,
long=opt_name,
prefix=from_install,
prefix=prefix,
opt_name=opt_name
),
"\n"
Expand Down

0 comments on commit 1e51a70

Please sign in to comment.