Skip to content

Commit

Permalink
update precommit and pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
thedannymarsh committed May 2, 2024
1 parent d931e04 commit 086f610
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore =
ignore =
# make black happy
E203, W503,
# self type
Expand Down
43 changes: 21 additions & 22 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@ name: Python package

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
33 changes: 16 additions & 17 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ permissions:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
36 changes: 25 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
# checking for syntax
- id: check-yaml
Expand All @@ -15,41 +15,47 @@ repos:
- id: check-merge-conflict
# sort python imports
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
# format f strings
- repo: https://github.com/ikamensh/flynt/
rev: "0.78"
rev: "1.0.1"
hooks:
- id: flynt
# pyupgrade (migrate code to newer syntax)
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py39-plus]
# format python code
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black]
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies:
- docformatter[tomli]
args: ["--in-place", "--config", "./pyproject.toml"]
# format markdown, yaml, json
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
rev: v4.0.0-alpha.8
hooks:
- id: prettier
exclude_types: [python, markdown]
args: ["--print-width", "100"]
# lint python code
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 7.0.0
hooks:
- id: flake8
# check for dead code
Expand All @@ -62,17 +68,25 @@ repos:
- flake8-use-fstring
- flake8-docstrings
- flake8-rst-docstrings
- flake8-blind-except
- flake8-requirements
- flake8-deprecated
- flake8-requirements
- pep8-naming
- flake8-annotations
- darglint
- flake8-warnings
- flake8-pie
- flake8-annotations
- flake8-annotations-complexity
- flake8-return
# format and lint markdown
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
rev: v0.40.0
hooks:
- id: markdownlint-fix
args: ["--disable", "md013,md034,md033,md036"]
# static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.1.1"
rev: "v1.10.0"
hooks:
- id: mypy
28 changes: 19 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "nd_line"
version = "0.2.0"
version = "0.2.0" # This is the only place version should be hard coded
authors = [
{ name="Daniel Marshall", email="[email protected]" },
]
description = "Interpolate points on an n-dimensional line by euclidean arc length"
readme = "README.md"
license = "MIT"
requires-python = ">=3.7"
license = {file = "LICENSE"}
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent"
]
dependencies = [
"numpy",
"scipy"
]

[project.urls]
Expand All @@ -38,6 +49,5 @@ wrap-summaries = 0
wrap-descriptions = 0
in-place = true

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.mypy]
no_namespace_packages = true
1 change: 0 additions & 1 deletion src/nd_line/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Module for creating an n-dimensional line."""
5 changes: 3 additions & 2 deletions src/nd_line/nd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Copyright Daniel Marshall
"""

import math
from typing import List, Optional
from typing import Optional

import numpy as np
from numpy import ndarray
Expand All @@ -25,7 +26,7 @@ def __init__(self, points: ArrayLike) -> None:
self.cumul: ndarray = np.cumsum([0.0] + alldist)
self.type = 'linear'

def _lengths(self, points: ndarray) -> List[float]:
def _lengths(self, points: ndarray) -> list[float]:
"""Calculate the length (sum of the euclidean distance between points).
:param points: numpy array of points
Expand Down

0 comments on commit 086f610

Please sign in to comment.