Skip to content

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

Open
@q0w

Description

@q0w
Contributor

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

Activity

q0w

q0w commented on Jul 6, 2023

@q0w
ContributorAuthor

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

atugushev commented on Jul 6, 2023

@atugushev
Member

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

q0w commented on Jul 6, 2023

@q0w
ContributorAuthor

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

atugushev commented on Jul 6, 2023

@atugushev
Member

It seems this is an another bug

Arguably empty config is still a config.

q0w

q0w commented on Jul 6, 2023

@q0w
ContributorAuthor

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

atugushev commented on Jul 9, 2023

@atugushev
Member

But why does not it found configuration in this case:

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

q0w

q0w commented on Jul 9, 2023

@q0w
ContributorAuthor

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

atugushev commented on Jul 9, 2023

@atugushev
Member

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

atugushev

atugushev commented on Jul 9, 2023

@atugushev
Member

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

q0w commented on Jul 9, 2023

@q0w
ContributorAuthor

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

atugushev

atugushev commented on Jul 9, 2023

@atugushev
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not workingconfigRelated to pip-tools' configuration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @atugushev@q0w

      Issue actions

        annotation --config is added even there is no configuration · Issue #1902 · jazzband/pip-tools