-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
Fix hardcoded reliance on pip #1882
base: master
Are you sure you want to change the base?
Changes from 2 commits
f24bce9
b1838f8
306dd82
a565a5f
8dca06c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDIT: This test is passing confirming this works, it will fail if you swap FROM fedora:latest
RUN dnf install -y git
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN uv python install 3.12
RUN uv tool install git+https://github.com/vpetrigo/hatch.git@fix/hardcoded-reliance-on-pip
ENV PATH="/root/.local/bin:${PATH}"
WORKDIR /work
RUN touch /work/pyproject.toml
RUN cat <<EOF > /work/pyproject.toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "foo"
version = "0.0.1"
dependencies = ["requests"]
[tool.hatch.env]
requires = [
"hatch-pip-compile"
]
[tool.hatch.envs.default]
installer = "uv"
type = "pip-compile"
pip-compile-resolver = "uv"
pip-compile-installer = "uv"
EOF
RUN mkdir /work/foo
RUN touch /work/foo/__init__.py
CMD ["hatch", "run", "head", "requirements.txt"] docker build . --tag hatch-pip-compile-test
docker run --rm -it hatch-pip-compile-test #
# This file is autogenerated by hatch-pip-compile with Python 3.12
#
# - requests
#
certifi==2024.12.14
# via requests
charset-normalizer==3.4.1
# via requests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually fails now since we've replaced Looks like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rolled back for now to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What may work is the following command: uv_bin = find_uv_bin()
pip_command = [uv_bin, 'pip']
pip_command.extend(['install', '--directory', str(pathlib.Path(sys.executable).parent.parent)]) Not sure if it is more reliable than calling a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed those changes for review just in the case that approach with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about two options that would work here: The first option essentially calls pip_command = [sys.executable, "-m", "uv", "pip"]
pip_command.extend(["install"]) The second option is to call the uv_binary = find_uv_bin()
pip_command = [uv_binary, "pip"]
pip_command.extend(["install", "--python", sys.executable]) Honestly, I think both of these options do the same thing 🤷 - I'm fine with whatever you and Ofek like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the implementation for the last option with passing |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,9 +160,9 @@ def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_me | |
if dependencies_in_sync(dependencies): | ||
return | ||
|
||
pip_command = [sys.executable, '-u', '-m', 'pip'] | ||
pip_command = [sys.executable, '-u', '-m', 'uv', 'pip'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
from uv import find_uv_bin
...
uv_bin = find_uv_bin()
pip_command = [uv_bin, '-u', '-m', 'pip'] This likely works the same though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated! |
||
|
||
pip_command.extend(['install', '--disable-pip-version-check', '--no-python-version-warning']) | ||
pip_command.extend(['install']) | ||
|
||
# Default to -1 verbosity | ||
add_verbosity_flag(pip_command, self.verbosity, adjustment=-1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, I was imagining the fix for this would be some complicated piece of work - but this is a really nice, targeted swap of
pip
foruv pip
only inensure_plugin_dependencies