Skip to content

Commit

Permalink
build setup (#33)
Browse files Browse the repository at this point in the history
* build setup

* fixes
  • Loading branch information
crflynn authored Jun 3, 2020
1 parent fb84ed8 commit 063866c
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 45 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git/
.github/
.idea/
.pytest_cache/
.venv/
build/
dist/
cython_debug/
htmlcov/
*.egg-info/
.coverage
.DS_Store
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,7 @@ cython_debug/

# ignore cython autogenerated files
skranger/ensemble/ranger.cpp
skranger/ensemble/ranger.html
skranger/ensemble/ranger.html

# src copy to deal with symlinks
skranger/ensemble/ranger/
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Use the python slim image
FROM python:3.8.3-slim

# Add build deps for python packages
# curl to install vendored poetry
# g++ to build sksurv
RUN apt-get update && \
apt-get install curl g++ -y && \
apt-get clean

# Set the working directory to app
WORKDIR /app

# Set the poetry version explicitly
ENV POETRY_VERSION=1.0.5
# Unbuffer the logger so we always get logs
ENV PYTHONUNBUFFERED=1
# Update the path for poetry python
ENV PATH=/root/.poetry/bin:/root/.local/bin:$PATH

# Install vendored poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

# Add dep configs
ADD ./pyproject.toml .
ADD ./poetry.lock .

# Install packages
# Disable virtualenv creation so we just use the already-installed python
RUN poetry config virtualenvs.create false && \
poetry run pip install -U pip && \
poetry install && \
rm -r ~/.cache/pip

# Add everything
ADD . .

# Set the entrypoint to poetry
ENTRYPOINT ["poetry"]
31 changes: 30 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ build:
poetry run python build.py clean
poetry run python build.py build_ext --inplace --force

.PHONY: copy
copy:
poetry run python buildpre.py

.PHONY: dist
dist: copy
poetry build

.PHONY: docker
docker:
docker build -t skranger .

.PHONY: linux
linux: copy docker
docker run --rm -v $(shell pwd)/dist:/app/dist:rw skranger build

.PHONY: docs
docs:
cd docs && \
Expand All @@ -15,7 +31,20 @@ fmt:
poetry run isort -y
poetry run black .

.PHONY: sdist
sdist: copy
poetry build -f sdist

.PHONY: setup
setup:
git submodule init
git submodule update
asdf install
poetry install --no-root
poetry run python buildpre.py
poetry install

.PHONY: test
test:
poetry run pytest --cov=skranger --cov-report=html tests/
open htmlcov/index.html
open htmlcov/index.html
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,18 @@ License
-------

``skranger`` is licensed under `GPLv3 <https://github.com/crflynn/skranger/blob/master/LICENSE.txt>`__.

Development
-----------

To develop locally, it is recommended to have ``asdf``, ``make`` and a C++ compiler already installed. After cloning, run ``make setup``. This will setup the ranger submodule, install python and poetry from ``.tool-versions``, install dependencies using poetry, copy the ranger source code into skranger, and then build and install skranger in the local virtualenv.

To format code, run ``make fmt``. This will run isort and black against the .py files.

To run tests and inspect coverage, run ``make test``.

To rebuild in place after making changes, run ``make build``.

To create python package artifacts, run ``make dist``.

To build and view documentation, run ``make docs``.
11 changes: 6 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

# skranger project directory
top = os.path.dirname(os.path.abspath(__file__))
# the cpp source code
ranger_src = os.path.join("ranger", "src")

# include skranger, ranger, and numpy headers
# requires running buildpre.py to find src in this location
include_dirs = [
top,
os.path.join(top, "skranger"),
os.path.join(top, "skranger", "ensemble"),
os.path.join(top, ranger_src),
os.path.join(top, "skranger", "ensemble", "ranger", "src"),
os.path.join(top, "skranger", "ensemble", "ranger", "src", "Forest"),
os.path.join(top, "skranger", "ensemble", "ranger", "src", "Tree"),
os.path.join(top, "skranger", "ensemble", "ranger", "src", "utility"),
np.get_include(),
]

Expand Down Expand Up @@ -58,7 +59,7 @@ def create_extension(module_name):

setup(
ext_modules=cythonize(
ext_modules, gdb_debug=False, force=True, annotate=True, compiler_directives={"language_level": "3"}
ext_modules, gdb_debug=False, force=True, annotate=False, compiler_directives={"language_level": "3"}
)
)

Expand Down
18 changes: 18 additions & 0 deletions buildpre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import shutil

top = os.path.dirname(os.path.abspath(__file__))


def copy_ranger_source():
"""Copy the ranger cpp source, following symlinks."""
src = os.path.join(top, "ranger", "cpp_version")
dst = os.path.join(top, "skranger", "ensemble", "ranger")
try:
shutil.rmtree(dst)
except FileNotFoundError:
pass
shutil.copytree(src, dst, symlinks=False)


copy_ranger_source()
16 changes: 8 additions & 8 deletions poetry.lock

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

13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ readme = "README.rst"
homepage = "https://github.com/crflynn/skranger"
repository = "https://github.com/crflynn/skranger"
documentation = "https://github.com/crflynn/skranger"
include = ["skranger/ensemble/ranger/**/*"]
build = "build.py"
keywords = ["random", "forest", "ranger", "machine", "learning"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
]

[tool.poetry.dependencies]
python = "^3.6.1"
Expand All @@ -61,6 +72,6 @@ pandas = "^1.0.3"
pytest-cov = "^2.9.0"

[build-system]
requires = ["poetry>=0.12"]
requires = ["poetry>=0.12", "cython==3.0a5", "numpy>=1.18.3"]
build-backend = "poetry.masonry.api"

Loading

0 comments on commit 063866c

Please sign in to comment.