Skip to content

Commit

Permalink
Add dependencies for pyproject.toml (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
esloch authored Aug 23, 2022
1 parent 13ccf19 commit a512c2f
Show file tree
Hide file tree
Showing 34 changed files with 2,992 additions and 633,602 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ jobs:
with:
miniconda-version: "latest"
mamba-version: "*"
environment-file: conda/environment.yaml
environment-file: conda/dev.yaml
channels: conda-forge,nodefaults
activate-environment: env-pysus
use-mamba: true
miniforge-variant: Mambaforge

- name: Install dependencies
- name: Install Dependencies
run: |
make install
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
export PATH="$HOME/.poetry/bin:$PATH"
poetry config virtualenvs.create false && poetry build && poetry install
- name: Lint with flake8
run: |
make check-codestyle
- name: build and deploy jupyterlab
- name: Run jupyterlab with PySUS
run: |
make run-jupyter-pysus
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pyvenv.cfg
*.jupyter/
*.local/
*.mozilla/
*.ipynb_checkpoints*
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ repos:
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 21.9b0
hooks:
- id: black
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: ^dist/


- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
recursive-include pysus *.c *.h
include pysus/utilities/*
include pysus/utilities/c-src/*
include requirements.txt
27 changes: 20 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
SHELL=/bin/bash
SHELL := /usr/bin/env bash
PYTHON := python
PYTHONPATH := ${PWD}


.PHONY: clean clean-test clean-pyc clean-build help
.DEFAULT_GOAL := help
Expand All @@ -22,15 +25,24 @@ DOCKER = docker-compose -p pysus -f docker/docker-compose.yaml
SERVICE :=


#* Poetry
.PHONY: poetry-download
poetry-download:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | $(PYTHON) -

.PHONY: poetry-remove
poetry-remove:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | $(PYTHON) - --uninstall

#* Installation
.PHONY: install
install: clean ## install the package to the active Python's site-packages
python setup.py install
install:
poetry lock -n && poetry export --without-hashes > requirements.txt
poetry build && poetry install

.PHONY: pre-commit-install
develop-install: clean ## install the package in development mode
pip install -e '.[dev]'
pre-commit install
pre-commit-install:
poetry run pre-commit install

#* Linting
.PHONY: check-codestyle
Expand All @@ -56,7 +68,7 @@ test-jupyter-pysus: ## run pytest for notebooks inside jupyter container

.PHONY: test
test: ## run tests quickly with the default Python
py.test
poetry run pytest -vv pysus/tests/

coverage: ## check code coverage quickly with the default Python
coverage run --source pysus/tests/ -m pytest
Expand All @@ -79,6 +91,7 @@ clean-build: ## remove build artifacts
find . -name '*.mozilla' -exec rm -fr {} +
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.ipynb_checkpoints' -exec rm -rf {} +

.PHONY: clean-pyc
clean-pyc: ## remove Python file artifacts
Expand Down
12 changes: 12 additions & 0 deletions conda/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: env-pysus
channels:
- conda-forge
- nodefaults
dependencies:
- cffi
- docker-compose
- gcc
- make
- pip
- psycopg2
- python 3.9.*
30 changes: 0 additions & 30 deletions conda/environment.yaml

This file was deleted.

65 changes: 36 additions & 29 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,47 @@ USER root

ENV DEBIAN_FRONTEND=noninteractive

ENV HOME "/home/pysus"
ENV PATH "$PATH:/home/pysus/.local/bin"
ENV ENV_NAME base
ENV PATH "/opt/conda/envs/$ENV_NAME/bin:$PATH"
ENV PATH "/opt/poetry/bin:$PATH"

RUN apt-get -qq update --yes \
&& apt-get -qq install --yes --no-install-recommends \
build-essential firefox\
ca-certificates sudo \
ca-certificates sudo curl \
&& rm -rf /var/lib/apt/lists/*

RUN useradd -ms /bin/bash developer \
&& echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer \
&& chmod 0440 /etc/sudoers.d/

# Set home to developer
ENV HOME /home/developer
# Allow the application to execute as any UID
# and still write temporary data to /tmp
ENV APP_TMP_DATA=/tmp

# Copy environment file to tmp/
COPY conda/environment.yaml ${APP_TMP_DATA}/environment.yaml
# Executable in a container to be owned by the root user
COPY docker/test_notebooks.sh /test_notebooks.sh
COPY docker/entrypoint.sh /entrypoint.sh

# Use environment to update the env base
RUN mamba update --all --yes --quiet \
&& mamba env update --file ${APP_TMP_DATA}/environment.yaml --name base \
RUN useradd -ms /bin/bash pysus \
&& echo "pysus ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pysus \
&& chmod 0440 /etc/sudoers.d/ \
&& echo 'source /opt/conda/bin/activate "$ENV_NAME" && exec "$@"' > /activate.sh \
&& echo 'source activate "$ENV_NAME"' > /home/pysus/.bashrc \
&& chmod +x /activate.sh \
&& chmod -R a+rwx /opt/conda /tmp \
&& sudo chown -R pysus:pysus /usr/src

COPY --chown=pysus:pysus conda/dev.yaml /tmp/dev.yaml
COPY --chown=pysus:pysus docker/entrypoint.sh /entrypoint.sh
COPY --chown=pysus:pysus pyproject.toml poetry.lock LICENSE README.md /usr/src/
COPY --chown=pysus:pysus pysus /usr/src/pysus
COPY --chown=pysus:pysus docs/source/*.ipynb /home/pysus/Notebooks/

RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | POETRY_HOME=/opt/poetry python && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false

RUN chmod -R a+rwx /home/pysus/.config/pypoetry/

USER pysus

RUN mamba env update -n $ENV_NAME \
--file /tmp/dev.yaml \
&& cd /usr/src && poetry build && poetry install \
&& mamba clean -afy

USER developer

# Copy only notebooks to the container with permissions to user
RUN mkdir ${HOME}/Notebooks
WORKDIR ${HOME}/Notebooks
COPY pysus/Notebooks .

ENTRYPOINT ["/entrypoint.sh"]
WORKDIR /home/pysus/Notebooks

CMD ["/usr/bin/firefox"]
ENTRYPOINT ["bash", "/activate.sh"]
2 changes: 2 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ services:
- DISPLAY=:0
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
entrypoint: ["/entrypoint.sh"]
command: ["/usr/bin/firefox"]
5 changes: 0 additions & 5 deletions docker/test_notebooks.sh

This file was deleted.

Loading

0 comments on commit a512c2f

Please sign in to comment.