Skip to content

Commit

Permalink
Adopt pyproject.toml and poetry packaging system
Browse files Browse the repository at this point in the history
  • Loading branch information
frthjf committed May 19, 2022
1 parent fd75a1f commit adf8021
Show file tree
Hide file tree
Showing 40 changed files with 2,114 additions and 357 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Check http://editorconfig.org for more information
# This is the main config file for this project:
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.{py, pyi}]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.{diff,patch}]
trim_trailing_whitespace = false
92 changes: 23 additions & 69 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,51 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push request
# events for the master branch, and pull request events for all branches.
on:
push:
branches: [ main ]
pull_request:
branches: [ '**' ]
on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }} #ubuntu-latest

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest] # Run macos tests if really required, since they charge 10 times more for macos
python-version: ["3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-latest, windows-latest] # Run macos tests if really required, since they charge 10 times more for macos
include:
- os: ubuntu-latest
path: ~/.cache/pip
- os: macos-latest
path: ~/Library/Caches/pip
- os: windows-latest
path: ~\AppData\Local\pip\Cache

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Ref: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v2.2.2
with:
python-version: ${{ matrix.python-version }}

# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install poetry
run: make poetry-download

# Cache the pip requirmenets for other tests. If requirements cached use them to speed up the build.
# Ref: https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Cache pip Linux
uses: actions/cache@v2
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache pip MacOS
uses: actions/cache@v2
if: startsWith(runner.os, 'macOS')
- name: Set up cache
uses: actions/cache@v3
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache pip Windows
uses: actions/cache@v2
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
echo update pip
python -m pip install --upgrade pip
echo update requirments
pip install -r requirements.txt
echo update test requirements
pip install -r tests/requirements.txt
# Runs a single command using the runners shell
- name: Welcome message
run: echo Hello, world! Welcome MiV-OS Build, lets start testing!
poetry config virtualenvs.in-project true
poetry install
# Formatting test with black and flake8
- name: Black and Flake8 formatting tests
if: startsWith(runner.os, 'macOS')
- name: Run style checks
run: |
if [[ "${{ matrix.python-version }}" == "3.8" ]]; then
black --version
black --check miv tests
flake8 --version
flake8 miv tests
fi
make check-codestyle
# General PyTest for all matrix strategy
- name: PyTest and MyPy
- name: Run tests
run: |
make ci
make test
# Set environment variables for coverage test. Coverage test is done using python 3.8
# Test MiV-OS using pytest
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: publish

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.x"
- name: Install Poetry
uses: snok/[email protected]
- name: Build
run: |
poetry build
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
59 changes: 42 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
default_language_version:
python: python3.8

default_stages: [commit, push]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: trailing-whitespace
- id: check-json
- id: end-of-file-fixer
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
additional_dependencies: ['click==8.0.4']
# args: [--line-length=120]
- repo: https://github.com/pycqa/flake8
rev: 4.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: trailing-whitespace
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
exclude: LICENSE

- repo: local
hooks:
- id: pyupgrade
name: pyupgrade
entry: poetry run pyupgrade --py37-plus
types: [python]
language: system

- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort --settings-path pyproject.toml
types: [python]
language: system

- repo: local
hooks:
- id: black
name: black
entry: poetry run black --config pyproject.toml
types: [python]
language: system

- repo: https://github.com/pycqa/flake8
rev: 4.0.0
hooks:
- id: flake8
84 changes: 78 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,83 @@
#* Variables
PYTHON := python
PYTHONPATH := `pwd`

#* 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:
poetry lock -n && poetry export --without-hashes > requirements.txt
poetry install -n
-poetry run mypy --install-types --non-interactive ./

.PHONY: pre-commit-install
pre-commit-install:
poetry run pre-commit install

#* Formatters
.PHONY: codestyle
codestyle:
poetry run pyupgrade --exit-zero-even-if-changed --py38-plus **/*.py
poetry run isort --settings-path pyproject.toml ./
poetry run black --config pyproject.toml ./

.PHONY: formatting
formatting: codestyle

#* Linting
.PHONY: test
test:
@python -m pytest
PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=miv tests/

.PHONY: check-codestyle
check-codestyle:
poetry run isort --diff --check-only --settings-path pyproject.toml ./
poetry run black --diff --check --config pyproject.toml ./
poetry run darglint --verbosity 2 miv tests

.PHONY: mypy
mypy:
@mypy --ignore-missing-imports miv
poetry run mypy --config-file pyproject.toml ./

.PHONY: lint
lint: test check-codestyle mypy check-safety

.PHONY: update-dev-deps
update-dev-deps:
poetry add -D "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest pylint@latest pytest@latest pyupgrade@latest coverage@latest pytest-html@latest pytest-cov@latest black@latest

#* Cleaning
.PHONY: pycache-remove
pycache-remove:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf

.PHONY: dsstore-remove
dsstore-remove:
find . | grep -E ".DS_Store" | xargs rm -rf

.PHONY: mypycache-remove
mypycache-remove:
find . | grep -E ".mypy_cache" | xargs rm -rf

.PHONY: ipynbcheckpoints-remove
ipynbcheckpoints-remove:
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf

.PHONY: pytestcache-remove
pytestcache-remove:
find . | grep -E ".pytest_cache" | xargs rm -rf

coverage:
@pytest --cov=miv tests/
.PHONY: build-remove
build-remove:
rm -rf build/

all:test mypy coverage
ci: test mypy
.PHONY: cleanup
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

sys.path.insert(0, os.path.abspath("../"))

from miv.version import VERSION

from miv import get_version

# -- Project information -----------------------------------------------------

Expand All @@ -28,7 +27,7 @@
author = "Gazzola Lab"

# The full version, including alpha/beta/rc tags
release = VERSION
release = get_version()

# -- General configuration ---------------------------------------------------

Expand Down
11 changes: 5 additions & 6 deletions examples/post_processing/spike_detection.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import os

import matplotlib.pyplot as plt
import neo
import numpy as np
import quantities as pq
from viziphant.rasterplot import rasterplot_rates

from miv.io import load_data
from miv.signal.filter import butter_bandpass_filter
from miv.signal.spike import (
align_to_minimum,
compute_spike_threshold,
detect_threshold_crossings,
align_to_minimum,
)

import neo
from viziphant.rasterplot import rasterplot_rates

import matplotlib.pyplot as plt


def main():
"""Example spike detection script"""
Expand Down
15 changes: 15 additions & 0 deletions miv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# type: ignore[attr-defined]
"""Python software for analysis and computing framework used in MiV project."""

import sys
from importlib import metadata as importlib_metadata


def get_version() -> str:
try:
return importlib_metadata.version(__name__)
except importlib_metadata.PackageNotFoundError: # pragma: no cover
return "unknown"


version: str = get_version()
2 changes: 1 addition & 1 deletion miv/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from miv.io.data import *
from miv.io.binary import *
from miv.io.data import *
Loading

0 comments on commit adf8021

Please sign in to comment.