Skip to content

Commit

Permalink
Migrate to ruff and pylint to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Jun 14, 2024
1 parent ef23584 commit 65633df
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 65 deletions.
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

33 changes: 5 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,18 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/myint/autoflake
rev: v2.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.8"
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --expand-star-imports
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
- id: ruff
args: ["--fix"]
exclude: tests/testdata
args: [--py38-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- id: ruff-format
exclude: tests/testdata
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/
rev: v1.1.3
hooks:
- id: black-disable-checker
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear, flake8-typing-imports==1.12.0]
- repo: local
hooks:
- id: pylint
Expand Down
7 changes: 0 additions & 7 deletions .pylintrc

This file was deleted.

43 changes: 42 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[build-system]
build-backend = "setuptools.build_meta"

requires = [
"setuptools>=66.1",
]
Expand Down Expand Up @@ -40,3 +39,45 @@ optional-dependencies.test = [
"pytest-cov",
]
urls.Homepage = "https://github.com/pierre-sassoulas/pySankey"

[tool.ruff]
line-length = 88
src = [
"pysankey",
]
format.docstring-code-format = true
lint.select = [
"B", # bugbear
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
"PIE", # flake8-pie
"PLC", # pylint convention
"PLE", # pylint error
"PLR", # pylint refactor
"PLR1714", # Consider merging multiple comparisons
"PLW", # pylint warning
"PYI", # flake8-pyi
"RUF", # ruff
"T100", # flake8-debugger
"UP", # pyupgrade
"W", # pycodestyle
]
lint.ignore = [
"PLR0913", # Too many arguments in function definition
"PLR2004", # Magic value used in comparison
]

[tool.pylint.main]
# Good variable names which should always be accepted, separated by a comma
good-names = "i,j,k"
variable-naming-style = "camelCase"
argument-naming-style = "camelCase"

disable = [
"missing-docstring",
"invalid-name",
"too-many-arguments",
"too-many-locals",
]
2 changes: 1 addition & 1 deletion pysankey/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Make simple, pretty Sankey Diagrams """
"""Make simple, pretty Sankey Diagrams"""

from pysankey.sankey import LabelMismatch, NullsInFrame, PySankeyException, sankey

Expand Down
9 changes: 4 additions & 5 deletions pysankey/sankey/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
r"""
Produces simple Sankey Diagrams with matplotlib.
r"""Produces simple Sankey Diagrams with matplotlib.
@author: Anneya Golob & https://github.com/Pierre-Sassoulas/pySankey/graphs/contributors
.-.
.--.( ).--.
Expand Down Expand Up @@ -41,7 +40,8 @@ def check_data_matches_labels(
) -> None:
"""Check whether data matches labels.
Raise a LabelMismatch Exception if not."""
Raise a LabelMismatch Exception if not.
"""
if len(labels) > 0:
if isinstance(data, list):
data = set(data)
Expand Down Expand Up @@ -76,8 +76,7 @@ def sankey(
color_gradient: bool = False,
alphaDict: Optional[Dict[Union[str, Tuple[str, str]], float]] = None,
) -> Any:
"""
Make Sankey Diagram showing flow from left-->right
"""Make Sankey Diagram showing flow from left-->right
Inputs:
left = NumPy array of object labels on the left of the diagram
Expand Down
3 changes: 2 additions & 1 deletion tests/generic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class GenericTest(unittest.TestCase):
"""Generic tests for sankey
If figure_name is used, the resulting images
will be removed at the end of the tests."""
will be removed at the end of the tests.
"""

@classmethod
def setUpClass(cls):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_create_dataframe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd

from pysankey.sankey import _create_dataframe

from tests.generic_test import TestCustomerGood


Expand All @@ -17,8 +17,7 @@ def test_dataframe_correct_type(self) -> None:
self.assertIsInstance(dataframe, pd.DataFrame)

def test_sorted_dataframe(self) -> None:
"""
Tests that if we pass a sorted dataframe, it doesn't change the values due to
"""Tests that if we pass a sorted dataframe, it doesn't change the values due to
an index mismatch.
"""
# Pass the data as is
Expand Down
1 change: 1 addition & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pysankey import sankey

from tests.generic_test import TestFruit


Expand Down
7 changes: 4 additions & 3 deletions tests/test_error_case.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from pysankey import LabelMismatch, NullsInFrame, sankey

from tests.generic_test import TestFruit


class TestErrorCase(TestFruit):
"""Test sankey's error case."""

def test_bad_color_labels(self) -> None:
"""sankey raise a value error when there is not enough color info"""
"""Sankey raise a value error when there is not enough color info"""
bad_color_dict = {"apple": "#f71b1b", "orange": "#f78c1b"}
with self.assertRaises(ValueError) as value_error:
sankey(self.data["true"], self.data["predicted"], colorDict=bad_color_dict)
self.assertIn(": lime, blueberry, banana, kiwi", str(value_error.exception))

def test_label_mismatch(self) -> None:
"""sankey raises a LabelMismatch when data doesn't match the labels"""
"""Sankey raises a LabelMismatch when data doesn't match the labels"""
with self.assertRaises(LabelMismatch):
sankey(
self.data["true"],
Expand All @@ -23,6 +24,6 @@ def test_label_mismatch(self) -> None:
)

def test_nulls_in_frame(self) -> None:
"""sankey raises a NullsInFrame when left or right data is null"""
"""Sankey raises a NullsInFrame when left or right data is null"""
with self.assertRaises(NullsInFrame):
sankey([None], self.data["predicted"])
2 changes: 1 addition & 1 deletion tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import matplotlib.pyplot as plt

from pysankey import sankey

from tests.generic_test import TestCustomerGood, TestFruit


Expand Down
2 changes: 1 addition & 1 deletion tests/test_sankey.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import matplotlib.pyplot as plt

from pysankey import sankey

from tests.generic_test import TestFruit


Expand Down

0 comments on commit 65633df

Please sign in to comment.