jazzband / pip-tools

A set of tools to keep your pinned Python dependencies fresh.
https://pip-tools.rtfd.io
BSD 3-Clause "New" or "Revised" License
7.77k stars 611 forks source link

Argument --pip-args "--isolated" is still loading $HOME/.pip/pip.conf #2125

Open adoussot opened 2 months ago

adoussot commented 2 months ago

Pip exposes the argument --isolated to "ignore environment variables and user configuration" (including $HOME/.pip/pip.conf) https://pip.pypa.io/en/stable/cli/pip/.

As pip-compile exposes an argument "--pip-args" I would expect that passing --isolated would ignore "$HOME/.pip/pip.conf" file. But the below command includes "--extra-index-url https://pypi.org/simple" which is only present in $HOME/.pip/pip.conf

pip-compile --pip-args "--isolated" --extra-index-url=https://server/repository/pypi-dev/simple --index-url=https://server/repository/pypi-prod/simple --output-file=./requirements_build.txt ./requirements_build.in

# OUTPUT
# WARNING: --strip-extras is becoming the default in version 8.0.0. To silence this warning, either use --strip-extras to opt into the new default or use --no-strip-extras to retain the existing behavior.
# #
# # This file is autogenerated by pip-compile with Python 3.11
# # by the following command:
# #
# #    pip-compile --extra-index-url=https://server/repository/pypi-dev/simple --index-url=https://server/repository/pypi-pro
# d/simple --output-file=../src/requirements_build.txt --pip-args='--isolated' ../src/requirements_build.in
# #
# --index-url https://server/repository/pypi-prod/simple
# --extra-index-url https://pypi.org/simple
# --extra-index-url https://server/repository/pypi-dev/simple

Content of $HOME/.pip/pip.conf

[global]
extra-index-url = https://pypi.org/simple 

If we are adding some traces in pip-tools and pip we can see that pip_args contains --isolated

['-i', 'https://server/repository/pypi-prod/simple', '--extra-index-url', 'https://server/repository/pypi-dev/simple', '--cache-dir', '/home/adoussot/.cache/pip-tools', '--isolated']

BUT when calling pip self.parser.parse_args it calls self.get_default_values => Which doesnt takes --isolated => and it load the user conf

  File "path/venv/lib/python3.11/site-packages/piptools/scripts/compile.py", line 311, in cli
    tmp_repository = PyPIRepository(pip_args, cache_dir=cache_dir)
  File "path/venv/lib/python3.11/site-packages/piptools/repositories/pypi.py", line 69, in __init__
    options, _ = self.command.parse_args(pip_args)
  File "path/venv/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 152, in parse_args
    a = self.parser.parse_args(args)
  File "/usr/lib/python3.11/optparse.py", line 1371, in parse_args
    values = self.get_default_values()
  File "path/venv/lib/python3.11/site-packages/pip/_internal/cli/parser.py", line 279, in get_default_values
    self.config.load()
  File "path/venv/lib/python3.11/site-packages/pip/_internal/configuration.py", line 124, in load
    self._load_config_files()
  File "path/venv/lib/python3.11/site-packages/pip/_internal/configuration.py", line 246, in _load_config_files
    config_files = dict(self.iter_config_files())
  File "path/venv/lib/python3.11/site-packages/pip/_internal/configuration.py", line 349, in iter_config_files
    import traceback; traceback.print_stack()
        @@@@ should_load_user_config! True
@@@@ self.parser.parse_args: (<Values at 0x7f662d7da250: {'help': None, 'debug_mode': False, 'isolated_mode': True,

I don't know if it's a pip-tools or a pip limitations. What's your thoughts ?

Environment Versions

  1. OS Type: Linux Debian
  2. Python version: 3.11.2
  3. pip version: 24.0
  4. pip-tools version: 7.4.1

Steps to replicate

  1. Add extra-index-url = https://pypi.org/simple to $HOME/.pip/pip.conf
  2. Executes pip-compile --pip-args "--isolated"
  3. Check the output include "--extra-index-url https://pypi.org/simple"

Expected result

pip-compile should ignore $HOME/.pip/pip.conf file and the output should NOT include "--extra-index-url https://pypi.org/simple"

Actual result

The output includes "--extra-index-url https://pypi.org/simple"

pip-compile --pip-args "--isolated" --extra-index-url=https://server/repository/pypi-dev/simple --index-url=https://server/repository/pypi-prod/simple --output-file=./requirements_build.txt ./requirements_build.in

# OUTPUT
.....
# #    pip-compile --extra-index-url=https://server/repository/pypi-dev/simple --index-url=https://server/repository/pypi-pro d/simple --output-file=../src/requirements_build.txt --pip-args='--isolated' ../src/requirements_build.in
# #
# --index-url https://server/repository/pypi-prod/simple
# --extra-index-url https://pypi.org/simple
# --extra-index-url https://server/repository/pypi-dev/simple