Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9912371

Browse files
committed
ran pre-commit on everything
1 parent 7d18d97 commit 9912371

17 files changed

Lines changed: 340 additions & 200 deletions

.github/workflows/black.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: ruff 'n' stuff
2+
on: [pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- name: Install Python
10+
uses: actions/setup-python@v4
11+
with:
12+
python-version: "3.12"
13+
- name: Install dependencies
14+
run: |
15+
python -m pip install --upgrade pip
16+
pip install ruff
17+
# Update output format to enable automatic inline annotations.
18+
- name: Run Ruff
19+
run: ruff check --output-format=github .
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run coverage via codecov
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
8+
jobs:
9+
run:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Setup Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.11
17+
- name: Generate coverage report
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install flake8 pytest
21+
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
22+
coverage run --source paramnormal check_paramnormal.py --doctest-modules --cov-report=xml
23+
- name: Upload coverage to Codecov
24+
uses: codecov/codecov-action@v1
25+
with:
26+
# directory: ./coverage/reports/
27+
flags: unittests
28+
name: codecov-umbrella
29+
fail_ci_if_error: true
30+
path_to_write_report: ./codecov_report.gz
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Run basic unit tests
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.9", "3.10", "3.11", "3.12"]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install pytest
30+
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
31+
- name: Test with pytest
32+
run: |
33+
python check_paramnormal.py --doctest-modules
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Run image comparison tests
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python 3.12
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.12
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install flake8 pytest
26+
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
27+
- name: Test with pytest
28+
run: |
29+
export MPL_IMGCOMP_TOLERANCE=20
30+
python check_paramnormal.py --strict --verbose

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.2.0
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: [ --fix ]
9+
# Run the formatter.
10+
- id: ruff-format
11+
12+
- repo: https://github.com/pycqa/isort
13+
rev: 5.13.2
14+
hooks:
15+
- id: isort
16+
language_version: python3
17+
18+
- repo: https://github.com/asottile/pyupgrade
19+
rev: v3.15.0
20+
hooks:
21+
- id: pyupgrade
22+
args:
23+
- --py310-plus
24+
25+
- repo: https://github.com/MarcoGorelli/absolufy-imports
26+
rev: v0.3.1
27+
hooks:
28+
- id: absolufy-imports
29+
name: absolufy-imports

check_paramnormal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import sys
2+
23
import matplotlib
3-
matplotlib.use('agg')
4+
5+
matplotlib.use("agg")
46

57
import paramnormal
8+
69
status = paramnormal.test(*sys.argv[1:])
710
sys.exit(status)

paramnormal/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
from .dist import *
2-
from . import activity
3-
from . import utils
4-
5-
from .tests import test
1+
from paramnormal.dist import * # noqa
2+
from paramnormal.tests import test # noqa

paramnormal/activity.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import numpy
22
from matplotlib import pyplot
33

4-
from . import dist
5-
from . import utils
4+
from paramnormal import dist, utils
65

76

87
def _check_distro(distro, **params):
98
# check if we're returning the class definition or an instance
10-
as_class = params.pop('as_class', False)
11-
if hasattr(distro, 'pdf'):
9+
as_class = params.pop("as_class", False)
10+
if hasattr(distro, "pdf"):
1211
return distro
13-
elif hasattr(distro, 'from_params'):
12+
elif hasattr(distro, "from_params"):
1413
return _check_distro(distro.name, as_class=as_class, **params)
1514
else:
1615
try:
1716
distro = getattr(dist, distro)
18-
except:
19-
raise ValueError("{} is not a valid paramnormal distribution".format(distro))
17+
except (AttributeError, TypeError):
18+
raise ValueError(f"{distro} is not a valid paramnormal distribution")
2019

2120
_params = utils._remove_nones(**params)
2221
if as_class:
@@ -74,7 +73,7 @@ def random(distro, **params):
7473
7574
"""
7675

77-
shape = params.pop('shape', None)
76+
shape = params.pop("shape", None)
7877
distro = _check_distro(distro, **params)
7978
return distro.rvs(size=shape)
8079

@@ -121,8 +120,17 @@ def fit(distro, data, as_params=True, **guesses):
121120
return distro.from_params(params)
122121

123122

124-
def plot(distro, which='PDF', data=None, fit_dist=True, ax=None,
125-
pad=0.05, xscale='linear', line_opts=None, **guesses):
123+
def plot(
124+
distro,
125+
which="PDF",
126+
data=None,
127+
fit_dist=True,
128+
ax=None,
129+
pad=0.05,
130+
xscale="linear",
131+
line_opts=None,
132+
**guesses,
133+
):
126134
"""
127135
Plot the PDF of a dataset and other representations of the
128136
distribution (histogram, kernel density estimate, and rug plot).
@@ -248,11 +256,11 @@ def plot(distro, which='PDF', data=None, fit_dist=True, ax=None,
248256
fxn = getattr(distro, which.lower())
249257

250258
# determine and set the xlimits of the plot
251-
xlimits = distro.ppf([pad/100, 1 - pad/100])
259+
xlimits = distro.ppf([pad / 100, 1 - pad / 100])
252260

253261
# determine the x-values
254-
if xscale == 'log':
255-
#xlimits = numpy.log10(xlimits)
262+
if xscale == "log":
263+
# xlimits = numpy.log10(xlimits)
256264
x_hat = numpy.logspace(*numpy.log10(xlimits), num=100)
257265
else:
258266
x_hat = numpy.linspace(*xlimits, num=100)
@@ -261,9 +269,9 @@ def plot(distro, which='PDF', data=None, fit_dist=True, ax=None,
261269
y_hat = fxn(x_hat)
262270

263271
line_opts = dict() if line_opts is None else line_opts
264-
line_opts['label'] = line_opts.pop('label', which)
272+
line_opts["label"] = line_opts.pop("label", which)
265273

266-
line, = ax.plot(x_hat, y_hat, **line_opts)
274+
(line,) = ax.plot(x_hat, y_hat, **line_opts)
267275
ax.set_xscale(xscale)
268276

269277
return ax

0 commit comments

Comments
 (0)