Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract supported req file option docs #7908

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-requirements-file-options-ref-list::

For example, to specify :ref:`--no-index <install_--no-index>` and two
:ref:`--find-links <install_--find-links>` locations:
Expand Down
44 changes: 43 additions & 1 deletion docs/pip_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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


class PipCommandUsage(rst.Directive):
Expand Down Expand Up @@ -108,9 +109,50 @@ 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):
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 = ''

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=prefix,
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-requirements-file-options-ref-list', PipReqFileOptionsReference
)
2 changes: 2 additions & 0 deletions news/7908.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
List of options supported in requirements file are extracted from source of truth,
instead of being maintained manually.
4 changes: 4 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,10 @@ def _handle_no_use_pep517(option, opt, value, parser):
action='store_true',
help=SUPPRESS_HELP,
) # type: Callable[..., Option]
# TODO: Move into a class that inherits from partial, currently does not
# work as mypy complains functools.partial is a generic class.
# This way we know we can ignore this option in docs auto generation
setattr(always_unzip, 'deprecated', True)
NoahGorny marked this conversation as resolved.
Show resolved Hide resolved


def _handle_merge_hash(option, opt_str, value, parser):
Expand Down