Skip to content

Commit

Permalink
refactor: update ruff rules and fix some type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
leifwar authored and davidkleiven committed Jan 6, 2025
1 parent 6fa3c44 commit fc9a7ec
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 14 deletions.
52 changes: 48 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,67 @@ select = [
"C4", # flake8-comprehensions
"C90", # mccabe
"COM", # flake8-commas
"D", # pydocstyle
"DTZ", # flake8-datetimez
"E", "W", # pycodestyle
"ERA", # eradicate
"F", # Pyflakes
"FA",
"FBT", # boolean trap
"FIX", # fix me
"FLY", # flynt
"FURB", # refurb
"G", # flake8-logging-format
"I", # isort
"ICN", # import conventions
"INP", # no pep420
"INT", # gettext
"ISC", # implicit str concat
"LOG", # flake8-logging
"N", # pep8-nameing
"NPY", # numpy specific rules
"PD", # pandas vet
"PERF", # Perflint
"PGH",
"PIE", # flake8-pie
"PL", # pylint
"PT", # pytest style
"PTH", # Pathlib
"Q", # quotes
"RET", # Return
"RSE", # raise
"RUF", # Ruff specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"SLF", # Self
"SLOT",
"T10", # debug statements
"T20", # flake8-print
"TC", # Type checking
"TCH", # flake8-type-checking
"TID", # tidy import
"TRY", # tryceratops
"UP", # pyupgrade
"YTT", # flake8-2020
]

ignore = ['S101', 'COM812', 'ANN101', 'ANN102', 'ANN401', 'TRY003']
ignore = [
'ANN401',
'COM812',
'D101',
'D102',
'D103',
'D105',
'D107',
'D203',
'D213',
'D413',
'FBT001',
'FBT002',
'FIX002',
'S101',
'TRY003'
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
Expand Down Expand Up @@ -101,11 +141,15 @@ exclude = [
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"


[tool.ruff.lint.per-file-ignores]
"cimsparql/data_models.py" = ["N815"]
"docs/conf.py" = ["A001"]
"docs/conf.py" = ["A001", "INP001", "D100"]
"src/cimsparql/data_models.py" = ["N815"]
"src/cimsparql/graphdb.py" = ["PD901"]
"src/cimsparql/model.py" = ["PD901"]
"src/cimsparql/type_mapper.py" = ["PD901"]
"tests/**/*.py" = [ "D100", "D101", "D103", "D104", "PLR2004"]
"tests/test*.py" = ["ANN201"]
"tests/test_type_mapper.py" = ["PD901"]

[tool.ruff.lint.pep8-naming]
# Allow Pydantic's `@validator` decorator to trigger class method treatment.
Expand Down
2 changes: 1 addition & 1 deletion src/cimsparql/graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __post_init__(self) -> None:
def url(self) -> str:
if self.rest_api == RestApi.BLAZEGRAPH:
return service_blazegraph(self.server, self.repo, self.protocol)
elif self.rest_api == RestApi.DIRECT_SPARQL_ENDPOINT:
if self.rest_api == RestApi.DIRECT_SPARQL_ENDPOINT:
return self.server
return service(self.repo, self.server, self.protocol, self.path)

Expand Down
2 changes: 0 additions & 2 deletions src/cimsparql/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"""

from __future__ import annotations


def service(repo: str | None = None, server: str = "127.0.0.1:7200", protocol: str = "https", path: str = "") -> str:
"""Service url for GraphdDBClient.
Expand Down
2 changes: 1 addition & 1 deletion src/cimsparql/value_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class ValueMapper:
"""Base value mapper."""

def map(self, df: pd.DataFrame) -> pd.DataFrame: # A003
def map(self, df: pd.DataFrame) -> pd.DataFrame:
return df


Expand Down
2 changes: 1 addition & 1 deletion tests/test_graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


def exception_logging(func: Callable[[Any], pd.DataFrame], *args: Any):
logger.debug(f"Starting {func.__name__}")
logger.debug("Starting %s", func.__name__)
try:
return func(*args)
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def get_node_consistency_test_data(
)


async def collect_node_consistency_data() -> list[NodeConsistencyData]:
async def collect_node_consistency_data() -> list[NodeConsistencyData | None]:
test_models = [t_custom.federated_model(), t_entsoe.micro_t1_nl()]
if any(m.model is None and m.must_run_in_ci and os.getenv("CI") for m in test_models):
pytest.fail("Model that must run in CI is None")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_type_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_map_data_types(httpserver: HTTPServer):
("date", ("2021-12-14", pd.Timestamp("2021-12-14 00:00:00"))),
(
"dateTime",
("2002-10-14T12:00:00", datetime.datetime(2002, 10, 14, 12, 0, 0)), # noqa DTZ001
("2002-10-14T12:00:00", datetime.datetime(2002, 10, 14, 12, 0, 0)), # noqa: DTZ001
),
("dateTime", ("2002-10-14T12:00:00Z", pd.Timestamp("2002-10-14 12:00:00+0000", tz="UTC"))),
("duration", ("P365D", datetime.timedelta(365))),
Expand All @@ -105,7 +105,7 @@ def test_map_data_types(httpserver: HTTPServer):
("time", ("21:32:52Z", pd.Timestamp("21:32:52", tz="UTC"))),
],
)
def test_xsd_types(dtype: str, test: tuple):
def test_xsd_types(dtype: str, test: tuple[str, Any]):
value, expect = test
assert type_mapper.XSD_TYPE_MAP[dtype](value) == expect

Expand Down Expand Up @@ -135,7 +135,7 @@ class FloatSchema(CoercingSchema):
({"float_col": ["1.0", None]}, {"float_col": [1.0, np.nan]}),
],
)
def test_coerce_missing_type(httpserver: HTTPServer, in_data: dict, out_data: dict):
def test_coerce_missing_type(httpserver: HTTPServer, in_data: dict[str, Any], out_data: dict[str, Any]):
client = init_triple_store_server(httpserver)
in_df, out_df = pd.DataFrame(in_data), pd.DataFrame(out_data)
mapper = type_mapper.TypeMapper(client)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xml_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@pytest.fixture
def xml_adaptor():
folder = Path(__file__).parent / "data/micro"
folder = Path(__file__).parent / "data" / "micro"
return XmlModelAdaptor.from_folder(folder)


Expand Down

0 comments on commit fc9a7ec

Please sign in to comment.