Skip to content

Commit

Permalink
Merge pull request #10 from roocs/modernize
Browse files Browse the repository at this point in the history
Modern Packaging
  • Loading branch information
sol1105 authored Oct 25, 2023
2 parents bc7dd34 + 259326a commit 002a3d0
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 126 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/first_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: First Pull Request

on:
pull_request_target:
types:
- opened

jobs:
welcome:
name: Welcome
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
// Get a list of all issues created by the PR opener
// See: https://octokit.github.io/rest.js/#pagination
const creator = context.payload.sender.login
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
creator,
state: 'all'
})
const issues = await github.paginate(opts)
for (const issue of issues) {
if (issue.number === context.issue.number) {
continue
}
if (issue.pull_request) {
return // Creator is already a contributor.
}
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `**Welcome**, new contributor!
It appears that this is your first Pull Request. To give credit where it's due, we ask that you add your information to the \`AUTHORS.rst\`:
- [ ] The relevant author information has been added to \`AUTHORS.rst\`
Please make sure you've read our [contributing guide](CONTRIBUTING.rst). We look forward to reviewing your Pull Request shortly ✨`
})
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: roocs-grids Testing Suite

on:
push:
branches:
- master
pull_request:

jobs:
black:
runs-on: ubuntu-latest
strategy:
matrix:
tox-env:
- black
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install linters
run: |
pip install black ruff
- name: Run linting suite
run: |
black --check roocs_grids
ruff roocs_grids
test:
name: Pip with Python${{ matrix.python-version }}
needs: black
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install roocs-grids
run: |
pip install -e ".[dev]"
- name: Run tests
run: |
pytest
55 changes: 29 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,46 @@ default_language_version:
python: python3

repos:
- repo: https://github.com/asottile/pyupgrade
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [ '--py39-plus' ]
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: mixed-line-ending
- repo: https://github.com/psf/black
- id: trailing-whitespace
exclude: setup.cfg
- id: end-of-file-fixer
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: mixed-line-ending
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: ["--target-version", "py39"]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
hooks:
- id: flake8
args: ['--ignore=E501']
- repo: https://github.com/PyCQA/isort
- id: ruff
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ['--profile', 'black']
#- repo: https://github.com/pycqa/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
# args: ["--convention=numpy"]
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- id: isort
args: ['--profile', 'black']
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
hooks:
- id: check-github-workflows
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

ci:
autofix_commit_msg: |
Expand Down
15 changes: 15 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=======
Credits
=======

Development Leads
-----------------

* Ag Stephens <[email protected]> `@agstephens <https://github.com/agstephens>`_
* Martin Schupfner <[email protected]> `@sol1105 <https://github.com/sol1105>`_

Contributors
-------------

* Carsten Ehbrecht <[email protected]> `@cehbrecht <https://github.com/cehbrecht>`_
* Trevor James Smith <[email protected]> `@Zeitsperre <https://github.com/Zeitsperre>`_
12 changes: 12 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Version History
===============

v0.1.2 (2023-10-25)
-------------------

Bug Fixes
^^^^^^^^^

* Added basic CI workflows
* Replaced setuptools with flit and pyproject.toml
* Added AUTHORS.rst and bump2version configuration
* Linting with ruff
* Made testing safer with non-POSIX environments

v0.1.1 (2023-10-20)
-------------------

Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
roocs-grids
===========

Grid definitions for the roocs regridder:
Grid definitions for the roocs regridder.

* Grids suggested for CMIP6: `Link <https://docs.google.com/document/d/1BfVVsKAk9MAsOYstwFSWI2ZBt5mrO_Nmcu7rLGDuL08/edit_>`_
* Grids used for the `IPCC Atlas <https://interactive-atlas.ipcc.ch/_>`_: `Link <https://github.com/SantanderMetGroup/ATLAS_>`_
Expand Down
93 changes: 93 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[build-system]
build-backend = "flit_core.buildapi"
requires = ["flit_core >=3.8,<4"]

[project]
name = "roocs_grids"
keywords = ["roocs_grids", "regrid", "grid", "interpolate", "cmip"]
authors = [
{name = "Ag Stephens", email = "[email protected]"},
{name = "Martin Schupfner", email = "[email protected]"}
]
maintainers = [
{name = "Carsten Ehbrecht", email = "[email protected]"},
{name = "Trevor James Smith", email = "[email protected]"}
]
license = {file = "LICENSE"}
python_requires = ">=3.8.0"
dynamic = ["description", "version"]
dependencies = []
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Atmospheric Science",
"Topic :: Scientific/Engineering :: GIS",
"Topic :: Software Development :: Libraries :: Python Modules"
]

[project.optional-dependencies]
dev = [
"black",
"bump2version",
"clisops",
"isort",
"pytest>=7.0.0",
"ruff>=0.1.0",
"xarray"
]

[project.urls]
"Source" = "https://github.com/roocs/roocs-grids/"
"Changelog" = "https://github.com/roocs/roocs-grids/blob/main/HISTORY.rst"
"Issue tracker" = "https://github.com/roocs/roocs-grids/issues"
"About ROOCS" = "https://roocs.github.io/"

[tool.black]
target-version = [
"py38",
"py39",
"py310",
"py311"
]

[tool.flit.sdist]
include = [
"AUTHORS.rst",
"HISTORY.rst",
"LICENSE",
"README.rst",
"tests/*.py"
]
exclude = [
"**/*.py[co]",
"**/__pycache__",
".*",
"scripts/*"
]

[tool.isort]
profile = "black"
py_version = 38

[tool.ruff]
src = ["roocs_grids"]
line-length = 88
target-version = "py38"
ignore = ["E501"]

[tool.ruff.format]
line-ending = "auto"

[tool.ruff.isort]
known-first-party = ["roocs_grids"]
lines-after-imports = 1
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

4 changes: 0 additions & 4 deletions requirements_dev.txt

This file was deleted.

18 changes: 12 additions & 6 deletions roocs_grids/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
"""Grid definitions for the roocs regridder."""
import pathlib

pkg_dir = os.path.dirname(__file__)
__author__ = "Martin Schupfner"
__email__ = "[email protected]"
__copyright__ = "Copyright 2018 United Kingdom Research and Innovation"
__version__ = "0.1.2"

pkg_dir = pathlib.Path(__file__).parent.absolute()

grid_dict = {
"0pt25deg": "cmip6_720x1440_scrip.20181001.nc",
Expand Down Expand Up @@ -76,11 +82,11 @@
" 384x768 nlatxnlon. Associated to a T255 spectral grid representation.",
}

grids_dir = os.path.join(pkg_dir, "grids")
grids_dir = pathlib.Path(pkg_dir).joinpath("grids")


def get_grid_file(grid_id):
def get_grid_file(grid_id: str) -> pathlib.Path:
if grid_id not in grid_dict:
raise Exception(f"Unknown grid id: {grid_id}")
raise FileNotFoundError(f"Unknown grid id: {grid_id}")

return os.path.join(grids_dir, grid_dict[grid_id])
return pathlib.Path(grids_dir).joinpath(grid_dict[grid_id])
3 changes: 0 additions & 3 deletions aux/create_grid_file.py → scripts/create_grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from pathlib import Path

import xarray as xr

# FIXME: This is a circular dependency, as clisops will be listing roocs-grids as a dependency
# this must be addressed before this module can be used.
from clisops import core as clore

from roocs_grids import grids_dir, pkg_dir
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[bumpversion]
current_version = 0.1.2
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)
serialize =
{major}.{minor}.{patch}

[bumpversion:file:roocs_grids/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
Loading

0 comments on commit 002a3d0

Please sign in to comment.