Skip to content

Commit

Permalink
build: updated setup (pyproject.toml, ruff, tox, trusted publishing)
Browse files Browse the repository at this point in the history
  • Loading branch information
martibosch committed Feb 18, 2024
1 parent 7d9c247 commit 0ec2bc7
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 77 deletions.
10 changes: 0 additions & 10 deletions .bumpversion.cfg

This file was deleted.

11 changes: 11 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Config for Dependabot updates. See Documentation here:
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
# Update GitHub actions in workflows
- package-ecosystem: "github-actions"
directory: "/"
# Check for updates to GitHub Actions every weekday
schedule:
interval: "daily"
131 changes: 131 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: release

on:
push:
tags:
- 'v*'

jobs:
build_sdist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: build source tarball
run: |
python -m build --sdist
twine check --strict dist/*
- uses: actions/upload-artifact@v3
with:
path: dist/*

build_wheels:
name: wheel on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# temporarily ignoring binary wheels for windows until pythran issues are fixed
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

# see https://github.com/pypa/cibuildwheel/issues/933
# - uses: pypa/cibuildwheel@v2

# Used to host cibuildwheel
- uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: install cibuildwheel
run: python -m pip install

- name: build wheels
run: python -m cibuildwheel --output-dir wheelhouse

- name: upload wheels
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl

publish_dev_build:
needs: [build_sdist, build_wheels]
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://pypi.org/p/detectree
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: publish to test pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true

release:
needs: [publish_dev_build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/detectree
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# see https://github.com/softprops/action-gh-release/issues/236
contents: write

# 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@v4

- name: generate change log
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
issues: true
issuesWoLabels: true
pullRequests: true
prWoLabels: true
unreleased: true
addSections: '{"documentation":{"prefix":"**Documentation:**","labels":["documentation"]}}'
sinceTag: v0.1.0
output: RELEASE-CHANGELOG.md

- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: create github release
uses: softprops/action-gh-release@v1
with:
body_path: ./RELEASE-CHANGELOG.md
files: dist/*.whl
draft: false
prerelease: false

- name: publish to pypi
uses: pypa/gh-action-pypi-publish@release/v1
47 changes: 47 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: tests

on:
pull_request:
branches:
- "*"

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
include:
- os: macos-latest
python-version: "3.12"
- os: windows-latest
python-version: "3.12"

runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4

- uses: mamba-org/setup-micromamba@v1
with:
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
pip
- name: install dependencies
run: pip install tox tox-gh-actions

- name: test with tox
run: tox
env:
CONDA_EXE: mamba

- name: upload coverage reports to Codecov
uses: codecov/codecov-action@v3

- name: list files
run: ls -l .
59 changes: 38 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
exclude: 'docs|node_modules|migrations|.tox'
default_stages: [commit]
fail_fast: true
ci:
autofix_commit_msg: "style(pre-commit.ci): auto fixes from pre-commit hooks"
autoupdate_commit_msg: "style(pre-commit.ci): pre-commit autoupdate"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.18.2
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.15.0
hooks:
- id: check-github-workflows
- id: commitizen

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
additional_dependencies: [prettier, prettier-plugin-toml, prettier-plugin-ini]
types: ["ini", "toml", "yaml"]

- repo: https://github.com/psf/black
rev: 22.10.0
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17 # Use the ref you want to point at
hooks:
- id: black
- id: mdformat
# Optionally add plugins
additional_dependencies:
- mdformat-gfm
- mdformat-black

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: isort
- id: yamllint
args: ["-d relaxed"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-github-workflows

- repo: https://gitlab.com/pycqa/flake8
rev: 5.0.4
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: flake8
additional_dependencies: [flake8-isort]
- id: pyupgrade

- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: pydocstyle
files: ^detectree
- id: ruff
args: [ --fix ]
- id: ruff-format
13 changes: 8 additions & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: mambaforge-4.10

python:
install:
- requirements: requirements.txt
- requirements: requirements-dev.txt
- method: pip
path: .
install:
- method: pip
path: .
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![PyPI version fury.io](https://badge.fury.io/py/detectree.svg)](https://pypi.python.org/pypi/detectree/)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/detectree.svg)](https://anaconda.org/conda-forge/detectree)
[![Documentation Status](https://readthedocs.org/projects/detectree/badge/?version=latest)](https://detectree.readthedocs.io/en/latest/?badge=latest)
[![Build Status](https://github.com/martibosch/detectree/workflows/tests/badge.svg?branch=main)](https://github.com/martibosch/detectree/actions?query=workflow%3A%22tests%22)
[![tests](https://github.com/martibosch/detectree/actions/workflows/tests.yml/badge.svg)](https://github.com/martibosch/detectree/blob/main/.github/workflows/tests.yml)
[![codecov](https://codecov.io/gh/martibosch/detectree/branch/main/graph/badge.svg?token=ZTZK2LFR6T)](https://codecov.io/gh/martibosch/detectree)
[![GitHub license](https://img.shields.io/github/license/martibosch/detectree.svg)](https://github.com/martibosch/detectree/blob/master/LICENSE)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.02172/status.svg)](https://doi.org/10.21105/joss.02172)
Expand All @@ -11,7 +11,7 @@

## Overview

DetecTree is a Pythonic library to classify tree/non-tree pixels from aerial imagery, following the methods of Yang et al. [1]. The target audience is researchers and practitioners in GIS that are interested in two-dimensional aspects of trees, such as their proportional abundance and spatial distribution throughout a region of study. These measurements can be used to assess important aspects of urban planning such as the provision of urban ecosystem services. The approach is of special relevance when LIDAR data is not available or it is too costly in monetary or computational terms.
DetecTree is a Pythonic library to classify tree/non-tree pixels from aerial imagery, following the methods of Yang et al. \[1\]. The target audience is researchers and practitioners in GIS that are interested in two-dimensional aspects of trees, such as their proportional abundance and spatial distribution throughout a region of study. These measurements can be used to assess important aspects of urban planning such as the provision of urban ecosystem services. The approach is of special relevance when LIDAR data is not available or it is too costly in monetary or computational terms.

```python
import detectree as dtr
Expand Down Expand Up @@ -48,7 +48,7 @@ A full example application of DetecTree to predict a tree canopy map for the Aus

Bosch M. 2020. “DetecTree: Tree detection from aerial imagery in Python”. *Journal of Open Source Software, 5(50), 2172.* [doi.org/10.21105/joss.02172](https://doi.org/10.21105/joss.02172)

Note that DetecTree is based on the methods of Yang et al. [1], therefore it seems fair to reference their work too. An example citation in an academic paper might read as follows:
Note that DetecTree is based on the methods of Yang et al. \[1\], therefore it seems fair to reference their work too. An example citation in an academic paper might read as follows:

> The classification of tree pixels has been performed with the Python library DetecTree (Bosch, 2020), which is based on the approach of Yang et al. (2009).

Expand All @@ -58,29 +58,29 @@ Note that DetecTree is based on the methods of Yang et al. [1], therefore it see

The easiest way to install `detectree` is with conda as in:

``` bash
```bash
conda install -c conda-forge detectree
```

### With pip

You can install `detectree` with pip as in:

``` bash
```bash
pip install detectree
```

If you want to be able to read compressed LAZ files, you will need [the Python bindings for `laszip`](https://github.com/tmontaigu/laszip-python). Note that the latter require [`laszip`], which can be installed using conda (which is automatically handled when installing `detectree` with conda as shown above) or downloaded from [laszip.org](https://laszip.org/). Then, detectree and the Python bindings for `laszip` can be installed with pip as in:
If you want to be able to read compressed LAZ files, you will need [the Python bindings for `laszip`](https://github.com/tmontaigu/laszip-python). Note that the latter require \[`laszip`\], which can be installed using conda (which is automatically handled when installing `detectree` with conda as shown above) or downloaded from [laszip.org](https://laszip.org/). Then, detectree and the Python bindings for `laszip` can be installed with pip as in:

``` bash
```bash
pip install detectree[laszip]
```

### Development install

To install a development version of detectree, you can first use conda to create an environment with all the dependencies - with the [`environment-dev.yml` file](https://github.com/martibosch/detectree/blob/main/environment-dev.yml) - and activate it as in:

``` bash
```bash
conda env create -f environment-dev.yml
conda activate detectree-dev
```
Expand All @@ -101,12 +101,12 @@ pre-commit install

## See also

* [lausanne-tree-canopy](https://github.com/martibosch/lausanne-tree-canopy): example computational workflow to get the tree canopy of Lausanne with DetecTree
* [A video of a talk about DetecTree](https://www.youtube.com/watch?v=USwF2KyxVjY) in the [Applied Machine Learning Days of EPFL (2020)](https://appliedmldays.org/) and [its respective slides](https://martibosch.github.io/detectree-amld-2020)
- [lausanne-tree-canopy](https://github.com/martibosch/lausanne-tree-canopy): example computational workflow to get the tree canopy of Lausanne with DetecTree
- [A video of a talk about DetecTree](https://www.youtube.com/watch?v=USwF2KyxVjY) in the [Applied Machine Learning Days of EPFL (2020)](https://appliedmldays.org/) and [its respective slides](https://martibosch.github.io/detectree-amld-2020)

## Acknowledgments

* With the support of the École Polytechnique Fédérale de Lausanne (EPFL)
- With the support of the École Polytechnique Fédérale de Lausanne (EPFL)

## References

Expand Down
Loading

0 comments on commit 0ec2bc7

Please sign in to comment.