Skip to content

feat: add pip builds #27

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

Merged
merged 2 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ ruby:
rust:
./test.sh quotes-app-rust

pip:
./test.sh quotes-app-pip


clean:
@for dir in $(shell ls -d */ | tr -d '/'); do \
Expand Down
1 change: 1 addition & 0 deletions quotes-app-pip/.flox/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/manifest.lock linguist-generated=true linguist-language=JSON
5 changes: 5 additions & 0 deletions quotes-app-pip/.flox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
run/
cache/
lib/
log/
!env/
1 change: 1 addition & 0 deletions quotes-app-pip/.flox/cache/upgrade-checks.json

Large diffs are not rendered by default.

Empty file.
4 changes: 4 additions & 0 deletions quotes-app-pip/.flox/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "quotes-app-pip",
"version": 1
}
413 changes: 413 additions & 0 deletions quotes-app-pip/.flox/env/manifest.lock

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions quotes-app-pip/.flox/env/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
version = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question nonblocking: do we want to rename quotes-app-python -> quotes-app-poetry?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, but I'd also like it to be *-python-poetry to be more descriptive.


[install]
python3.pkg-path = "python312"
pip.pkg-path = "python312Packages.pip"
setuptools.pkg-path = "python312Packages.setuptools"

[hook]
on-activate = """
# Autogenerated by Flox

# Setup a Python virtual environment

export PYTHON_DIR="$FLOX_ENV_CACHE/python"
if [ ! -d "$PYTHON_DIR" ]; then
echo "Creating python virtual environment in $PYTHON_DIR"
python -m venv "$PYTHON_DIR"
fi

# Quietly activate venv and install packages in a subshell so
# that the venv can be freshly activated in the profile section.
(
source "$PYTHON_DIR/bin/activate"
# install the dependencies for this project based on pyproject.toml
# <https://pip.pypa.io/en/stable/cli/pip_install/>
pip install -e .
)

# End autogenerated by Flox
"""

[profile]
bash = """
# Autogenerated by Flox

echo "Activating python virtual environment" >&2
source "$PYTHON_DIR/bin/activate"

# End autogenerated by Flox
"""
fish = """
# Autogenerated by Flox

echo "Activating python virtual environment" >&2
source "$PYTHON_DIR/bin/activate.fish"

# End autogenerated by Flox
"""
tcsh = """
# Autogenerated by Flox

echo "Activating python virtual environment" >&2
source "$PYTHON_DIR/bin/activate.csh"

# End autogenerated by Flox
"""
zsh = """
# Autogenerated by Flox

echo "Activating python virtual environment" >&2
source "$PYTHON_DIR/bin/activate"

# End autogenerated by Flox
"""

[build.quotes-app-pip]
command = '''
# Create a virtual environment for the project and its dependencies.
mkdir -p $out/libexec
python3 -m venv $out/libexec/venv
source $out/libexec/venv/bin/activate

# Install the project and its dependencies into the virtual environment
pip install .

# Symlink the project from the virtual environment into the `$out/bin`
# directory.
mkdir $out/bin
cd $out/bin
ln -s ../libexec/venv/bin/quotes-app-pip .

echo "OUT"
ls -al $out
echo
echo "LIBEXEC"
ls -al $out/libexec/venv/lib/python3.12/site-packages/pip-25.0.1.dist-info/
'''
runtime-packages = ["python3"]

[build.quotes-app-pip-deps]
command = '''
# Prevent install being a noop when run from an existing activation that
# already has the virtualenv and dependencies installed.
unset VIRTUAL_ENV

# The virtual environment is only needed to be able to run
# pip commands
mkdir -p $out/libexec
python3 -m venv $out/libexec/venv
source $out/libexec/venv/bin/activate

# Download wheels/source-dists of all of the dependencies
mkdir -p $out/libexec/deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
mkdir -p $out/libexec/deps
mkdir -p $out/deps

Is this only used by the pip install ${quotes-app-pip-deps}/libexec/deps/* command? libexec feels wrong to me. As this is only ever used by build.quotes-app-pip-pure, do we even need to follow FHS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend to users to use FHS, so I'm just following that convention.

pip download --dest $out/libexec/deps .

# We don't want/need to package the virtual environment in this step
rm -rf $out/libexec/venv
'''

[build.quotes-app-pip-pure]
command = '''
# Create a virtual environment for the project and its dependencies.
mkdir -p $out/libexec
python3 -m venv $out/libexec/venv
source $out/libexec/venv/bin/activate

# Install dependencies from the impure step
pip install ${quotes-app-pip-deps}/libexec/deps/*

# Install this project, skipping the deps we've just installed
pip install --no-build-isolation --no-deps .
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: This --no-build-isolation flag is required to prevent pip from downloading a new copy of setuptools for the build. It does that by default even if there's a copy of setuptools in the environment.


# Symlink the project from the virtual environment into the `$out/bin`
# directory.
mkdir $out/bin
cd $out/bin
ln -s ../libexec/venv/bin/quotes-app-pip quotes-app-pip-pure
'''
sandbox = "pure"
runtime-packages = ["python3"]
Loading
Loading