Skip to content

Commit

Permalink
Packaging support; first steps towards PyPi
Browse files Browse the repository at this point in the history
This will also let us fix readthedocs, since it cannot build our
C++ code, but it _CAN_ install from pip.
  • Loading branch information
dcdehaas committed Oct 7, 2024
1 parent 055838b commit f1d4cae
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Dockerfile.pkg1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:20.04

RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y python3 python3.8-venv python3.9 python3.9-venv python3-setuptools python3-pip git build-essential cmake wget python3.9-dev
RUN cd /tmp \
&& wget https://github.com/Kitware/CMake/releases/download/v3.30.4/cmake-3.30.4-linux-x86_64.tar.gz \
&& tar -xf cmake-3.30.4-linux-x86_64.tar.gz \
&& cp -r cmake-3.30.4-linux-x86_64/bin/* /usr/local/bin/ \
&& cp -r cmake-3.30.4-linux-x86_64/man/* /usr/local/man/ \
&& cp -r cmake-3.30.4-linux-x86_64/share/* /usr/local/share/

COPY . /grgl_src

ENV PATH="/grgl_src/Env38/bin:$PATH"
# Build the Python 3.8 wheel
RUN cd /grgl_src \
&& python3.8 -m venv Env38 \
&& pip3 install wheel \
&& GRGL_GSL=1 GRGL_BGEN=1 python setup.py bdist_wheel
ENV PATH="/grgl_src/Env39/bin:$PATH"
# Build the Python 3.9 wheel
RUN cd /grgl_src \
&& python3.9 -m venv Env39 \
&& pip3 install wheel \
&& GRGL_GSL=1 GRGL_BGEN=1 python setup.py bdist_wheel
# Copy to an easily accesible location
RUN mkdir /output && cp /grgl_src/dist/*.whl /output/
21 changes: 21 additions & 0 deletions Dockerfile.pkg2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:22.04

RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y python3.10 python3.10-venv python3.10-dev python3.11 python3.11-venv python3.11-dev python3-setuptools python3-pip git build-essential cmake wget

COPY . /grgl_src

ENV PATH="/grgl_src/Env310/bin:$PATH"
# Build the Python 3.10 wheel
RUN cd /grgl_src \
&& python3.10 -m venv Env310 \
&& pip3 install wheel \
&& GRGL_GSL=1 GRGL_BGEN=1 python setup.py bdist_wheel
ENV PATH="/grgl_src/Env311/bin:$PATH"
# Build the Python 3.11 wheel
RUN cd /grgl_src \
&& python3.11 -m venv Env311 \
&& pip3 install wheel \
&& GRGL_GSL=1 GRGL_BGEN=1 python setup.py bdist_wheel
# Copy to an easily accesible location
RUN mkdir /output && cp /grgl_src/dist/*.whl /output/
44 changes: 44 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Releasing new GRGL versions

This outlines the steps for releasing a new GRGL version.

## Version numbering

Bug fixes and minor non-breaking changes do not require a version number bump. Yes, this means that folks who installed via `pip` will not get an updated version unless they `--force-reinstall` or remove and then reinstall. If the bug/change is significant, then bump the minor version.

* Minor version number bump occurs for non-breaking changes.
* Major version number bump occurs for breaking changes. Breaking changes are considered non-backwards-compatible file format changes or breaking changes to the Python API. Breaking changes are allowed to the C++ API without bumping the major version number.

Steps:
* Update `include/grgl/version.h`
* Update `setup.py` to have the new version
* After merging to `main` and ensuring all CI passes (and testing prior to that), run the steps for PyPi below

## Packaging for PyPi

Build the package distributions for PyPi. We build a source dist and then Linux binary distributions for recent Python versions.

```
# Remove dist/ to start fresh
rm -rf dist
# Build the source distribution (for MacOS, mostly)
python setup.py sdist
# Build the Python3.8 and Python3.9 packages on an older Docker image
docker build . -f Dockerfile.pkg1 -t grgl_pkg1:latest
docker run -v $PWD/dist:/dist -it grgl_pkg1:latest bash -c "cp /output/*.whl /dist/"
# Build the Python3.10+ packages on a newer Docker image
docker build . -f Dockerfile.pkg2 -t grgl_pkg2:latest
docker run -v $PWD/dist:/dist -it grgl_pkg2:latest bash -c "cp /output/*.whl /dist/"
# Fix file permissions from Docker
sudo chown ddehaas dist/*.whl
sudo chgrp ddehaas dist/*.whl
```

To upload to PyPi, ensure that your dist directory is clean (only has the packages you _just_ built), then upload via twine:
```
python3 -m twine upload dist/*
```
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
breathe
sphinx-rtd-theme
pygrgl
2 changes: 1 addition & 1 deletion include/grgl/version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define GRGL_MAJOR_VERSION 1
#define GRGL_MINOR_VERSION 0
#define GRGL_MINOR_VERSION 1
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ def __init__(self, name, cmake_lists_dir=".", sources=[], extra_executables=[],
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
self.extra_executables = extra_executables

def all_files(dir_name):
result = []
for root, dirs, files in os.walk(dir_name):
for f in files:
result.append(os.path.join(root, f))
return result

class CMakeBuild(build_ext):
def get_source_files(self):
return (["CMakeLists.txt", ] + all_files("src/") + all_files("include/") + all_files("third-party/")
+ all_files("extra/") + all_files("test/"))

def build_extensions(self):
try:
out = subprocess.check_output(["cmake", "--version"])
Expand Down

0 comments on commit f1d4cae

Please sign in to comment.