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.69k stars 610 forks source link

Parse pyproject.toml statically where possible #1964

Closed hauntsaninja closed 5 months ago

hauntsaninja commented 1 year ago
Contributor checklist
Maintainer checklist
webknjaz commented 1 year ago

Plz use pathlib everywhere instead of low-level os calls.

hauntsaninja commented 1 year ago

Sure, was just matching style to preexisting code

hauntsaninja commented 1 year ago

Just to be explicit: atugushev suggested I don't work on this PR until https://github.com/jazzband/pip-tools/pull/1681 is merged. This makes sense to me, since the two conflict.

webknjaz commented 9 months ago

Hey @hauntsaninja, that PR was merged about a month ago. So it seems like this one can be considered unblocked.

hauntsaninja commented 9 months ago

Thanks for the nudge, I've rebased the changes on top of main

webknjaz commented 9 months ago

Ah, I was just cleaning up the old notification emails and noticed this..

Since this looks up the [build-system] section, I think @apljungquist should be invited to review too.

webknjaz commented 9 months ago

Could you also include more information regarding the motivation, use case, possible side effects, usage examples etc. into the PR description? Make sure all of those are also present as tests.

webknjaz commented 9 months ago

Oh, and it looks like the contributor checklist might've been overlooked, could you verify?

hauntsaninja commented 8 months ago

Thanks for the initial review! I pushed a bunch of changes; this should now be much closer to shippable

chrysle commented 6 months ago

@webknjaz Could you review again? This is a larger change, so I wouldn't like to merge this on my own.

hauntsaninja commented 5 months ago

Thank you for the reviews!

chrysle commented 5 months ago

Thanks, I was about to suggest the same! Could you rebase properly?

hauntsaninja commented 5 months ago

fixed the test and ungoofed the git!

chrysle commented 5 months ago

Great, thank you for the contribution!

charliermarsh commented 5 months ago

Just as a heads up, since we struggle with a similar thing in uv, I think this will error on Hatch projects that use Hatch's context formatting. Here's an example: https://github.com/astral-sh/uv/blob/ae35a215c67a161e759769b832b99740f4ecad69/scripts/packages/root_editable/pyproject.toml.

If I run from main, I get:

❯ pip-compile ../uv/scripts/packages/root_editable/pyproject.toml
Traceback (most recent call last):
  File "/Users/crmarsh/workspace/pip-tools/.venv/bin/pip-compile", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/crmarsh/workspace/pip-tools/.venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/.venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/.venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/.venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/.venv/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/piptools/scripts/compile.py", line 365, in cli
    metadata = build_project_metadata(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/piptools/build.py", line 155, in build_project_metadata
    project_metadata = maybe_statically_parse_project_metadata(src_file)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/piptools/build.py", line 92, in maybe_statically_parse_project_metadata
    InstallRequirement(Requirement(req), comes_from)
                       ^^^^^^^^^^^^^^^^
  File "/Users/crmarsh/workspace/pip-tools/.venv/lib/python3.12/site-packages/pip/_vendor/packaging/requirements.py", line 117, in __init__
    raise InvalidRequirement(f"Invalid URL: {req.url}")
pip._vendor.packaging.requirements.InvalidRequirement: Invalid URL: {root:uri}/../black_editable
hauntsaninja commented 5 months ago

Hmm that's a violation of standards. It should probably declare dependencies as dynamic, or not use PEP 621

charliermarsh commented 5 months ago

Yeah, there's a discussion on it here if you'd like to chime in: https://github.com/pypa/hatch/issues/1331