Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed May 23, 2024
1 parent 213486b commit 866e0e6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 84 deletions.
57 changes: 18 additions & 39 deletions cc_plugin_glider/glider_dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def check_dimensions(self, dataset):
test = dimension in dataset.dimensions
score += int(test)
if not test:
messages.append("%s is not a valid dimension" % dimension)
messages.append(f"{dimension} is not a valid dimension")
return self.make_result(level, score, out_of, "Required Dimensions", messages)

def check_lat_lon_attributes(self, dataset):
Expand Down Expand Up @@ -348,7 +348,7 @@ def check_global_attributes(self, dataset):
score += int(test)
out_of += 1
if not test:
messages.append("Attr %s not present" % field)
messages.append(f"Attr {field} not present")
continue
v = getattr(dataset, field, "")
if isinstance(v, str):
Expand All @@ -358,7 +358,7 @@ def check_global_attributes(self, dataset):
score += int(test)
out_of += 1
if not test:
messages.append("Attr %s is empty" % field)
messages.append(f"Attr {field} is empty")

"""
Verify that sea_name attribute exists and is valid
Expand Down Expand Up @@ -636,31 +636,25 @@ def check_qartod(self, dataset):

test_ctx.assert_true(
getattr(ncvar, "long_name", ""),
"attribute {}:long_name must be a non-empty string".format(
qartod_var,
),
f"attribute {qartod_var}:long_name must be a non-empty string",
)

test_ctx.assert_true(
getattr(ncvar, "flag_meanings", ""),
"attribute {}:flag_meanings must be a non-empty string".format(
qartod_var,
),
f"attribute {qartod_var}:flag_meanings must be a non-empty string",
)

test_ctx.assert_true(
isinstance(flag_values, np.ndarray),
"attribute {}:flag_values must be defined as an array of bytes".format(
qartod_var,
),
f"attribute {qartod_var}:flag_values must be defined as an array of bytes",
)

if isinstance(flag_values, np.ndarray):
dtype = flag_values.dtype
test_ctx.assert_true(
util.compare_dtype(dtype, np.dtype("|i1")),
"attribute {}:flag_values has an illegal data-type, must "
"be byte".format(qartod_var),
f"attribute {qartod_var}:flag_values has an illegal data-type, must "
"be byte",
)

valid_min_dtype = getattr(valid_min, "dtype", None)
Expand Down Expand Up @@ -699,8 +693,8 @@ def check_ancillary_variables(self, dataset):
score += int(test)
if not test:
msg = (
"Invalid ancillary_variables attribute for {}, "
"{} is not a variable".format(var, acv)
f"Invalid ancillary_variables attribute for {var}, "
f"{acv} is not a variable"
)
messages.append(msg)

Expand Down Expand Up @@ -752,8 +746,8 @@ def check_valid_min_dtype(self, dataset):
if valid_min is not None:
test_ctx.assert_true(
util.compare_dtype(np.dtype(valid_min_dtype), ncvar.dtype),
"{}:valid_min has a different data type, {}, than variable {}, "
"{}".format(var_name, valid_min_dtype, var_name, str(ncvar.dtype)),
f"{var_name}:valid_min has a different data type, {valid_min_dtype}, than variable {var_name}, "
f"{str(ncvar.dtype)}",
)

return test_ctx.to_result()
Expand All @@ -780,8 +774,8 @@ def check_valid_max_dtype(self, dataset):
if valid_max is not None:
test_ctx.assert_true(
util.compare_dtype(np.dtype(valid_max_dtype), ncvar.dtype),
"{}:valid_max has a different data type, {}, than variable {} "
"{}".format(var_name, valid_max_dtype, str(ncvar.dtype), var_name),
f"{var_name}:valid_max has a different data type, {valid_max_dtype}, than variable {str(ncvar.dtype)} "
f"{var_name}",
)

return test_ctx.to_result()
Expand Down Expand Up @@ -895,42 +889,27 @@ def check_ncei_tables(self, dataset):

for var_name in var_name_set:
if var_name not in dataset.variables:
msg = "Referenced {} variable {} does not exist".format(
global_att_name,
var_name,
)
msg = f"Referenced {global_att_name} variable {var_name} does not exist"
test_ctx.assert_true(False, msg)
continue

var = dataset.variables[var_name]
# have to use .ncattrs, hangs if using `in var` ?
var_attr_exists = var_remap[global_att_name] in var.ncattrs()
msg = "Attribute {} should exist in variable {}".format(
var_remap[global_att_name],
var_name,
)
msg = f"Attribute {var_remap[global_att_name]} should exist in variable {var_name}"
test_ctx.assert_true(var_attr_exists, msg)

if not var_attr_exists:
continue
search_attr = getattr(var, var_remap[global_att_name])

msg = "Attribute {} '{}' for variable {} not contained in {} authority table".format(
var_remap[global_att_name],
search_attr,
var_name,
global_att_name,
)
msg = f"Attribute {var_remap[global_att_name]} '{search_attr}' for variable {var_name} not contained in {global_att_name} authority table"
test_ctx.assert_true(search_attr in check_set, msg)

else:
# check for global attribute existence already handled above
global_att_value = getattr(dataset, global_att_name)
msg = "Global attribute {} value '{}' not contained in {} authority table".format(
global_att_name,
global_att_value,
global_att_name,
)
msg = f"Global attribute {global_att_name} value '{global_att_value}' not contained in {global_att_name} authority table"
test_ctx.assert_true(global_att_value in check_set, msg)

return test_ctx.to_result()
1 change: 1 addition & 0 deletions cc_plugin_glider/required_var_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Attributes with values set to None mean we only check that the attribute exists, not whether the value matches
"""

required_var_attrs = {
"time": {
"dtype": "f8",
Expand Down
1 change: 1 addition & 0 deletions cc_plugin_glider/tests/resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
cc_plugin_glider/tests/resources.py
"""

import importlib
import subprocess

Expand Down
1 change: 1 addition & 0 deletions cc_plugin_glider/tests/test_glidercheck.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
cc_plugin_glider/tests/test_glidercheck.py
"""

import os
import unittest
from urllib.parse import urljoin
Expand Down
7 changes: 2 additions & 5 deletions cc_plugin_glider/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
cc_plugin_glider/util.py
"""

from operator import eq

import numpy as np
Expand Down Expand Up @@ -108,11 +109,7 @@ def _check_variable_attrs(dataset, var_name, required_attributes=None):
score -= 1
else:
messages.append(
"Variable {} attribute {} must be {}".format(
var_name,
attr,
check_attrs[attr],
),
f"Variable {var_name} attribute {attr} must be {check_attrs[attr]}",
)
score -= 1
else:
Expand Down
84 changes: 44 additions & 40 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=42",
"setuptools_scm",
"setuptools-scm",
"wheel",
]

[project.readme]
file = "README.md"
content-type = "text/markdown"

[project]
name = "cc-plugin-glider"
description = "Compliance Checker Glider DAC plugin"
license = {text = "Apache-2.0"}
readme.content-type = "text/markdown"
readme.file = "README.md"
license = { text = "Apache-2.0" }
maintainers = [
{name = "Robert Fratantonio", email="[email protected]"},
{ name = "Robert Fratantonio", email = "[email protected]" },
]
requires-python = ">=3.9"
classifiers = [
Expand All @@ -30,55 +28,61 @@ dynamic = [
"version",
]

[project.urls]
documentation = "http://ioos.github.io/compliance-checker/"
homepage = "https://github.com/ioos/cc-plugin-glider"
repository = "https://github.com/ioos/cc-plugin-glider"
[project.entry-points."compliance_checker.suites"]
"gliderdac" = "cc_plugin_glider.glider_dac:GliderCheck"
urls.documentation = "http://ioos.github.io/compliance-checker/"
urls.homepage = "https://github.com/ioos/cc-plugin-glider"
urls.repository = "https://github.com/ioos/cc-plugin-glider"
entry-points."compliance_checker.suites"."gliderdac" = "cc_plugin_glider.glider_dac:GliderCheck"

[tool.setuptools]
packages = ["cc_plugin_glider"]
packages = [
"cc_plugin_glider",
]
include-package-data = true
license-files = ["LICENSE.txt"]
license-files = [
"LICENSE.txt",
]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
readme = {file = "README.md", content-type = "text/markdown"}
dependencies = { file = [
"requirements.txt",
] }
readme = { file = "README.md", content-type = "text/markdown" }

[tool.setuptools_scm]
write_to = "cc_plugin_glider/_version.py"
write_to_template = "__version__ = '{version}'"
tag_regex = "^(?P<prefix>v)?(?P<version>[^\\+]+)(?P<suffix>.*)?$"

[tool.ruff]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"F", # flakes
"I", # import sorting
"T20", # flake8-print
"UP", # upgrade
]
target-version = "py38"
line-length = 79

[tool.pytest.ini_options]
filterwarnings = [
"error:::cc-plugin-glider.*",
"ignore::UserWarning",
"ignore::RuntimeWarning",
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"F", # flakes
"I", # import sorting
"T20", # flake8-print
"UP", # upgrade
]

[tool.check-manifest]
ignore = [
"*.yml",
".coveragerc",
"Makefile",
"docs",
"docs/*",
"notebooks",
"notebooks/*",
"tests",
"tests/*",
"*.yml",
".coveragerc",
"Makefile",
"docs",
"docs/*",
"notebooks",
"notebooks/*",
"tests",
"tests/*",
]

[tool.pytest.ini_options]
filterwarnings = [
"error:::cc-plugin-glider.*",
"ignore::UserWarning",
"ignore::RuntimeWarning",
]

0 comments on commit 866e0e6

Please sign in to comment.