diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4cf9643..6ee1cef 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,10 +24,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -e .[dev] + pip install hatch - name: Run tests - run: pytest + run: hatch run test:all lint: runs-on: ubuntu-latest @@ -38,10 +38,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[dev] + pip install hatch - - name: Sourcery login - run: sourcery login --token ${{ secrets.SOURCERY_TOKEN }} + - name: Setup environment + run: | + hatch run sourcery login --token ${{ secrets.SOURCERY_TOKEN }} - name: Set up pre-commit uses: pre-commit/action@v3.0.0 diff --git a/README.md b/README.md index 4d0f0df..206d3a3 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,23 @@ This package is in active development. ### Setup -After cloning the repository, install the package in editable mode with the development dependencies using: +This project uses [hatch](https://hatch.pypa.io/latest/) to manage the development environment and build and publish releases. Make sure `hatch` is [installed](https://hatch.pypa.io/latest/install/) first: ```bash -$ pip install -e .[dev] +$ pip install hatch ``` +Now you can [enter the development environment](https://hatch.pypa.io/latest/environment/#entering-environments) using: + +```bash +$ hatch shell +``` + +This will install development dependencies in an isolated environment and drop you into a shell (use `exit` to leave). + ### Pre-commit -This project uses [pre-commit](https://pre-commit.com/) to run testing, linting, type-checking, and formatting. You can run pre-commit manually with: +Use [pre-commit](https://pre-commit.com/) to run linting, type-checking, and formatting: ```bash $ pre-commit run --all-files @@ -26,16 +34,44 @@ $ pre-commit run --all-files $ pre-commit install ``` +You can run pre-commit hooks separately and pass additional arguments to them. For example, to run `flake8` on a single file: + +```bash +$ pre-commit run flake8 --files=src/sklearn_knn/_base.py +``` + ### Testing -Unit tests are *not* run by `pre-commit`, but can be run manually with: +Unit tests are *not* run by `pre-commit`, but can be run manually using `hatch` [scripts](https://hatch.pypa.io/latest/config/environment/overview/#scripts): ```bash -$ pytest +$ hatch run test:all ``` Measure test coverage with: ```bash -$ pytest --cov=sklearn_knn +$ hatch run test:coverage +``` + +Any additional arguments are passed to `pytest`. For example, to run a subset of tests matching a keyword: + +```bash +$ hatch run test:all -k gnn +``` + +### Releasing + +First, use `hatch` to [update the version number](https://hatch.pypa.io/latest/version/#updating). + +```bash +$ hatch version [major|minor|patch] +``` + +Then, [build](https://hatch.pypa.io/latest/build/#building) and [publish](https://hatch.pypa.io/latest/publish/#publishing) the release to PyPI with: + +```bash +$ hatch clean +$ hatch build +$ hatch publish ``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..407b82f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "scikit-learn-knn" +dynamic = ["version"] +description = "Scikit-learn estimators for kNN methods" +readme = "README.md" +license = "" +requires-python = ">=3.8" +authors = [ + { name = "Matt Gregory", email = "matt.gregory@oregonstate.edu" }, + { name = "Aaron Zuspan", email = "aaron.zuspan@oregonstate.edu" } +] +dependencies = [ + "numpy", + "scikit-learn", +] + +[project.urls] +Homepage = "https://github.com/lemma-osu/scikit-learn-knn" +Source = "https://github.com/lemma-osu/scikit-learn-knn" + +[tool.hatch.version] +path = "src/sklearn_knn/__about__.py" + +[tool.hatch.build.targets.wheel] +packages = ["src/sklearn_knn"] + +[tool.hatch.build.targets.sdist] +include = [ + "/src", +] + +[tool.hatch.envs.default] +dependencies = [ + "pre-commit", + "sourcery", +] + +[tool.hatch.envs.test] +dependencies = [ + "pytest", + "pytest-cov", + "pandas" +] + +[tool.hatch.envs.test.scripts] +all = "pytest {args}" +coverage = "pytest --cov=src/sklearn_knn {args}" + +[tool.pytest.ini_options] +pythonpath = "src/" diff --git a/setup.py b/setup.py deleted file mode 100644 index 491d04b..0000000 --- a/setup.py +++ /dev/null @@ -1,40 +0,0 @@ -from setuptools import find_packages, setup - - -def setup_package(): - metadata = dict( - name="scikit-learn-knn", - author="LEMMA group @ Oregon State University", - author_email="matt.gregory@oregonstate.edu", - description="Scikit-learn estimators for kNN methods", - url="http://github.com/lemma-osu/scikit-learn-knn/", - version="0.1.0", - package_dir={"": "src"}, - packages=find_packages(where="src"), - python_requires=">=3.8", - install_requires=[ - "numpy", - "scikit-learn", - ], - extras_require={ - "dev": [ - "black", - "bumpversion", - "flake8", - "flake8-bugbear", - "isort", - "pytest", - "pytest-cov", - "pandas", - "pre-commit", - "mypy", - "twine", - "sourcery", - ], - }, - ) - setup(**metadata) - - -if __name__ == "__main__": - setup_package() diff --git a/src/sklearn_knn/__about__.py b/src/sklearn_knn/__about__.py new file mode 100644 index 0000000..3dc1f76 --- /dev/null +++ b/src/sklearn_knn/__about__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/src/sklearn_knn/__init__.py b/src/sklearn_knn/__init__.py index eafc84d..b24f827 100644 --- a/src/sklearn_knn/__init__.py +++ b/src/sklearn_knn/__init__.py @@ -1,3 +1,4 @@ +from .__about__ import __version__ # noqa: F401 from ._euclidean import Euclidean from ._gnn import GNN from ._mahalanobis import Mahalanobis