Last active
June 15, 2023 17:19
-
-
Save charnley/c87e9f5675228df9e0b966d6ad3cc1a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repos: | |
- repo: https://github.com/pre-commit/pre-commit-hooks | |
rev: v3.4.0 | |
hooks: | |
- id: trailing-whitespace | |
exclude: ^tests/resources/ | |
- id: end-of-file-fixer | |
exclude: ^tests/resources/ | |
- id: check-yaml | |
args: ["--unsafe"] | |
- id: check-added-large-files | |
- id: check-ast | |
- id: check-json | |
- id: debug-statements | |
- id: detect-aws-credentials | |
args: [--allow-missing-credentials] | |
- id: detect-private-key | |
- id: check-merge-conflict | |
- id: check-added-large-files | |
args: ['--maxkb=3000'] | |
- repo: https://github.com/myint/autoflake | |
rev: v1.4 | |
hooks: | |
- id: autoflake | |
name: Removes unused variables | |
args: | |
- --in-place | |
- --remove-all-unused-imports | |
- --expand-star-imports | |
- --ignore-init-module-imports | |
- repo: https://github.com/pre-commit/mirrors-isort | |
rev: v5.10.1 | |
hooks: | |
- id: isort | |
name: Sorts imports | |
args: [ | |
# Align isort with black formatting | |
"--multi-line=3", | |
"--trailing-comma", | |
"--force-grid-wrap=0", | |
"--use-parentheses", | |
"--line-width=99", | |
] | |
- repo: https://github.com/psf/black | |
rev: 22.3.0 | |
hooks: | |
- id: black | |
name: Fixes formatting | |
language_version: python3 | |
args: ["--line-length=99"] | |
- repo: https://github.com/pycqa/flake8 | |
rev: 4.0.1 | |
hooks: | |
- id: flake8 | |
name: Checks pep8 style | |
args: [ | |
"--max-line-length=99", | |
# Ignore imports in init files | |
"--per-file-ignores=*/__init__.py:F401,setup.py:E121", | |
# ignore long comments (E501), as long lines are formatted by black | |
# ignore Whitespace before ':' (E203) | |
# ignore Line break occurred before a binary operator (W503) | |
"--ignore=E501,E203,W503", | |
] | |
- repo: local | |
hooks: | |
- id: mypy | |
name: Checking types | |
entry: mypy | |
language: system | |
types: [ python ] | |
- repo: local | |
hooks: | |
- id: jupyisort | |
name: Sorts ipynb imports | |
entry: jupytext --pipe-fmt ".py" --pipe "isort - --multi-line=3 --trailing-comma --force-grid-wrap=0 --use-parentheses --line-width=99" --sync | |
files: \.ipynb$ | |
language: python | |
- id: jupyblack | |
name: Fixes ipynb format | |
entry: jupytext --pipe-fmt ".py" --pipe "black - --line-length=99" --sync | |
files: \.ipynb$ | |
language: python | |
- id: nbconvert | |
name: Removes ipynb content | |
entry: jupyter nbconvert | |
args: | |
[ | |
"--ClearOutputPreprocessor.enabled=True", | |
"--ClearMetadataPreprocessor.enabled=True", | |
"--RegexRemovePreprocessor.enabled=True", | |
"--to=notebook", | |
"--log-level=ERROR", | |
"--inplace", | |
] | |
files: \.ipynb$ | |
language: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM docker-repo/rocky | |
ARG WORKDIR="/workdir" | |
ARG CONDA_NAME="api-service" | |
ENV CONDA_NAME=${CONDA_NAME} | |
USER root | |
RUN echo "${CONDA_NAME}" | |
# Setup environment | |
COPY environment.yml ${WORKDIR}/environment.yml | |
RUN conda update --all --quiet | |
RUN yum install libXext libSM libXrender -y # rdkit render dependencies | |
RUN mamba env create --name ${CONDA_NAME} -f ${WORKDIR}/environment.yml --quiet | |
RUN conda clean -afy | |
# Change default conda env | |
ENV CONDA_DEFAULT_ENV ${CONDA_NAME} | |
RUN echo "source activate ${CONDA_NAME}" > ~/.bashrc | |
# Change default conda didn't work, so overwrite path to look for python here | |
ENV PATH=/home/docker/anaconda/envs/${CONDA_NAME}/bin:${PATH} | |
# Copy source-code | |
COPY ./src ${WORKDIR}/src | |
COPY ./pyproject.toml ${WORKDIR}/pyproject.toml | |
COPY ./logging.yaml ${WORKDIR}/logging.yaml | |
COPY ./pytest.ini ${WORKDIR}/pytest.ini | |
COPY ./tests ${WORKDIR}/tests | |
RUN python -m pip install ${WORKDIR} | |
WORKDIR ${WORKDIR} | |
CMD ["-m", "uvicorn", "--host", "0.0.0.0", "--port", "80", "packagename.service.main:app", "--log-config", "logging.yaml"] | |
EXPOSE 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: format test clean | |
DOCKERNAME=servicerapp | |
PACKAGE=packagename | |
all: env precommit | |
# Setup | |
env: | |
mamba env create -f ./environment.yml -p ./env --quiet | |
./env/bin/python -m pip install -e . | |
precommit: | |
./env/bin/pre-commit install | |
# Commit work | |
format: | |
pre-commit run --all-files | |
test: | |
python -m pytest -vrs tests | |
test-cov-html: | |
python -m pytest -vrs --cov=${PACKAGE} --cov-report html tests | |
test-docker: | |
docker run --rm -it --entrypoint "pytest" ${DOCKERNAME} | |
# Build | |
build-docker: | |
docker build -f ./docker/service.Dockerfile . -t ${DOCKERNAME} | |
# Work | |
start-api: | |
python -m uvicorn \ | |
${PACKAGE}.service.main:app \ | |
--reload --port 5000 --log-config logging.dev.yaml | |
start-docker-api: | |
docker run -p 8080:80 ${DOCKERNAME} | |
start-docker-bash: | |
docker run --rm -it --entrypoint bash ${DOCKERNAME} | |
jupyter: | |
jupyter lab | |
# Post work | |
clean: | |
clean-env: | |
rm -rf ./env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[build-system] | |
requires = ["setuptools", "setuptools-scm"] | |
build-backend = "setuptools.build_meta" | |
[project] | |
name = "program_name" | |
dynamic = ["version"] | |
authors = [ | |
{name = "Jimmy Kromann", email = "jimmy.kromann@email.com"}, | |
] | |
requires-python = ">=3.8" | |
[tool.setuptools.dynamic] | |
version = {attr = "packagename.__version__"} | |
[options.packages.find] | |
where="src" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment