Skip to content

Commit

Permalink
chore: cruft update (#94)
Browse files Browse the repository at this point in the history
* style: reformat comments

* chore: cruft update

* fix: ignore poetry.lock

* fix: absolufy imports, yesqa, bandit

* chore: cruft update

* fix: remove redundant cast

* ci: remove typeguard
  • Loading branch information
lsorber authored Aug 29, 2022
1 parent c7cede2 commit 80a270a
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 1,869 deletions.
7 changes: 5 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "[email protected]:radix-ai/poetry-cookiecutter",
"commit": "d789ff6aa6eebc31018020da4373e674d8c3b464",
"commit": "966391b0342fc923a177a30c39285adf4416fa17",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -17,10 +17,13 @@
"with_streamlit_app": "0",
"with_typer_cli": "0",
"continuous_integration": "GitHub",
"docstring_style": "NumPy",
"private_package_repository_name": "",
"private_package_repository_url": "",
"__package_name_kebab_case": "graphchain",
"__package_name_snake_case": "graphchain",
"_template": "[email protected]:radix-ai/poetry-cookiecutter"
}
},
"directory": null
}
}
77 changes: 42 additions & 35 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,49 @@
"dockerComposeFile": "../docker-compose.yml",
"service": "dev",
"workspaceFolder": "/app/",
"initializeCommand": "ssh-add --apple-load-keychain || true",
"overrideCommand": true,
"postStartCommand": "cp --update /var/lib/poetry/poetry.lock /app/ && mkdir -p /app/.git/hooks/ && cp --update /var/lib/git/* /app/.git/hooks/",
"extensions": [
"bungcip.better-toml",
"eamodio.gitlens",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-python.vscode-pylance",
"ryanluker.vscode-coverage-gutters",
"visualstudioexptteam.vscodeintellicode"
],
"settings": {
"coverage-gutters.coverageFileNames": [
"reports/coveragepy.xml"
],
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.rulers": [
100
],
"files.autoSave": "onFocusChange",
"python.defaultInterpreterPath": "/opt/app-env/bin/python",
"python.formatting.provider": "black",
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.pydocstyleEnabled": true,
"python.linting.pylintEnabled": false,
"python.terminal.activateEnvironment": false,
"python.testing.pytestEnabled": true,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
"postStartCommand": "cp --update /opt/build/poetry/poetry.lock /app/ && mkdir -p /app/.git/hooks/ && cp --update /opt/build/git/* /app/.git/hooks/",
"customizations": {
"vscode": {
"extensions": [
"bungcip.better-toml",
"eamodio.gitlens",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-python.vscode-pylance",
"ryanluker.vscode-coverage-gutters",
"visualstudioexptteam.vscodeintellicode"
],
"settings": {
"coverage-gutters.coverageFileNames": [
"reports/coverage.xml"
],
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.rulers": [
100
],
"files.autoSave": "onFocusChange",
"python.defaultInterpreterPath": "/opt/app-env/bin/python",
"python.formatting.provider": "black",
"python.linting.banditArgs": [
"--configfile",
"pyproject.toml"
],
"python.linting.banditEnabled": true,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.pydocstyleEnabled": true,
"python.terminal.activateEnvironment": false,
"python.testing.pytestEnabled": true,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# http://flake8.pycqa.org/en/latest/user/configuration.html#project-configuration
# https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
# TODO: https://github.com/PyCQA/flake8/issues/234
color = always
doctests = True
ignore = DAR103,E203,E501,FS003,S101,W503
ignore = DAR103,E203,E501,W503
max_line_length = 100
max_complexity = 10

Expand Down
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ updates:
directory: /
schedule:
interval: monthly
commit-message:
prefix: "ci"
prefix-development: "ci"
include: "scope"
- package-ecosystem: pip
directory: /
schedule:
interval: monthly
commit-message:
prefix: "build"
prefix-development: "build"
include: "scope"
versioning-strategy: lockfile-only
allow:
- dependency-type: "all"
5 changes: 1 addition & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ on:
- created

jobs:

publish:

runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.8"

Expand Down
41 changes: 14 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,33 @@ on:
pull_request:

jobs:

test:

runs-on: ubuntu-latest

strategy:

matrix:
python-version: ["3.8"]
fail-fast: false

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Cache Python environment
uses: actions/cache@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
path: .venv/
key: venv-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
node-version: 16

- name: Install Poetry
run: pip install --no-input poetry
- name: Install @devcontainers/cli
run: npm install --location=global @devcontainers/cli

- name: Install Python environment
- name: Start Dev Container
env:
DOCKER_BUILDKIT: 1
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction
git config --global init.defaultBranch main
devcontainer up --workspace-folder .
- name: Lint
run: poetry run poe lint
- name: Lint package
run: devcontainer exec --workspace-folder . poe lint

- name: Test
run: poetry run poe test
- name: Test package
run: devcontainer exec --workspace-folder . poe test

- name: Upload coverage
uses: codecov/codecov-action@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ node_modules/
# Poetry
.venv/
dist/
poetry.lock

# PyCharm
.idea/
Expand Down
25 changes: 21 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand Down Expand Up @@ -55,6 +55,18 @@ repos:
require_serial: true
language: system
types: [python]
- id: absolufy-imports
name: absolufy-imports
entry: absolufy-imports
require_serial: true
language: system
types: [python]
- id: yesqa
name: yesqa
entry: yesqa
require_serial: true
language: system
types: [python]
- id: isort
name: isort
entry: isort
Expand All @@ -72,16 +84,21 @@ repos:
entry: shellcheck --check-sourced
language: system
types: [shell]
- id: flake8
name: flake8
entry: flake8
- id: bandit
name: bandit
entry: bandit --configfile pyproject.toml
language: system
types: [python]
- id: pydocstyle
name: pydocstyle
entry: pydocstyle
language: system
types: [python]
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
- id: poetry-check
name: poetry check
entry: poetry check
Expand Down
89 changes: 63 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker/dockerfile:experimental
# syntax=docker/dockerfile:1
FROM python:3.8-slim AS base

# Configure Python to print tracebacks on crash [1], and to not buffer stdout and stderr [2].
Expand All @@ -9,46 +9,83 @@ ENV PYTHONUNBUFFERED 1

# Install Poetry.
ENV POETRY_VERSION 1.1.13
RUN --mount=type=cache,id=poetry,target=/root/.cache/ pip install poetry==$POETRY_VERSION
RUN --mount=type=cache,target=/root/.cache/ \
pip install poetry==$POETRY_VERSION

# Create and activate a virtual environment.
RUN python -m venv /opt/app-env
ENV PATH /opt/app-env/bin:$PATH
ENV VIRTUAL_ENV /opt/app-env

# Install compilers that may be required for certain packages or platforms.
RUN rm /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,target=/var/cache/apt/ \
--mount=type=cache,target=/var/lib/apt/ \
apt-get update && \
apt-get install --no-install-recommends --yes build-essential

# Set the working directory.
WORKDIR /app/

# Install the run time Python environment.
COPY poetry.lock* pyproject.toml /app/
RUN --mount=type=cache,target=/root/.cache/ \
mkdir -p src/graphchain/ && touch src/graphchain/__init__.py && touch README.md && \
poetry install --no-dev --no-interaction

# Create a non-root user.
ARG UID=1000
ARG GID=$UID
RUN groupadd --gid $GID app && \
useradd --create-home --gid $GID --uid $UID app

FROM base as ci

# Install git so we can run pre-commit.
RUN --mount=type=cache,target=/var/cache/apt/ \
--mount=type=cache,target=/var/lib/apt/ \
apt-get update && \
apt-get install --no-install-recommends --yes git

# Install the development Python environment.
RUN --mount=type=cache,target=/root/.cache/ \
poetry install --no-interaction

# Give the non-root user ownership and switch to the non-root user.
RUN chown --recursive app /app/ /opt/
USER app

FROM base as dev

# Install development tools: compilers, curl, git, gpg, ssh, starship, vim, and zsh.
RUN rm /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt/ \
--mount=type=cache,id=apt-lib,target=/var/lib/apt/ \
# Install development tools: compilers, curl, git, gpg, ssh, starship, sudo, vim, and zsh.
RUN --mount=type=cache,target=/var/cache/apt/ \
--mount=type=cache,target=/var/lib/apt/ \
apt-get update && \
apt-get install --no-install-recommends --yes build-essential curl git gnupg ssh vim zsh zsh-antigen && \
chsh --shell /usr/bin/zsh && \
apt-get install --no-install-recommends --yes build-essential curl git gnupg ssh sudo vim zsh zsh-antigen && \
sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- "--yes" && \
echo 'source /usr/share/zsh-antigen/antigen.zsh' >> ~/.zshrc && \
echo 'antigen bundle zsh-users/zsh-autosuggestions' >> ~/.zshrc && \
echo 'antigen apply' >> ~/.zshrc && \
echo 'eval "$(starship init zsh)"' >> ~/.zshrc && \
zsh -c 'source ~/.zshrc'
usermod --shell /usr/bin/zsh app

# Install the development Python environment.
COPY .pre-commit-config.yaml poetry.lock* pyproject.toml /app/
RUN --mount=type=cache,id=poetry,target=/root/.cache/ \
mkdir -p src/graphchain/ && touch src/graphchain/__init__.py && touch README.md && \
poetry install --no-interaction && \
mkdir -p /var/lib/poetry/ && cp poetry.lock /var/lib/poetry/ && \
RUN --mount=type=cache,target=/root/.cache/ \
poetry install --no-interaction

# Persist output generated during docker build so that we can restore it in the dev container.
COPY .pre-commit-config.yaml /app/
RUN mkdir -p /opt/build/poetry/ && cp poetry.lock /opt/build/poetry/ && \
git init && pre-commit install --install-hooks && \
mkdir -p /var/lib/git/ && cp .git/hooks/commit-msg .git/hooks/pre-commit /var/lib/git/
mkdir -p /opt/build/git/ && cp .git/hooks/commit-msg .git/hooks/pre-commit /opt/build/git/

FROM base as ci
# Give the non-root user ownership and switch to the non-root user.
RUN chown --recursive app /app/ /opt/ && \
echo 'app ALL=(root) NOPASSWD:ALL' > /etc/sudoers.d/app && \
chmod 0440 /etc/sudoers.d/app
USER app

# Install the run time Python environment.
# TODO: Replace `--no-dev` with `--without test` when Poetry 1.2.0 is released.
COPY poetry.lock pyproject.toml /app/
RUN --mount=type=cache,id=poetry,target=/root/.cache/ \
mkdir -p src/graphchain/ && touch src/graphchain/__init__.py && touch README.md && \
poetry install --no-dev --no-interaction
# Configure the non-root user's shell.
RUN echo 'source /usr/share/zsh-antigen/antigen.zsh' >> ~/.zshrc && \
echo 'antigen bundle zsh-users/zsh-syntax-highlighting' >> ~/.zshrc && \
echo 'antigen bundle zsh-users/zsh-autosuggestions' >> ~/.zshrc && \
echo 'antigen apply' >> ~/.zshrc && \
echo 'eval "$(starship init zsh)"' >> ~/.zshrc && \
echo 'HISTFILE=~/.zsh_history' >> ~/.zshrc && \
zsh -c 'source ~/.zshrc'
Loading

0 comments on commit 80a270a

Please sign in to comment.