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

22.5.0: pep517 build fails because is requires hatch-fancy-pypi-readme during build #13

Closed
kloczek opened this issue Sep 10, 2022 · 27 comments

Comments

@kloczek
Copy link

kloczek commented Sep 10, 2022

Looks like now hatch-fancy-pypi-readme requires its own code to pass pep517 build

+ /usr/bin/python3 -sBm build -w --no-isolation
* Getting dependencies for wheel...

ERROR Missing dependencies:
        hatch-fancy-pypi-readme>=22.4.0

Why not use during build `hatch-fancy-pypi-readme1 code from build tree? 🤔

@ofek
Copy link
Contributor

ofek commented Sep 10, 2022

Works for me:

❯ python -m build -w
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (hatch-fancy-pypi-readme>=22.4.0, hatchling)
* Getting dependencies for wheel...
* Building wheel...
Successfully built hatch_fancy_pypi_readme-22.6.0.dev0-py3-none-any.whl

@kloczek
Copy link
Author

kloczek commented Sep 10, 2022

So you have installed in build env hatch-fancy-pypi-readme>=22.4.0.
I cannot build 22.0.4 either ..

But again: code of requires version is in build tree and many other modules is possible to build self bootstrapping (whey, build)

@ofek
Copy link
Contributor

ofek commented Sep 10, 2022

This isn't a build backend it's a plugin

@kloczek
Copy link
Author

kloczek commented Sep 10, 2022

hatch-fancy-pypi-readme is required in exact minimum version so it cannot be used over PYTHONPATH=$PWD/src python -m build -w --no-isolation because in src/ there is no module metadata.
Other thing is that evebn after build it will be no metadata in src/ because hatchling as same as whey and poetry is not producing metadata in any other place than generated .whl archive.

It works for you because you executed build without --no-isolation which is causing that missing hatch-fancy-pypi-readme*.whl is downloaded duting build execution from pypi repo.
Try use that with --no-isolation to relay only what you have installed in build env and before that please uninstall hatch-fancy-pypi-readme module.

@hynek
Copy link
Owner

hynek commented Sep 11, 2022

@ofek is there a way around this or is every distro gonna complain about this now? :-/

@kloczek
Copy link
Author

kloczek commented Sep 11, 2022

No as long as you are requiring in pyprojest.toml module build needs metadata of tjose mofdules somewhere in build env. Just checked my +1k spec files with python moduls. Try to have look on buildd, calver, dbusmockandflit` code. In those cases I've managed to prepare build procedure which would not require installed in build env those moduels by use

%build
export PYTHONPATH=$PWD/src
%pyproject_wheel

or

%build
export PYTHONPATH=$PWD
%pyproject_wheel

to break self dependencies.

@hynek
Copy link
Owner

hynek commented Sep 11, 2022

fixed by 2f17c36 💔

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

cc other Linux distro experts @musicinmybrain @frenzymadness @stefanor @hroncok

Is there really no way for a package to depend on itself? I wanted Hatchling to start using hatch-vcs so I can version using Git. Is that impossible?

@hroncok
Copy link

hroncok commented Sep 11, 2022

It should be possible to:

  1. not list the self-dependency
  2. use the https://peps.python.org/pep-0517/#in-tree-build-backends feature

@Czaki
Copy link

Czaki commented Sep 11, 2022

Is there really no way for a package to depend on itself

it may be possible, but such a package cannot depend on itself in build-system.requires section so in the case of hatch there should be introduced to detect plugins stored locally in the filesystem, not only installed packages.

@hroncok
Copy link

hroncok commented Sep 11, 2022

or if there is a a Python way to "register" a hatch plugin, the build backend could be set to a local script that imports the plugin, registers it and "returns" the hatch backend

@Czaki
Copy link

Czaki commented Sep 11, 2022

@hroncok
Copy link

hroncok commented Sep 11, 2022

Pseudo-code:

[build-system]
requires = ["hatch"]
build-backend = "intree_plugin_loader:build"
backend-path = ["tools", "src"]
# tools/intree_plugin_loader.py

from hatchling import build as build_original
from hatch import register_plugin_xxx
__all__ = ['build']

def build(*args, **kwargs):
    register_plugin_xxx(...)
    return build_original(*args, **kwargs)

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

Ah okay I think I understand for Hatchling, ty! Though I don't understand why this package can't depend on an older version of itself for builds. The code is under src/ so imports would correctly use the old version, no?

@hroncok
Copy link

hroncok commented Sep 11, 2022

It can technically depend on itself only when it is already packaged as a wheel. It makes it impossible to bootstrap from the source. That it a distro maintainers' problem to solve but OTOH it's always nice to try to avoid it. I think some of the relevant PEPs discourages this but I am not entirely sure.

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

Ohhhh right distros build from source all the way down. I get it now, bummer. Thank you!

@hroncok
Copy link

hroncok commented Sep 11, 2022

PEP 517 even forbids this, see https://www.python.org/dev/peps/pep-0517/#build-requirements

Project build requirements will define a directed graph of requirements (project A needs B to build, B needs C and D, etc.) This graph MUST NOT contain cycles. If (due to lack of co-ordination between projects, for example) a cycle is present, front ends MAY refuse to build the project.

However front ends MAY have modes where they do not consider wheels when locating build requirements, and so projects MUST NOT assume that publishing wheels is sufficient to break a requirement cycle.

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

I do wonder if by cycle it implicitly means package only or the traditional package + version.

@hroncok
Copy link

hroncok commented Sep 11, 2022

See the discussion in pypa/wheel#429 for some details.

@Czaki
Copy link

Czaki commented Sep 11, 2022

PEP 517 even forbids this, see

It does not. It prohibits making cycles, not depending on local code.

@hroncok
Copy link

hroncok commented Sep 11, 2022

Yes. "depending on self" is a cycle. I was answering to

I don't understand why this package can't depend on an older version of itself

@Czaki
Copy link

Czaki commented Sep 11, 2022

Agree. On the older version is a cycle. It will be nice to have some citations or paraphrases for context.

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

So to make this work:

  1. Hatchling needs a way to load plugins based on file system paths rather than just relying on entry points metadata (this will be tough but doable)
  2. This project would change to:
    [build-system]
    requires = ["hatchling"]
    build-backend = "hatchling.build"
    backend-path = ['src']

Does that sound right?

@hroncok
Copy link

hroncok commented Sep 11, 2022

That is a way to do it. Maybe hatch could have a configuration section that would made the plugin lookup from sys.path more explicit.

@hroncok
Copy link

hroncok commented Sep 11, 2022

I got an idea: Since the configuration already has:

[project.entry-points.hatch]
fancy-pypi-readme = "hatch_fancy_pypi_readme.hooks"

Hatch could also load the plugin entrypoints from the pyproject.toml it is reading. That should be easier than "a way to load plugins based on file system paths"

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

Clever! I will do that 🚀

@ofek
Copy link
Contributor

ofek commented Sep 11, 2022

To confirm, my plan is to load all project.entry-points.hatch if build-system.backend-path is defined.

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

No branches or pull requests

5 participants