Skip to content

Commit

Permalink
Fix building for Python version (#3)
Browse files Browse the repository at this point in the history
* Update poetry and lock file

* Fix wheel building for all Python versions
Bump version

* Add testing
  • Loading branch information
AHemmerShift authored Nov 19, 2024
1 parent 22b7476 commit 796cd57
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"image": "quay.io/pypa/manylinux2014_x86_64",
"customizations": {
"vscode": {
"extensions": [
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ cython_debug/
#.idea/

# Automatically generated
setup.py
setup.py

# Wheel directories
wheelhouse/
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
"cmath": "cpp",
"optional": "cpp"
},
"python.linting.enabled": false
"python.linting.enabled": false,
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"*_test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM quay.io/pypa/manylinux2014_x86_64

# Install poetry
RUN curl -sSL https://install.python-poetry.org | /opt/python/cp310-cp310/bin/python3 - && \
ln -s /root/.local/bin/poetry /usr/local/bin/poetry

# Set working directory
WORKDIR /app

# Copy project files
COPY . .

# Create directory for wheels
RUN mkdir -p /app/wheelhouse && chmod +x /app/build_wheels.sh

# Default command to build wheels
CMD ["/app/build_wheels.sh"]
4 changes: 3 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def build(setup_kwargs):
[Pybind11Extension(
"lazyk",
['src/lazyk_pybind.cpp', 'src/lazyk.cpp'],
extra_compile_args=['-O3', '-pthread'],
extra_compile_args=['-O3', '-pthread', '-fvisibility=hidden'],
extra_link_args=['-fvisibility=hidden'],
define_macros=[('VERSION_INFO', '"0.1.2"')],
language='c++',
cxx_std=11
)],
Expand Down
19 changes: 19 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e # Exit on any error

# Build the Docker image
echo "Building Docker image..."
docker build -t lazyk-builder .

# Create wheelhouse directory if it doesn't exist
mkdir -p wheelhouse

# Build the wheels
echo "Building wheels..."
docker run --rm -v $(pwd):/app lazyk-builder

# List the built wheels
echo "Built wheels:"
ls -l wheelhouse/

echo "Build complete! Wheels are in ./wheelhouse/"
14 changes: 14 additions & 0 deletions build_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Install dependencies and build wheels for each Python version
for PYBIN in /opt/python/cp3*/bin; do
"${PYBIN}/pip" install poetry pybind11 numpy cython wheel setuptools
"${PYBIN}/poetry" config virtualenvs.create false
"${PYBIN}/poetry" install --no-root
"${PYBIN}/poetry" build -f wheel
done

# Bundle external shared libraries into the wheels
for whl in dist/*.whl; do
auditwheel repair "$whl" --plat manylinux2014_x86_64 -w /app/wheelhouse/
done
126 changes: 62 additions & 64 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -e # Exit on any error

# Parse command line arguments
IS_TEST=false
if [ "$1" == "--test" ]; then
IS_TEST=true
fi

# Set credentials based on environment
if [ "$IS_TEST" = true ]; then
USERNAME="$PYPI_TEST_USERNAME"
PASSWORD="$PYPI_TEST_PASSWORD"
REPO="https://test.pypi.org/legacy/"
echo "Using TestPyPI environment..."
else
USERNAME="$PYPI_USERNAME"
PASSWORD="$PYPI_PASSWORD"
REPO="https://upload.pypi.org/legacy/"
echo "Using production PyPI environment..."
fi

# Check if credentials are set
if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
echo "Please set $([ "$IS_TEST" = true ] && echo "PYPI_TEST_USERNAME and PYPI_TEST_PASSWORD" || echo "PYPI_USERNAME and PYPI_PASSWORD") environment variables"
exit 1
fi

# Install twine if not already installed
pip install --upgrade twine

# Check the distribution files
echo "Checking distribution files..."
twine check wheelhouse/*

# Prompt for confirmation
echo "Ready to upload to PyPI. Please confirm (y/n)"
read -r confirm
if [ "$confirm" != "y" ]; then
echo "Upload cancelled"
exit 1
fi

# Upload to PyPI
echo "Uploading to $([ "$IS_TEST" = true ] && echo "TestPyPI" || echo "PyPI")..."
twine upload --repository-url "$REPO" --username "$USERNAME" --password "$PASSWORD" wheelhouse/*

echo "Upload complete!"
Loading

0 comments on commit 796cd57

Please sign in to comment.