Skip to content

Commit

Permalink
Move to hatchling build system (#55)
Browse files Browse the repository at this point in the history
* Bumps minimum Python version to 3.8 and minimum Pandas version to 2.0.0.
* Incorporates linting via ruff, black, and isort.
* Expands python-package GitHub workflow to test more OSes and Python version.
* Fixes failing tests and adds new tests.
  • Loading branch information
jpdunc23 authored Feb 9, 2024
1 parent 855116c commit 22d06eb
Show file tree
Hide file tree
Showing 20 changed files with 3,557 additions and 1,698 deletions.
101 changes: 81 additions & 20 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,96 @@
# This workflow will install Python dependencies, run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

# based on https://github.com/pypa/hatch/blob/master/.github/workflows/test.yml
name: tests

on: [ push ]
on:
push:
branches:
- master
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
STABLE_PYTHON_VERSION: '3.11'
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"

jobs:
build:

runs-on: ubuntu-latest
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.7.15, 3.10.8]
python-version: ["3.9", "3.10", "3.11"]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev] --no-cache-dir

- name: Ensure latest pip
run: python -m pip install --upgrade pip

- name: Install Hatch
run: pip install hatch

- name: Install vflow
run: python -m pip install -e .

- name: Check styles
run: hatch run style:check

- name: Test with pytest
run: |
pytest --cov=./ --cov-report=xml
- name: Lint with pylint
run: |
pylint vflow *.py --rcfile=.pylintrc
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v2
run: hatch run full

- name: Disambiguate coverage filename
run: mv .coverage ".coverage.${{ matrix.os }}.${{ matrix.python-version }}"

- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: .coverage.*

coverage:
name: Report coverage
runs-on: ubuntu-latest
needs:
- build

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ env.STABLE_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}

- name: Install Hatch
run: pip install hatch

- name: Download coverage data
uses: actions/download-artifact@v3
with:
name: coverage-data

- name: Combine coverage data
run: hatch run coverage:combine

- name: Export coverage reports
run: hatch run coverage:report-xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: gitignore; -*-

**mlruns
**.ipynb_checkpoints
**cache*
Expand Down Expand Up @@ -48,3 +50,54 @@ notebooks/data/*
.hypothesis
**coverage*
codecov

# -- Emacs
# https://github.com/github/gitignore/blob/main/Global/Emacs.gitignore

*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el

# network security
/network-security.data
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
VERSION ?= $(shell git rev-parse --short HEAD)
CONDA_ENV_NAME ?= vflow
HATCH_ENV_NAME ?= test

.PHONY: build_conda_env build_ipykernel test_% run_tests fix_styles

build_conda_env:
conda create -n $(CONDA_ENV_NAME) -y python==3.10 pip
conda run -n $(CONDA_ENV_NAME) --no-capture-output pip install -r requirements.txt
conda run -n $(CONDA_ENV_NAME) --no-capture-output pip install . ipykernel

build_ipykernel:
conda run -n $(CONDA_ENV_NAME) python -m ipykernel install --user --name $(CONDA_ENV_NAME) --display-name "Python [conda:$(CONDA_ENV_NAME)]"

test_%:
hatch -v run dev $(PYTEST_ARGS) tests/test_$*.py

run_tests:
hatch -v run cov

fix_styles:
hatch -v run style:fmt
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ See the [docs](https://yu-group.github.io/veridical-flow/) for reference on the
## Installation

Install with `pip install vflow` (see [here](https://github.com/Yu-Group/veridical-flow/blob/master/docs/troubleshooting.md) for help). For dev version (unstable), clone the repo and run `python setup.py develop` from the repo directory.
### Stable version

```bash
pip install vflow
```

### Development version (unstable)

```bash
pip install vflow@git+https://github.com/Yu-Group/veridical-flow
```

# References

Expand Down
7 changes: 0 additions & 7 deletions docs/troubleshooting.md

This file was deleted.

62 changes: 62 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# based on https://github.com/pypa/hatch/blob/master/hatch.toml

[envs.default]
dependencies = [
"coverage[toml]",
"pytest-cov",
"pytest-randomly",
"pytest-rerunfailures",
"pytest-xdist",
]

[envs.default.scripts]
# --cov must not come before an argument in order to use the sources defined by config
_cov = "pytest --cov --cov-report=term-missing --cov-config=pyproject.toml"
dev = "pytest -p no:randomly --no-cov {args:tests}"
cov = "_cov -p no:randomly {args:tests}"
full = "_cov -n auto --reruns 5 --reruns-delay 3 -r aR {args:tests}"

[envs.dev]
template = "default"
dependencies = [
"jupyterlab",
"torch>=1.0.0",
"torchvision",
"tqdm",
"scikit-learn>=0.23.0",
]

[envs.dev.env-vars]
PIP_INDEX_URL = "https://download.pytorch.org/whl/cpu"
PIP_EXTRA_INDEX_URL = "https://pypi.org/simple/"

[envs.style]
detached = true
dependencies = [
"ruff",
"black",
"isort",
]

[envs.style.scripts]
check = [
"ruff vflow tests",
"black --check --diff vflow tests",
"isort --check --diff --profile black vflow tests",
]
fmt = [
"isort --profile black ./vflow ./tests",
"black ./vflow ./tests",
"check",
]

[envs.coverage]
detached = true
dependencies = [
"coverage[toml]",
"lxml",
]

[envs.coverage.scripts]
combine = "coverage combine {args}"
report-xml = "coverage xml -i"
56 changes: 54 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"

[project]
name = "vflow"
version = "0.1.2"
authors = [
{ name="Chandan Singh", email="[email protected]" },
{ name="James Duncan", email="[email protected]" },
{ name="Abhineet Agarwal", email="[email protected]" },
{ name="Rush Kapoor", email="[email protected] " },
]
maintainers = [
{ name="James Duncan", email="[email protected]" },
]
description = "A framework for doing stability analysis with PCS."
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Intended Audience :: Science/Research",
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Operating System :: OS Independent",
]
license = {text = "MIT"}
dynamic = ["dependencies"]

[project.urls]
Homepage = "https://vflow.csinva.io/"
Issues = "https://github.com/Yu-Group/veridical-flow/issues"

[project.optional-dependencies]
gpu = ["torch"]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]

[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
"/notebooks",
]

[tool.hatch.build.targets.wheel]
packages = ["vflow"]

[tool.coverage.run]
branch = true
source_pkgs = ["vflow", "tests"]
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
numpy
scipy
matplotlib
networkx
pandas>=2.0.0
joblib
pytest
ray
mlflow
Loading

0 comments on commit 22d06eb

Please sign in to comment.