Pip-tools: Using pip-compile --no-index doesn't exclude the --extra-index-url from being added to requirements.txt

Created on 8 Jan 2020  路  7Comments  路  Source: jazzband/pip-tools


Prior to 4.x.x using pip-compile and --no-index option correctly excluded the --extra-index-url from the generated requirements.txt

This doesn't seem to work with the latest release.

Environment Versions

  1. OS Type: Mac OS
  2. Python version: Python 3.7.3
  3. pip version: pip 19.3.1
  4. pip-tools version: pip-compile, version 4.3.0

Steps to replicate

$ pip-compile --extra-index-url=https://mycustomusername:[email protected] --no-index

Expected result

In the requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --no-index --output-file requirements.txt setup.py
#

Actual result

#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --extra-index-url=https://mycustomusername:[email protected] --no-index
#
cli enhancement help wanted

Most helpful comment

Yeah it was quite obvious that this was a bug prior to 4.x.x

I also agree that --emit-index-url would be a viable option.

I'll be keen on finding a middle ground since we recently upgraded to 4.x.x and lost the previous bug/behaviour.

All 7 comments

Hello @jackton1

Thanks for the issue! The fact is the --no-index option has nothing to do with To update, run: header. This option controls whether pip-compile should print out --index-url or --extra-index-url to the output (below the header/commentaries).

Default behavior without --no-index option:

$ echo "" | pip-compile - -qo- --extra-index-url https://foo
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --extra-index-url=https://foo --output-file=- -
#
--extra-index-url https://foo

See --no-index skips --extra-index-url in the output:

$ echo "" | pip-compile - -qo- --extra-index-url https://foo --no-index
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --extra-index-url=https://foo --no-index --output-file=- -
#

Notice the To update, run: header, there's always --extra-index-url regardless of --no-index.

Prior to 4.x.x using pip-compile and --no-index option correctly excluded the --extra-index-url from the generated requirements.txt

That's because before 4.X --index-url and --extra-index-url were never printed to the header section.

Most likely, you need the --no-header option, which is the recommended way to hide sensitive data from the output.

Should we remove --index-url/--extra-index-url from the header if there is --no-index? I'd say no but would like to hear opinions.

Personally from the help information it mentions the index url which one could assume relates
to -I,--index-url.

 --index / --no-index            Add index URL to generated file

If this is the case using a similar option --no-extra-index could mean exclude the extra index url explicitly else this could also be another option. Since I'll like to keep the header because it includes warning that the requirements.txt was autogenerated and shouldn't be manually modified.

This could be a new option --no-extra-index or assuming the presence of --no-index also means exclude the extra-index-url from the requirements.txt header.

I prefer the former since it's clear and explicit. @atugushev

@jackton1

I prefer the former since it's clear and explicit

I must note that --index-url and --extra-index-url were never printed to the output before 3.7.0 regardless whether or not the --no-index was set on. Thus, this former behavior was kind of a bug.

See also https://github.com/jazzband/pip-tools/issues/811#issuecomment-521266376 wich could be related.

Yeah it was quite obvious that this was a bug prior to 4.x.x

I also agree that --emit-index-url would be a viable option.

I'll be keen on finding a middle ground since we recently upgraded to 4.x.x and lost the previous bug/behaviour.

Here is the fix #1146. Please test and review it, any feedback is welcomed!

Will do. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dazza-codes picture dazza-codes  路  3Comments

jedie picture jedie  路  4Comments

vphilippon picture vphilippon  路  4Comments

kmontag picture kmontag  路  4Comments

tuukkamustonen picture tuukkamustonen  路  5Comments