Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow custom CF url (-d) #1066

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cc-plugin-glider-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
create-args: >-
python=3 pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes like this make it hard to follow the actual changes in the PR. While I personally prefer the requirements-dev.txt we are stuck with the original file name here and no need to change it now.

PS: I'd welcome a change like this in its own PR, away from important code changes that require careful review.

--channel conda-forge

- name: Install compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cc-plugin-sgrid-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
create-args: >-
python=3 pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
--channel conda-forge

- name: Install compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cc-plugin-ugrid-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
create-args: >-
python=3 pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
--channel conda-forge

- name: Install compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
create-args: >-
python=3 pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
--channel conda-forge

- name: Install compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/default-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
create-args: >-
python=${{ matrix.python-version }} pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
--channel conda-forge

- name: Install compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
create-args: >-
python=3 pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
--channel conda-forge

- name: Install compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
create-args: >-
python=3 pip
--file requirements.txt
--file test_requirements.txt
--file requirements-test.txt
--channel conda-forge

- name: Install compliance-checker
Expand Down
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ repos:
- id: requirements-txt-fixer
args:
- requirements.txt
- test_requirements.txt
- requirements-dev.txt
- requirements-docs.txt
- requirements-test.txt

- repo: https://github.com/psf/black
rev: 24.4.0
Expand Down
2 changes: 1 addition & 1 deletion cchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def main():
check_suite.load_generated_checkers(args)

if args.version:
print("IOOS compliance checker version %s" % __version__)
print(f"IOOS compliance checker version {__version__}")
sys.exit(0)

options_dict = parse_options(args.option) if args.option else defaultdict(set)
Expand Down
2 changes: 1 addition & 1 deletion compliance_checker/acdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def check_time_extents(self, ds):
BaseCheck.MEDIUM,
False,
"time_coverage_extents_match",
["Failed to retrieve and convert times for variables %s." % timevar],
[f"Failed to retrieve and convert times for variables {timevar}."],
)

start_dt = abs(time0 - t_min)
Expand Down
6 changes: 3 additions & 3 deletions compliance_checker/cf/cf_1_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def check_names_unique(self, ds):
names[k.lower()] += 1

fails = [
"Variables are not case sensitive. Duplicate variables named: %s" % k
f"Variables are not case sensitive. Duplicate variables named: {k}"
for k, v in names.items()
if v > 1
]
Expand Down Expand Up @@ -1822,7 +1822,7 @@ def check_time_coordinate(self, ds):
BaseCheck.HIGH,
False,
self.section_titles["4.4"],
["%s does not have units" % name],
[f"{name} does not have units"],
)
ret_val.append(result)
continue
Expand All @@ -1833,7 +1833,7 @@ def check_time_coordinate(self, ds):
correct_units = util.units_temporal(variable.units)
reasoning = None
if not correct_units:
reasoning = ["%s does not have correct time units" % name]
reasoning = [f"{name} does not have correct time units"]
result = Result(
BaseCheck.HIGH,
correct_units,
Expand Down
17 changes: 10 additions & 7 deletions compliance_checker/cf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@
def _get(self, entrynode, attrname, required=False):
vals = entrynode.xpath(attrname)
if len(vals) > 1:
raise Exception("Multiple attrs (%s) found" % attrname)
raise Exception(f"Multiple attrs ({attrname}) found")

Check warning on line 202 in compliance_checker/cf/util.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/util.py#L202

Added line #L202 was not covered by tests
elif required and len(vals) == 0:
raise Exception("Required attr (%s) not found" % attrname)
raise Exception(f"Required attr ({attrname}) not found")

Check warning on line 204 in compliance_checker/cf/util.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/util.py#L204

Added line #L204 was not covered by tests

return vals[0].text

Expand Down Expand Up @@ -236,22 +236,21 @@

def __getitem__(self, key):
if not (key in self._names or key in self._aliases):
raise KeyError("%s not found in standard name table" % key)
raise KeyError(f"{key} not found in standard name table")

if key in self._aliases:
idx = self._aliases.index(key)
entryids = self._root.xpath("alias")[idx].xpath("entry_id")

if len(entryids) != 1:
raise Exception(
"Inconsistency in standard name table, could not lookup alias for %s"
% key,
f"Inconsistency in standard name table, could not lookup alias for {key}",
)

key = entryids[0].text

if key not in self._names:
raise KeyError("%s not found in standard name table" % key)
raise KeyError(f"{key} not found in standard name table")

Check warning on line 253 in compliance_checker/cf/util.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/util.py#L253

Added line #L253 was not covered by tests

idx = self._names.index(key)
entry = self.NameEntry(self._root.xpath("entry")[idx])
Expand Down Expand Up @@ -289,7 +288,11 @@
if version == "latest":
url = "http://cfconventions.org/Data/cf-standard-names/current/src/cf-standard-name-table.xml"
else:
url = f"http://cfconventions.org/Data/cf-standard-names/{version}/src/cf-standard-name-table.xml"
if version.startswith("http"):
url = version
version = '"url specified"'

Check warning on line 293 in compliance_checker/cf/util.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/util.py#L292-L293

Added lines #L292 - L293 were not covered by tests
Copy link
Member

@ocefpaf ocefpaf May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could say "custom URL"? Although, if this variable is not used anywhere we can probably remove it here.

else:
url = f"http://cfconventions.org/Data/cf-standard-names/{version}/src/cf-standard-name-table.xml"

r = requests.get(url, allow_redirects=True)
r.raise_for_status()
Expand Down
5 changes: 2 additions & 3 deletions compliance_checker/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
cls.json_output(cs, score_dict, output_filename, ds_loc, limit, out_fmt)

else:
raise TypeError("Invalid format %s" % out_fmt)
raise TypeError(f"Invalid format {out_fmt}")

Check warning on line 128 in compliance_checker/runner.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/runner.py#L128

Added line #L128 was not covered by tests

errors_occurred = cls.check_errors(score_groups, verbose)

Expand Down Expand Up @@ -259,8 +259,7 @@
if len(errors):
errors_occurred = True
print(
"WARNING: The following exceptions occurred during the %s checker (possibly indicate compliance checker issues):"
% checker,
f"WARNING: The following exceptions occurred during the {checker} checker (possibly indicate compliance checker issues):",
file=sys.stderr,
)
for check_name, epair in errors.items():
Expand Down
4 changes: 2 additions & 2 deletions compliance_checker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def new_nc_file(tmpdir):
"""
nc_file_path = os.path.join(tmpdir, "example.nc")
if os.path.exists(nc_file_path):
raise OSError("File Exists: %s" % nc_file_path)
raise OSError(f"File Exists: {nc_file_path}")
nc = Dataset(nc_file_path, "w")
# no need for cleanup, built-in tmpdir fixture will handle it
return nc
Expand All @@ -101,7 +101,7 @@ def new_nc_file(tmpdir):
def tmp_txt_file(tmpdir):
file_path = os.path.join(tmpdir, "output.txt")
if os.path.exists(file_path):
raise OSError("File Exists: %s" % file_path)
raise OSError(f"File Exists: {file_path}")

return file_path

Expand Down
2 changes: 1 addition & 1 deletion compliance_checker/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_attr_in_valid_choices(self):
priority,
(1, 2),
"test",
["test present, but not in expected value list (%s)" % valid_choices],
[f"test present, but not in expected value list ({valid_choices})"],
)
self.ds.test = "a"
base.attr_check(attr, self.ds, priority, rv3)
Expand Down
2 changes: 1 addition & 1 deletion compliance_checker/tests/test_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def new_nc_file(self):
"""
nc_file_path = os.path.join(gettempdir(), "example.nc")
if os.path.exists(nc_file_path):
raise OSError("File Exists: %s" % nc_file_path)
raise OSError(f"File Exists: {nc_file_path}")
nc = Dataset(nc_file_path, "w")
self.addCleanup(os.remove, nc_file_path)
self.addCleanup(nc.close)
Expand Down
10 changes: 10 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
flake8
flake8-builtins
flake8-comprehensions
flake8-mutable
flake8-print
httpretty
pre-commit
pytest
pytest-flake8
requests-mock
4 changes: 4 additions & 0 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
myst-parser
numpydoc
pydata-sphinx-theme
sphinx
File renamed without changes.
27 changes: 12 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
cf-units>=2
cftime>=1.1.0
cf-units
importlib-metadata # drop this when dropping Python 3.8
importlib-resources # drop this when dropping Python 3.8
isodate>=0.6.1
jinja2>=2.7.3
lxml>=3.2.1
netcdf4>=1.6.4
owsLib>=0.8.3
isodate
lxml
netcdf4
owslib
packaging
pendulum>=1.2.4
pygeoif>=0.6
pyproj>=2.2.1
regex>=2017.07.28
requests>=2.2.1
setuptools>=15.0
shapely>=1.7.1
validators>=0.14.2
pendulum
pygeoif
pyproj
regex
requests
shapely
validators