Skip to content

Commit

Permalink
Merge pull request #93 from gmrukwa/poetry-fixup
Browse files Browse the repository at this point in the history
Poetry fixup
  • Loading branch information
gmrukwa committed Aug 22, 2023
2 parents 7097957 + 3c4ad93 commit 1b34ba4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 33 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install LLVM
run: brew install llvm
if: matrix.os == 'macos-latest'
- name: Install OpenMP
run: brew install libomp
if: matrix.os == 'macos-latest'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgomp1
if: matrix.os == 'ubuntu-latest'
- name: Setup poetry
run: |
pip install poetry poetry-core
Expand Down Expand Up @@ -144,6 +155,7 @@ jobs:
yum install -y hdf5-devel && \
pip install --upgrade pip && \
pip install poetry poetry-core && \
poetry run pip install oldest-supported-numpy && \
poetry install && \
poetry build -f wheel && \
deactivate'
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ jobs:
yum install -y hdf5-devel && \
pip install --upgrade pip && \
pip install poetry poetry-core && \
poetry install && \
poetry run pip install oldest-supported-numpy && \
poetry install -vvv && \
poetry run pytest && \
deactivate'
Expand All @@ -68,7 +69,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libgomp1
poetry install
poetry install -vvv
- name: Test library
run: poetry run pytest
env:
Expand All @@ -93,7 +94,7 @@ jobs:
- name: Setup poetry
uses: abatilo/actions-poetry@v2.2.0
- name: Install dependencies
run: poetry install
run: poetry install -vvv
- name: Test library
run: poetry run pytest
env:
Expand All @@ -115,6 +116,8 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install LLVM
run: brew install llvm
- name: Install OpenMP
run: brew install libomp
- name: Setup poetry
Expand All @@ -126,7 +129,7 @@ jobs:
echo "CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include:$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV
echo "LIBRARY_PATH=/usr/local/opt/llvm/lib:/usr/local/opt/libomp/lib:$LIBRARY_PATH" >> $GITHUB_ENV
echo "DYLD_LIBRARY_PATH=/usr/local/opt/llvm/lib:/usr/local/opt/libomp/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
poetry install
poetry install -vvv
env:
CC: /usr/local/opt/llvm/bin/clang
CXX: /usr/local/opt/llvm/bin/clang++
Expand Down
20 changes: 18 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
import sys
from glob import glob

import numpy
from setuptools import Extension

################################################
# Hack for https://github.com/python-poetry/poetry/issues/6154#issue-1336927568

import subprocess

try:
import numpy
except ImportError:
subprocess.run(["pip", "install", "oldest-supported-numpy"])


import numpy


################################################

LINUX_OPTS = {
"extra_link_args": [
"-fopenmp",
Expand Down Expand Up @@ -54,7 +69,8 @@ def build(setup_kwargs):
sources=glob("gamred_native/*.c"),
include_dirs=["gamred_native", numpy.get_include()],
define_macros=[
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),
("NPY_NO_DEPRECATED_API", None),
("NPY_1_7_API_VERSION", None),
],
**OPTS,
),
Expand Down
34 changes: 10 additions & 24 deletions docker/unittest.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,23 @@ RUN apt-get update &&\

FROM base as builder
SHELL ["/bin/bash", "-c"]
RUN mkdir -p /install/lib/python3.9/site-packages
ENV PYTHONPATH .:/install/lib/python3.9/site-packages
RUN apt-get update &&\
apt-get install -y gcc curl &&\
rm -rf /var/lib/apt/lists/*
ENV POETRY_HOME="/opt/poetry"
RUN curl -sSL https://install.python-poetry.org | python -
ENV PATH="${POETRY_HOME}/bin:${PATH}"
RUN poetry config virtualenvs.create false


FROM builder AS deps_builder
COPY . /app
RUN poetry install &&\
poetry build


FROM builder AS deps_install
COPY --from=deps_builder /app/dist /app/dist
COPY requirements-dev.txt requirements-dev.txt
RUN pip install -r requirements-dev.txt \
--prefix=/install \
--no-cache-dir \
--no-warn-script-location &&\
pip install /app/dist/divik*.whl \
--prefix=/install \
--no-cache-dir \
--no-warn-script-location


FROM base
FROM builder
ENV ENABLE_SLOW_TESTS True
COPY --from=deps_install /install /usr/local
COPY requirements-dev.txt requirements-dev.txt
COPY pyproject.toml pyproject.toml
COPY poetry.lock poetry.lock
RUN poetry install
COPY . /app
RUN pytest
RUN poetry run pip freeze | grep numpy
RUN poetry install
RUN poetry build
RUN poetry run pytest
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "divik"
version = "3.2.2"
version = "3.2.3"
description = "Divisive iK-means algorithm implementation"
authors = ["Grzegorz Mrukwa <g.mrukwa@gmail.com>"]
license = "Apache-2.0"
Expand All @@ -26,7 +26,10 @@ classifiers = [
include = [
"gamred_native",
]
build = "build.py"

[tool.poetry.build]
script = "build.py"
generate-setup-file = true

[tool.poetry.dependencies]
python = ">=3.7.1,<4.0"
Expand Down Expand Up @@ -71,7 +74,7 @@ fit-clusters = "divik._cli.fit_clusters:main"
[build-system]
requires = [
"poetry-core>=1.0.0",
"numpy>=0.12.1",
"oldest-supported-numpy",
"setuptools",
]
build-backend = "poetry.core.masonry.api"

0 comments on commit 1b34ba4

Please sign in to comment.