Skip to content

Commit

Permalink
Merge pull request #23 from cosminc98/master
Browse files Browse the repository at this point in the history
Major rewrite that merges the two plugin versions, adds tests, CI/CD pipeline
  • Loading branch information
cosminc98 authored Jan 23, 2024
2 parents 0d2ab99 + e392fc3 commit f5a85b1
Show file tree
Hide file tree
Showing 41 changed files with 2,049 additions and 249 deletions.
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu

ARG VENV_PATH=/opt/dev-venv
ENV VENV_ACTIVATE=${VENV_PATH}/bin/activate

RUN apt update
RUN apt install -y python3.10-venv nvidia-cuda-toolkit gcc vim git

# the mkdir command bypasses a profiler error, which allows us to run it with
# host code only to at least check that the profiler parameters are correctly
# provided; without this line, some tests will fail
RUN mkdir -p /usr/lib/x86_64-linux-gnu/nsight-compute/sections

# we create the virtualenv here so that the devcontainer.json setting
# python.defaultInterpreterPath can be used to find it; if we do it in the
# post_create.sh script, the virtualenv will not be loaded and features like
# pylance, black, isort, etc. will not work
RUN python3.10 -m venv ${VENV_PATH}
RUN echo "source ${VENV_ACTIVATE}" >> ~/.bashrc
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Python Environment",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"postCreateCommand": "bash .devcontainer/post_create.sh",
"customizations": {
"vscode": {
"extensions": [
"editorconfig.editorconfig",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.isort",
"ms-python.flake8",
"ms-python.black-formatter",
"ryanluker.vscode-coverage-gutters"
],
"settings": {
"python.defaultInterpreterPath": "/opt/dev-venv/bin/python"
}
}
}
}
7 changes: 7 additions & 0 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# install developer dependencies
pip install .[dev]

# make sure the developer uses pre-commit hooks
pre-commit install
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 79
select = F,E,W,B,B901,B902,B903
exclude = .eggs,.git,.tox,nssm,obj,out,packages,pywin32,tests,swagger_client
ignore = E722,B001,W503,E203
22 changes: 22 additions & 0 deletions .github/workflows/code-quality-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Same as `code-quality-pr.yaml` but triggered on commit to master branch
# and runs on all files (instead of only the changed ones)

name: Code Quality Master

on:
push:
branches: [master]

jobs:
code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2

- name: Run pre-commits
uses: pre-commit/[email protected]
36 changes: 36 additions & 0 deletions .github/workflows/code-quality-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow finds which files were changed, prints them,
# and runs `pre-commit` on those files.

# Inspired by the sktime library:
# https://github.com/alan-turing-institute/sktime/blob/main/.github/workflows/test.yml

name: Code Quality PR

on:
pull_request:
branches: [master, "release/*", "dev"]

jobs:
code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2

- name: Find modified files
id: file_changes
uses: trilom/[email protected]
with:
output: " "

- name: List modified files
run: echo '${{ steps.file_changes.outputs.files}}'

- name: Run pre-commits
uses: pre-commit/[email protected]
with:
extra_args: --files ${{ steps.file_changes.outputs.files}}
46 changes: 46 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/nvcc4jupyter
permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
86 changes: 86 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master, "release/*", "dev"]

jobs:
run_tests_ubuntu:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10", "3.11", "3.12"]

timeout-minutes: 20

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 }}

# the mkdir command bypasses a profiler error, which allows us to run it
# with host code only to at least check that the profiler parameters are
# correctly provided
- name: Install CUDA tools
run: |
sudo apt update
sudo apt install nvidia-cuda-toolkit
sudo mkdir -p /usr/lib/x86_64-linux-gnu/nsight-compute/sections
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
- name: List dependencies
run: |
python -m pip list
- name: Run pytest
run: |
pytest -v
# upload code coverage report
code-coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
lfs: "true"
- run: git lfs pull

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install CUDA tools
run: |
sudo apt update
sudo apt install nvidia-cuda-toolkit
sudo mkdir -p /usr/lib/x86_64-linux-gnu/nsight-compute/sections
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
pip install pytest-cov[toml]
- name: Run tests and collect coverage
run: pytest --cov nvcc4jupyter

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
37 changes: 36 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Virtual Environment
*env*

# Misc
.pytest_cache/
.DS_Store
.idea
.idea
53 changes: 53 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: check-executables-have-shebangs
- id: check-toml
- id: check-case-conflict
- id: check-added-large-files

# python code formatting
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
args: ["--config", "pyproject.toml"]

# python import sorting
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--settings-path", "pyproject.toml"]

# python check (PEP8), programming errors and code complexity
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ["--config", ".flake8"]

# pylint check
- repo: https://github.com/pycqa/pylint
rev: v3.0.3
hooks:
- id: pylint
args: ["--rcfile", "pyproject.toml"]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.6
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
32 changes: 32 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.10"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
Loading

0 comments on commit f5a85b1

Please sign in to comment.