Skip to content

Commit 9179527

Browse files
Merge pull request #11 from btschwertfeger/7-move-from-setuppy-to-pyprojecttoml
Move from setup.py to pyproject.toml
2 parents 1203a06 + 4154c72 commit 9179527

File tree

7 files changed

+157
-147
lines changed

7 files changed

+157
-147
lines changed

.github/workflows/codecov.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ jobs:
3939
- name: Install dependencies
4040
run: |
4141
python -m pip install --upgrade pip
42-
python -m pip install pytest pytest-cov
43-
python -m pip install -r requirements.txt
44-
python -m pip install -r tests/requirements.txt
4542
4643
- name: Install package
47-
run: python setup.py install
44+
run: python -m pip install ".[dev]"
4845

4946
- name: Generate coverage report
5047
run: |
51-
pip install pytest pytest-cov
5248
pytest --cov --cov-report=xml
5349
5450
- name: Upload coverage to Codecov

.github/workflows/python-package.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ jobs:
3939
- name: Install dependencies
4040
run: |
4141
python -m pip install --upgrade pip
42-
python -m pip install flake8 pytest scikit-learn scipy
43-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
44-
- name: Lint with flake8
45-
run: |
46-
# stop the build if there are Python syntax errors or undefined names
47-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
48-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
49-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
42+
# python -m pip install flake8 pytest scikit-learn scipy
43+
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
44+
45+
- name: Install the package
46+
run: python -m pip install ".[dev]"
47+
5048
- name: Test with pytest
5149
run: |
5250
pytest tests/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ share/python-wheels/
2626
.installed.cfg
2727
*.egg
2828
MANIFEST
29+
_version.py
2930

3031
# PyInstaller
3132
# Usually these files are written by a python script from a template

.pre-commit-config.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,31 @@ repos:
55
# all available hooks can be found here: https://github.com/pre-commit/pre-commit-hooks/blob/main/.pre-commit-hooks.yaml
66
- id: check-yaml
77
- id: check-ast
8+
- id: check-toml
89
- id: check-docstring-first
910
- id: check-case-conflict
1011
- id: check-merge-conflict
1112
- id: check-added-large-files
1213
args: ["--maxkb=500"]
14+
- id: check-executables-have-shebangs
1315
- id: trailing-whitespace
1416
- id: fix-byte-order-marker
1517
- id: fix-encoding-pragma
1618
- id: requirements-txt-fixer
19+
- id: mixed-line-ending
20+
- id: name-tests-test
21+
args: ["--pytest-test-first"]
1722
- id: end-of-file-fixer
18-
- id: check-executables-have-shebangs
23+
- id: pretty-format-json
1924
- id: detect-private-key
25+
- repo: https://github.com/pre-commit/pygrep-hooks
26+
rev: v1.10.0
27+
hooks:
28+
- id: python-use-type-annotations
29+
- id: rst-backticks
30+
# - id: rst-inline-touching-normal
31+
- id: rst-directive-colons
32+
- id: text-unicode-replacement-char
2033
- repo: https://github.com/psf/black
2134
rev: 23.1.0
2235
hooks:

Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!make
2+
# -*- coding: utf-8 -*-
3+
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
4+
# Github: https://github.com/btschwertfeger
5+
6+
VENV := venv
7+
GLOBAL_PYTHON := $(shell which python3)
8+
PYTHON := $(VENV)/bin/python3
9+
10+
.PHONY := build dev install test test_upload live_upload clean
11+
12+
## Builds the python-kraken-sdk
13+
##
14+
build:
15+
$(PYTHON) -m pip wheel -w dist --no-deps .
16+
17+
## Installs the package in edit mode
18+
##
19+
dev:
20+
$(PYTHON) -m pip install -e .[dev]
21+
22+
## Install the package
23+
##
24+
install:
25+
$(PYTHON) -m pip install .
26+
27+
## Run the unittests
28+
##
29+
test:
30+
$(PYTHON) -m pytest tests/
31+
32+
## Build the documentation
33+
##
34+
doc:
35+
cd docs && make html
36+
37+
## Run the documentation tests
38+
##
39+
doctest:
40+
cd docs && make doctest
41+
42+
## Pre-Commit
43+
pre-commit:
44+
@pre-commit run -a
45+
46+
## Clean the workspace
47+
##
48+
clean:
49+
rm -rf .pytest_cache build/ dist/ python_cmethods.egg-info docs/_build
50+
rm -f .coverage cmethods/_version.py
51+
52+
find tests -name "__pycache__" | xargs rm -rf
53+
find cmethods -name "__pycache__" | xargs rm -rf
54+
find examples -name "__pycache__" | xargs rm -rf

pyproject.toml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "python-cmethods"
7+
dynamic = ["version"]
8+
authors = [
9+
{ name="Benjamin Thomas Schwertfeger", email="[email protected]" },
10+
]
11+
description = "Collection of bias correction procedures for 1- and 3-dimensional climate data"
12+
readme = "README.md"
13+
license = {file = "LICENSE"}
14+
requires-python = ">=3.8"
15+
dependencies = [
16+
"xarray>=2022.11.0",
17+
"netCDF4>=1.6.1",
18+
"numpy",
19+
"tqdm",
20+
]
21+
keywords = [
22+
"climate-science",
23+
"bias",
24+
"bias-correction",
25+
"bias-adjustment",
26+
"climate-reanalysis",
27+
"reanalysis",
28+
"linear-scaling",
29+
"variance-scaling",
30+
"delta-method",
31+
"delta-change-method",
32+
"quantile-mapping",
33+
"quantile-delta-mapping"
34+
]
35+
classifiers = [
36+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
37+
"Programming Language :: Python",
38+
"Programming Language :: Python :: 3.8",
39+
"Programming Language :: Python :: 3.9",
40+
"Programming Language :: Python :: 3.10",
41+
"Programming Language :: Python :: 3.11",
42+
"Natural Language :: English",
43+
"Operating System :: MacOS",
44+
"Operating System :: Unix"
45+
]
46+
47+
[project.urls]
48+
"Homepage" = "https://github.com/btschwertfeger/python-cmethods"
49+
"Bug Tracker" = "https://github.com/btschwertfeger/python-cmethods/issues"
50+
51+
[tool.setuptools]
52+
include-package-data = false
53+
54+
[tool.setuptools.packages.find]
55+
include = ["cmethods*"]
56+
exclude = [
57+
"docs*",
58+
"tests*",
59+
"examples*",
60+
".env",
61+
]
62+
63+
[tool.setuptools_scm]
64+
write_to = "cmethods/_version.py"
65+
version_scheme = "guess-next-dev"
66+
local_scheme = "no-local-version"
67+
68+
[tool.pytest]
69+
junit_family = "xunit2"
70+
testpaths = ["tests"]
71+
72+
[project.optional-dependencies]
73+
dev = [
74+
"pytest", "pytest-cov",
75+
"scikit-learn", "scipy",
76+
"sphinx", "sphinx-rtd-theme"
77+
]
78+
examples = ["matplotlib"]

setup.py

Lines changed: 3 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -3,137 +3,7 @@
33
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
44
# Github: https://github.com/btschwertfeger
55

6-
import io
7-
import os
8-
import sys
9-
from shutil import rmtree
6+
import setuptools_scm # pylint: disable=unused-import
7+
from setuptools import setup
108

11-
from setuptools import Command, find_packages, setup
12-
13-
NAME = "python-cmethods"
14-
DESCRIPTION = (
15-
"Collection of bias adjustment procedures for multidimensional climate data"
16-
)
17-
URL = "https://github.com/btschwertfeger/Bias-Adjustment-Python"
18-
19-
AUTHOR = "Benjamin Thomas Schwertfeger"
20-
REQUIRES_PYTHON = ">=3.8.0"
21-
VERSION = "0.6.3"
22-
23-
# What packages are required for this module to be executed?
24-
REQUIRED = [
25-
"xarray>=2022.11.0",
26-
"netCDF4>=1.6.1",
27-
"numpy",
28-
"tqdm",
29-
]
30-
31-
# What packages are optional?
32-
EXTRAS = {
33-
"working examples notebook": ["matplotlib"],
34-
"tests": ["scikit-learn", "scipy"],
35-
}
36-
37-
here = os.path.abspath(os.path.dirname(__file__))
38-
39-
# only works if 'README.md' is present in your MANIFEST.in file!
40-
try:
41-
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
42-
long_description = f"\n{f.read()}"
43-
except FileNotFoundError:
44-
long_description = DESCRIPTION
45-
46-
47-
class UploadCommand(Command):
48-
"""Support setup.py upload."""
49-
50-
description = "Build and publish the package."
51-
user_options = []
52-
53-
@staticmethod
54-
def status(s):
55-
print(f"\033[1m{s}\033[0m")
56-
57-
def initialize_options(self):
58-
pass
59-
60-
def finalize_options(self):
61-
pass
62-
63-
def run(self):
64-
try:
65-
self.status("Removing previous builds…")
66-
rmtree(os.path.join(here, "dist"))
67-
except OSError:
68-
pass
69-
70-
self.status("Building Source and Wheel (universal) distribution…")
71-
os.system(f"{sys.executable} setup.py sdist bdist_wheel --universal")
72-
73-
self.status("Uploading the package to PyPI via Twine…")
74-
os.system("twine upload dist/*")
75-
sys.exit(0)
76-
77-
78-
class TestUploadCommand(Command):
79-
"""Support setup.py test upload."""
80-
81-
description = "Build and test publishing the package."
82-
user_options = []
83-
84-
@staticmethod
85-
def status(s):
86-
print(f"\033[1m{s}\033[0m")
87-
88-
def initialize_options(self):
89-
pass
90-
91-
def finalize_options(self):
92-
pass
93-
94-
def run(self):
95-
try:
96-
self.status("Removing previous builds…")
97-
rmtree(os.path.join(here, "dist"))
98-
except OSError:
99-
pass
100-
101-
self.status("Building Source and Wheel (universal) distribution…")
102-
os.system(f"{sys.executable} setup.py sdist bdist_wheel --universal")
103-
104-
self.status("Uploading the package to PyPI via Twine…")
105-
os.system("twine upload -r testpypi dist/*")
106-
107-
sys.exit(0)
108-
109-
110-
setup(
111-
name=NAME,
112-
version=VERSION,
113-
description=DESCRIPTION,
114-
long_description=long_description,
115-
long_description_content_type="text/markdown",
116-
author=AUTHOR,
117-
author_email=EMAIL,
118-
python_requires=REQUIRES_PYTHON,
119-
url=URL,
120-
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
121-
install_requires=REQUIRED,
122-
extras_require=EXTRAS,
123-
include_package_data=True,
124-
license="GPLv3",
125-
classifiers=[
126-
# Trove classifiers
127-
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
128-
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
129-
"Programming Language :: Python",
130-
"Programming Language :: Python :: 3.8",
131-
"Natural Language :: English",
132-
"Operating System :: MacOS",
133-
"Operating System :: Unix",
134-
],
135-
cmdclass={
136-
"upload": UploadCommand,
137-
"test": TestUploadCommand,
138-
},
139-
)
9+
setup()

0 commit comments

Comments
 (0)