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

Binary app error: Could not find a version that satisfies the requirement #1436

Open
PhilipVinc opened this issue Apr 27, 2024 · 4 comments
Open

Comments

@PhilipVinc
Copy link

Hello,

I tried to setup a project using hatch/pyapp, but after building the project with pyapp (which completes successfully) I keep getting the following error.

ERROR: Could not find a version that satisfies the requirement test_app==0.0.1 (from versions: none)
ERROR: No matching distribution found for test_app ==0.0.1

The steps I followed where to create a project with hatch init test_app then edit the pyproject.toml by adding those two lines

[project.scripts]
test_app = "test_app:main"

[tool.hatch.build.targets.binary]
test_app = ["test_app"]

and then build the app with hatch build --target binary.

I am on macOS.

Is this somehow known? Do you have some ideas on what I could try to do to fix it?

@PhilipVinc
Copy link
Author

After considerate effort googling in GitHub, I found out that with the following script I am able to generate some build-in images that work...

#!/usr/bin/env bash
current_version=$(hatch version)
hatch build
PYAPP_UV_ENABLED="1" PYAPP_PROJECT_PATH="$(ls ${PWD}/dist/test_app-${current_version}-py3-none-any.whl)" PYAPP_DISTRIBUTION_EMBED="1" hatch build -t binary

Nevertheless, I'm unsure of how this happens to work while the other does not.

@J-qak
Copy link

J-qak commented Jul 17, 2024

I can confirm I have same issue, this doesn't work right out of the box and I wasn't able to find many resources.
Apparently only way is to introduce environmental variables for pyapp, thank you @PhilipVinc for the example script.

It would be nice if these settings could be configured directly in pyproject.toml in [tool.hatch.build.targets.binary] instead of environmental variables.

@Tobi-De
Copy link

Tobi-De commented Jul 23, 2024

Having the same issue here

It would be nice if these settings could be configured directly in pyproject.toml in [tool.hatch.build.targets.binary] instead of environmental variables.

good idea imo, @ofek

@mmorys
Copy link

mmorys commented Aug 27, 2024

I've been struggling with the same issue, thinking it was something wrong with my configuration. Indeed it seems to be a bug with the binary plugin to hatch build. I need to use the method @PhilipVinc used to first build an sdist/wheel, set that as the PYAPP_PROJECT_PATH, and finally use hatch build -t binary.

Here is a workaround I came up with for the time being for a one-liner binary build in a separate environment:

# pyproject.toml snippet
[project.scripts]
run-test-app = "test_app:main"

[tool.hatch.build.targets.binary]
scripts = ["run-test-app"]

[tool.hatch.envs.build]
detached = true
[tool.hatch.envs.build.env-vars]
PYAPP_DISTRIBUTION_EMBED = "true"
PYAPP_PROJECT_PATH = "{root}/dist/test_app.tar.gz"
PYAPP_UV_ENABLED = "true"
PYAPP_PYTHON_VERSION = "3.11"
[tool.hatch.envs.build.scripts]
binary = [
 "hatch build -c -t sdist",
 "mv {root}/dist/test_app-*.tar.gz {root}/dist/test_app.tar.gz",
 "hatch build -t binary"
]
# Shell command to compile binary
$ hatch run build:binary

This requires a separate environment to set up for the build environment to do it's thing, which is redundant, but works for now.


Here is what I think it should look like once it's fixed, with all the PyApp options exposed as binary build plugin options, and the project being built and installed in the compiled binary:

[tool.hatch.build.targets.binary]
scripts = ["run-test-app"]
distribution-embed = "true"
uv-enabled = "true"
python-version = "true"

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

4 participants