Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish to PyPI

on:
release:
types: [published]

jobs:
deploy:
name: Build & Publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine

- name: Build package
run: make build

- name: Check distribution
run: make test-dist

- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: make upload
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test

on:
push:
branches:
- '**'
pull_request:
branches: [main]

jobs:
test:
name: Test Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v7
with:
python-version: ${{ matrix.python-version }}

- name: Create environment
run: make env python-version=${{ matrix.python-version }}

- name: Run tests
run: source ./env/bin/activate && make test python=python

- name: Check format and types
run: source ./env/bin/activate && make format

- name: Build package
run: source ./env/bin/activate && make build

- name: Check distribution
run: source ./env/bin/activate && make test-dist

- name: Test installation from wheel
run: |
pip install dist/*.whl
python -c "import hpc_funcs; print(hpc_funcs.__version__)"
76 changes: 14 additions & 62 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v5.0.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
exclude: ^tests/resources/uge/qstat_jobinfo_(array|error)\.json$
- id: debug-statements
- id: detect-aws-credentials
args: [--allow-missing-credentials]
Expand All @@ -20,79 +20,31 @@ repos:
- id: check-added-large-files
args: ['--maxkb=3000']

- repo: https://github.com/myint/autoflake
rev: v2.3.1
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: 24.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.6
hooks:
- id: black
name: Fixes formatting
language_version: python3
args: ["--line-length=99"]


- repo: https://github.com/pycqa/flake8
rev: 7.1.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: https://github.com/pre-commit/mirrors-mypy
# rev: v0.782
# hooks:
# - id: mypy
# args: [--ignore-missing-imports]
- id: ruff
args: [--fix]
- id: ruff-format

- repo: local
hooks:

- id: mypy
- id: ty
name: Static type checking
entry: mypy
files: \.py$
language: python
entry: ty check
files: ^src/.*\.py$
language: system

- 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
entry: jupytext --pipe-fmt ".py" --pipe "ruff check --select I --fix -" --sync
files: \.ipynb$
language: python

- id: jupyblack
- id: jupyformat
name: Fixes ipynb format
entry: jupytext --pipe-fmt ".py" --pipe "black - --line-length=99" --sync
entry: jupytext --pipe-fmt ".py" --pipe "ruff format -" --sync
files: \.ipynb$
language: python

Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: update-format format test test-dist build types upload cov
.PHONY: update-format format check test test-dist build types upload cov clean clean-env

package=hpc_funcs
version_file1=./src/hpc_funcs/version.py
Expand All @@ -21,16 +21,10 @@ env: ${env}_uv

env_uv:
uv venv ${env}
uv pip install -r requirements.txt --python ${env}/bin/python
uv pip install -e . --python ${env}/bin/python
uv pip install -e .[dev] --python ${env}/bin/python
${python} -m pre_commit install

env_conda:
conda env create -f ./environment.yml -p ${env} --quiet
${python} -m pre_commit install
${python} -m pip install -e .


## Development

update-format:
Expand All @@ -39,6 +33,8 @@ update-format:
format:
${python} -m pre_commit run --all-files

check: format types

test:
${python} -m pytest ./tests

Expand Down Expand Up @@ -107,3 +103,7 @@ clean:
rm -rf *.whl
rm -rf ./build/ ./__pycache__/
rm -rf ./dist/

clean-env:
rm -rf ./${env}/
rm -f .git/hooks/pre-commit
90 changes: 84 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,96 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "hpce_utils"
name = "hpc_funcs"
dynamic = ["version"]
authors = []
description = "HPC utility functions"
readme = "README.md"
license = {text = "MIT"}
requires-python = ">=3.11"
classifiers = [
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = [
"jinja2",
"tqdm",
]

[project.optional-dependencies]
dev = [
"ruff",
"ty",
"pip",
"pre-commit",
"pytest",
"pytest-cov",
"pandas",
"twine",
"build",
"monkeytype",
]

[tool.setuptools.dynamic]
version = {attr = "hpce_utils.version.VERSION"}
version = {attr = "hpc_funcs.version.__version__"}

[options.packages.find]
where="src"
[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"*" = ["*.jinja"]
"*" = ["*.jinja", "py.typed"]

[tool.ruff]
line-length = 99
target-version = "py311"
exclude = [
".git",
".github",
"__pycache__",
"build",
"dist",
"*.egg-info",
"env",
]

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort (import sorting)
"UP", # pyupgrade (modern Python syntax)
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
]

[tool.ruff.lint.isort]
known-first-party = ["hpc_funcs"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["B017", "B023", "E501"]
"*/__init__.py" = ["F401"]

[tool.ty]
# Type checking with ty (Astral's extremely fast Python type checker)

[tool.ty.environment]
python-version = "3.11"

[tool.ty.src]
exclude = ["tests/"]

[tool.ty.rules]
# Ignore unresolved imports since pre-commit env doesn't have all packages
unresolved-import = "ignore"

[tool.pytest.ini_options]
testpaths = ["tests"]
log_cli = true
log_cli_level = "DEBUG"
18 changes: 0 additions & 18 deletions setup.py

This file was deleted.

Loading
Loading