From afb4e6f5ba84a4baf6484a622deaa8955da23bfb Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 26 Mar 2020 21:01:41 +0200 Subject: [PATCH 1/4] cli: cmdoptions: Mark always_unzip as depreceated --- src/pip/_internal/cli/cmdoptions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 5b5647d64f4..adfc81767c4 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -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) def _handle_merge_hash(option, opt_str, value, parser): From a80d5426cac21a73e830095f54ffc16c6ce6b57d Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 26 Mar 2020 21:08:16 +0200 Subject: [PATCH 2/4] docs: Reqfile options are now generated automatically --- docs/html/reference/pip_install.rst | 13 +---------- docs/pip_sphinxext.py | 34 +++++++++++++++++++++++++++++ news/7908.doc | 2 ++ 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 news/7908.doc diff --git a/docs/html/reference/pip_install.rst b/docs/html/reference/pip_install.rst index 294e969f3e1..f33e279373d 100644 --- a/docs/html/reference/pip_install.rst +++ b/docs/html/reference/pip_install.rst @@ -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 ` - * :ref:`--extra-index-url ` - * :ref:`--no-index ` - * :ref:`-c, --constraint ` - * :ref:`-r, --requirement ` - * :ref:`-e, --editable ` - * :ref:`-f, --find-links ` - * :ref:`--no-binary ` - * :ref:`--only-binary ` - * :ref:`--require-hashes ` - * :ref:`--pre ` - * :ref:`--trusted-host <--trusted-host>` +.. pip-requirements-file-options-ref-list:: For example, to specify :ref:`--no-index ` and two :ref:`--find-links ` locations: diff --git a/docs/pip_sphinxext.py b/docs/pip_sphinxext.py index 29ca34c7289..4db8db5d7b6 100644 --- a/docs/pip_sphinxext.py +++ b/docs/pip_sphinxext.py @@ -10,6 +10,7 @@ from pip._internal.cli import cmdoptions from pip._internal.commands import create_command +from pip._internal.req.req_file import SUPPORTED_OPTIONS class PipCommandUsage(rst.Directive): @@ -108,9 +109,42 @@ def process_options(self): ) +class PipReqFileOptionsReference(PipOptions): + + 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 = '' + + from_install = ( + 'install_' + if option not in cmdoptions.general_group['options'] else + '' + ) + self.view_list.append( + ' * :ref:`{short}{long}<{prefix}{opt_name}>`'.format( + short=short_opt_name, + long=opt_name, + prefix=from_install, + 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 + ) diff --git a/news/7908.doc b/news/7908.doc new file mode 100644 index 00000000000..8a5d182196e --- /dev/null +++ b/news/7908.doc @@ -0,0 +1,2 @@ +Requirements file options are now extracted from the code instead +of being maintained manually. From 7494d703569008540cb6c62029dae76a327d54dc Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Mon, 27 Apr 2020 14:39:25 +0300 Subject: [PATCH 3/4] docs: Improve prefix calculation of reqfile option autogeneration --- docs/pip_sphinxext.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/pip_sphinxext.py b/docs/pip_sphinxext.py index 4db8db5d7b6..6cc7a2c82ec 100644 --- a/docs/pip_sphinxext.py +++ b/docs/pip_sphinxext.py @@ -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 @@ -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): @@ -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" From 4c8b175649a46676273cc55cf33f326d41cf378a Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 31 May 2020 21:07:54 +0300 Subject: [PATCH 4/4] news: Update news/7908.doc Co-authored-by: Pradyun Gedam --- news/7908.doc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/news/7908.doc b/news/7908.doc index 8a5d182196e..ec5ee72ac2e 100644 --- a/news/7908.doc +++ b/news/7908.doc @@ -1,2 +1,2 @@ -Requirements file options are now extracted from the code instead -of being maintained manually. +List of options supported in requirements file are extracted from source of truth, +instead of being maintained manually.