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

Config file discovery doesn't work as intended #2096

Open
un-def opened this issue May 31, 2024 · 1 comment · May be fixed by #2097
Open

Config file discovery doesn't work as intended #2096

un-def opened this issue May 31, 2024 · 1 comment · May be fixed by #2097
Labels
bug Something is not working config Related to pip-tools' configuration duplicate Duplicate of an existing issue/PR

Comments

@un-def
Copy link

un-def commented May 31, 2024

As it stated in the documentation, pip-tools look for the configuration file “in the same directory as your requirements input files”. However, due to the way click works, it's not true:

  1. --config (and --no-config) is declared as eager: https://github.com/jazzband/pip-tools/blob/7.4.1/piptools/scripts/options.py#L317-L333
  2. --config's callback override_defaults_from_config_file tries to get the src_files param value to compute the config path relative to the source files: https://github.com/jazzband/pip-tools/blob/7.4.1/piptools/utils.py#L543
  3. But since callbacks of eager options are called before other options are processed, src_files is always empty. From the click documentation: “All eager parameters are evaluated before all non-eager parameters, but again in the order as they were provided on the command line by the user.”
  4. select_config_file falls back to the current working dir as a config file location: https://github.com/jazzband/pip-tools/blob/7.4.1/piptools/utils.py#L627-L630

Environment Versions

  1. Linux
  2. Python version: Python 3.12.3
  3. pip version: pip 24.0
  4. pip-tools version: pip-compile, version 7.4.1

Steps to replicate

  1. Create the requirements directory requirements/ with requirements.in.
  2. Create the configuration file .pip-tools.toml or pyproject.toml with generate-hashes = true.
  3. Run pip compile requirements/requirements.in.

Expected result

requirements/requirements.txt contains hashes.

Actual result

requirements/requirements.txt has no hashes; the configuration file is ignored.

un-def added a commit to un-def/pip-tools that referenced this issue May 31, 2024
@un-def un-def linked a pull request May 31, 2024 that will close this issue
4 tasks
@chrysle chrysle added bug Something is not working duplicate Duplicate of an existing issue/PR config Related to pip-tools' configuration labels May 31, 2024
@chrysle
Copy link
Contributor

chrysle commented May 31, 2024

Thanks for raising this issue! Note this was already discovered and the same fix suggested in #1902.

I proposed it in #2048 some time ago, unfortunately it seems to have been forgotten. Thanks for providing the tests though, I might transfer them there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working config Related to pip-tools' configuration duplicate Duplicate of an existing issue/PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants