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

annotation --config is added even there is no configuration #1902

Open
q0w opened this issue Jul 6, 2023 · 11 comments · May be fixed by #2048
Open

annotation --config is added even there is no configuration #1902

q0w opened this issue Jul 6, 2023 · 11 comments · May be fixed by #2048
Labels
bug Something is not working config Related to pip-tools' configuration

Comments

@q0w
Copy link
Contributor

q0w commented Jul 6, 2023

pip-tools 6.14.0 adds --config annotation even there is no configuration.

Environment Versions

  1. OS Type: Linux
  2. Python version: $ python -V: 3.11.3
  3. pip version: $ pip --version: 22.3.1
  4. pip-tools version: $ pip-compile --version: 6.14.0

Steps to replicate

mkdir requirements
touch pyproject.toml
echo astpretty > requirements/test.in
pip-compile --allow-unsafe --generate-hashes --output-file=requirements/test.txt --resolver=backtracking --strip-extras requirements/test.in

Expected result

#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes --output-file=requirements/test.txt --resolver=backtracking --strip-extras requirements/test.in
#
astpretty==3.0.0 \
    --hash=sha256:15bfd47593667169485a1fa7938b8de9445b11057d6f2b6e214b2f70667f94b6 \
    --hash=sha256:b08c95f32e5994454ea99882ff3c4a0afc8254c38998a0ed4b479dba448dc581
    # via -r requirements/test.in

Actual result

#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
#    pip-compile --allow-unsafe --config=pyproject.toml --generate-hashes --output-file=requirements/test.txt --resolver=backtracking --strip-extras requirements/test.in
#
astpretty==3.0.0 \
    --hash=sha256:15bfd47593667169485a1fa7938b8de9445b11057d6f2b6e214b2f70667f94b6 \
    --hash=sha256:b08c95f32e5994454ea99882ff3c4a0afc8254c38998a0ed4b479dba448dc581
    # via -r requirements/test.in
@q0w
Copy link
Contributor Author

q0w commented Jul 6, 2023

When running pip-compile click context has no src_files, so select_config_file returns pyproject.toml, but after compiling click context has src_files as requirements/test.in, so select_config_file returns None and so pyproject.toml != None
Making --config is_eager=False works

@atugushev
Copy link
Member

atugushev commented Jul 6, 2023

Perhaps, src_files should be eager instead of config. Which makes sense, because --config depends on src_files in override_defaults_from_config_file.

@q0w
Copy link
Contributor Author

q0w commented Jul 6, 2023

oh maybe in override_defaults_from_config_file it should return None if there is no config in the file.
So config should be None, if pyproject.toml is empty

def override_defaults_from_config_file(
    ctx: click.Context, param: click.Parameter, value: str | None
) -> Path | None:
    if ctx.params.get("no_config"):
        return None

    if value is None:
        config_file = select_config_file(ctx.params.get("src_files", ()))
        if config_file is None:
            return None
    else:
        config_file = Path(value)

    config = parse_config_file(config_file)
    if not config:
        return None
    _assign_config_to_cli_context(ctx, config)
    return config_file

It seems this is an another bug

@atugushev
Copy link
Member

It seems this is an another bug

Arguably empty config is still a config.

@q0w
Copy link
Contributor Author

q0w commented Jul 6, 2023

But why does not it found configuration in this case:

- pyproject.toml
- requirements
-- test.in

pyproject.toml is not empty
with src_files = ('requirements/test.in',) config_file is None

@atugushev
Copy link
Member

But why does not it found configuration in this case:

@q0w I'm not following. Could you please elaborate?

@q0w
Copy link
Contributor Author

q0w commented Jul 9, 2023

When src_files is ('requirements/test.in',) it does not find a config file from pyproject.toml. Use an example from this issue and add a pip-tools configuration in pyproject.toml to reproduce.

@atugushev
Copy link
Member

select_config_file(('requirements/test.in',)) is None because it searches config in requirements/pyproject.toml.

@atugushev
Copy link
Member

atugushev commented Jul 9, 2023

select_config_file called twice, when parsing args and in get_compile_command() and gives different results, because:

  • on first call src_files is empty, because it's not yet handled (not eager)
  • on second call src_files non-empty - all args are handled

Which is why is_eager=True flag on src_files fixes the issue.

@q0w
Copy link
Contributor Author

q0w commented Jul 9, 2023

Yes, but I think it should find pyproject.toml because pip-tools is called in PWD=., not requirements dir

@atugushev
Copy link
Member

atugushev commented Jul 9, 2023

@q0w agreed 👍🏻 select_config_file should search for configs in PWD and in src_files dirs. Currently, it searches in PWD or src_files dirs.

@atugushev atugushev added the config Related to pip-tools' configuration label Jul 16, 2023
@chrysle chrysle linked a pull request Jan 20, 2024 that will close this issue
4 tasks
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants