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

Preliminary support for Pixi projects using pyproject.toml #455

Merged
merged 9 commits into from
Oct 7, 2024

Conversation

jherland
Copy link
Member

@jherland jherland commented Sep 9, 2024

NOTE: We do not currently differentiate between Conda dependencies and PyPI dependencies, meaning that we assume that a Conda dependency named FOO will map one-to-one to a Python package named FOO. This is certainly not true for Conda dependencies that are not Python packages, and it probably isn't even true for all Conda dependencies that do indeed include Python packages.

Commits:

  • parse_requirements_txt: Add debug log messages for invalid lines
  • parse_pyproject_toml: Support Pixi dependencies
  • parse_pyproject_toml: Support Pixi pypi-dependencies
  • parse_pyproject_toml: Support Pixi "feature" dependencies
  • parse_pyproject_toml: Support Pixi "feature" pypi-dependencies
  • parse_pyproject_toml: Ignore Pixi's self-dependency
  • Add more Pixi tests
  • Talk about Pixi in our docs
  • sample_projects: Add Pixi project using pyproject.toml

When invalid lines are found in a requirements.txt file, we used to
silently ignore them. With this, we still ignore them, but we now log a
debug message so that it is easier for inquisitive users to see what's
happening.
Add preliminary support for parsing Conda dependencies in the
[tool.pixi.dependencies] section of pyproject.toml. This is used by Pixi
to declare mandatory dependencies that are taken from the Conda
ecosystem (rather than the PyPI ecosystem).

One complication of Pixi dependencies is that if a dependency is listed
_both_ as a PyPI dependency (in the standard PEP621 location) and as a
Conda dependency in the [tool.pixi.dependencies] table, then the latter
takes precedence.

NOTE: We do not currently differentiate between Conda dependencies and
PyPI dependencies, meaning that we assume that a Conda dependency named
FOO will map one-to-one to a Python package named FOO. This is certainly
not true for Conda dependencies that are not Python packages, and it
probably isn't even true for all Conda dependencies that do indeed
include Python packages.

For now, we only make sure that the "same" dependency is not yielded
twice when it appears in both as a PyPI and Conda dependency.
In addition to accepting PyPI dependencies in the standard PEP621
[project.dependencies] table, Pixi also supports a separate
[tool.pixi.pypi-dependencies] table for these dependencies, e.g.:

    ```toml
    [project]
    name = "my_project"
    requires-python = ">= 3.9"

    [tool.pixi.project]
    channels = ["conda-forge"]
    platforms = ["linux-64"]

    [tool.pixi.pypi-dependencies]
    nump = "*"
    ```

(This section is also used for the editable self-dependency that Pixi
adds by default in its projects, but more on that in a later commit.)
Pixi uses the name "feature" to signify an optional dependency group.
They look very much like Poetry's dependency groups, and the "extras"
that are declared in PEP621's `optional-dependencies`, but contain
Conda dependencies rather than PyPI dependencies.

Add support for parsing them.

For now, FawltyDeps does not differentiate between mandatory and
optional dependencies: Dependencies from all feature sections are
parsed and returned.
@jherland jherland marked this pull request as ready for review September 10, 2024 10:09
@jherland jherland self-assigned this Sep 10, 2024
In addition to [tool.pixi.feature.NAME.dependencies] for declaring
optional Conda dependencies, Pixi completes the picture by also having
[tool.pixi.feature.NAME.pypi-dependencies] for declaring optional PyPI
dependencies (although this technically overlaps with the PEP621
[project.optional-dependencies]).
Pixi inserts this self-dependency by default in its projects:

    ```toml
    [project]
    name = "my_project"
    requires-python = ">= 3.9"

    [tool.pixi.project]
    channels = ["conda-forge"]
    platforms = ["linux-64"]

    [tool.pixi.pypi-dependencies]
    my_project = { path = ".", editable = true }
    ```

This self-dependency should NOT be considered a declared dependency,
but is rather a mechanism to produce an editable installation of the
project itself inside the environments that Pixi creates.

In general it probably does not make sense for FawltyDeps to accept
these self-dependencies, no matter how/where they are found?
This was created with the following commands:

  - pixi init --format pyproject pixi_pyproject_example
  - cd pixi_pyproject_example/
  - pixi add python
  - pixi add requests
  - pixi add --pypi fawltydeps
  - echo "import requests" > pixi_pyproject_example/__init__.py

followed by removing/truncating files that I do not currently consider
to be important for FawltyDeps to make sense of this project.

The result is a simple Pixi project with two declared Conda
dependencies (Python itself + requests) and one PyPI dependency
(fawltydeps), along with a single source file that imports requests.

The expected result of running FawltyDeps here is success (requests is
both declared and imported, fawltydeps is part of the default tool
exception, and Python itself is auto-ignored as a dependency).
@jherland jherland changed the title Preliminary support for Pixi project using pyproject.toml Preliminary support for Pixi projects using pyproject.toml Sep 11, 2024
@jherland jherland merged commit fc25862 into main Oct 7, 2024
63 checks passed
@jherland jherland deleted the jherland/pixi-support branch October 7, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[conda] Support Pixi's use of pyproject.toml to declare conda dependencies?
2 participants