From c75b1e1c3ac52786109480bca92c432372808c59 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Fri, 14 Oct 2022 13:20:31 +1300 Subject: [PATCH] Py source consistency using isort and pyupgrade tools, rm unused imports Also remove unused shebangs on non-executable module and test files --- docs/conf.py | 14 ++++++-------- docs/scripts/make_table.py | 12 +++++------- notebooks/conftest.py | 5 ++--- notebooks/test_notebooks.py | 4 ++-- pymt/__init__.py | 4 ++-- pymt/errors.py | 3 --- pymt/framework/bmi_bridge.py | 5 ++--- pymt/framework/bmi_docstring.py | 2 -- pymt/framework/bmi_mapper.py | 1 - pymt/framework/bmi_plot.py | 1 - pymt/framework/bmi_setup.py | 3 +-- pymt/framework/bmi_timeinterp.py | 1 - pymt/framework/bmi_ugrid.py | 3 +-- pymt/framework/services.py | 4 +--- pymt/framework/timeinterp.py | 1 - pymt/grids/assertions.py | 3 --- pymt/grids/connectivity.py | 2 -- pymt/grids/esmp.py | 1 - pymt/grids/field.py | 1 - pymt/grids/igrid.py | 2 +- pymt/grids/map.py | 1 - pymt/grids/raster.py | 1 - pymt/grids/rectilinear.py | 2 -- pymt/grids/structured.py | 2 -- pymt/grids/unstructured.py | 1 - pymt/mappers/celltopoint.py | 2 -- pymt/mappers/esmp.py | 2 -- pymt/mappers/imapper.py | 7 ++----- pymt/mappers/mapper.py | 1 - pymt/mappers/pointtocell.py | 2 -- pymt/mappers/pointtopoint.py | 2 -- pymt/model_collection.py | 3 ++- pymt/portprinter/port_printer.py | 1 - pymt/printers/nc/constants.py | 1 - pymt/printers/nc/database.py | 4 +--- pymt/printers/nc/read.py | 2 -- pymt/printers/nc/ugrid.py | 1 - pymt/printers/nc/ugrid_read.py | 9 ++++++--- pymt/printers/nc/write.py | 1 - pymt/services/constant/constant.py | 1 - pymt/services/gridreader/gridreader.py | 2 +- pymt/services/gridreader/time_series_names.py | 1 - pymt/timeline.py | 1 - pymt/utils/__init__.py | 1 - pymt/utils/prefix.py | 2 +- pymt/utils/utils.py | 1 - scripts/changelog.py | 15 +++++++-------- scripts/prm2input.py | 10 +++------- scripts/prm2template.py | 10 +++------- scripts/prmscan.py | 6 +----- scripts/vtu2ncu.py | 3 +-- tests/component/__init__.py | 2 +- tests/component/conftest.py | 2 +- tests/events/conftest.py | 4 ++-- tests/framework/test_bmi_var_units.py | 3 +-- tests/grids/test_assertions.py | 2 -- tests/grids/test_esmp.py | 2 -- tests/grids/test_field.py | 2 -- tests/grids/test_raster.py | 2 -- tests/grids/test_rectilinear.py | 2 -- tests/mappers/test_mapper.py | 8 ++++---- tests/mappers/test_pointtopoint.py | 1 - tests/portprinter/__init__.py | 4 ++-- tests/portprinter/conftest.py | 4 ++-- tests/portprinter/test_port_printer_queue.py | 1 - tests/portprinter/test_utils.py | 3 --- tests/printers/nc/test_database.py | 1 - tests/printers/nc/test_nc.py | 1 - tests/printers/nc/test_nc_examples.py | 1 - tests/test_models.py | 1 - tests/test_timeline.py | 1 - tests/test_units.py | 5 ++--- 72 files changed, 66 insertions(+), 156 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index ef353ad3..83b6fbfc 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # # pymt documentation build configuration file, created by # sphinx-quickstart on Fri Jun 9 13:47:02 2017. @@ -25,7 +24,6 @@ import pymt - if os.environ.get("READTHEDOCS", ""): # RTD doesn't use the repo's Makefile to build docs. import subprocess @@ -69,9 +67,9 @@ master_doc = "index" # General information about the project. -project = u"pymt" -copyright = u"2018, Eric Hutton" -author = u"Eric Hutton" +project = "pymt" +copyright = "2018, Eric Hutton" +author = "Eric Hutton" # The version info for the project you're documenting, acts as replacement # for |version| and |release|, also used in various other places throughout @@ -147,7 +145,7 @@ # (source start file, target name, title, author, documentclass # [howto, manual, or own class]). latex_documents = [ - (master_doc, "pymt.tex", u"pymt Documentation", u"Eric Hutton", "manual") + (master_doc, "pymt.tex", "pymt Documentation", "Eric Hutton", "manual") ] @@ -155,7 +153,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, "pymt", u"pymt Documentation", [author], 1)] +man_pages = [(master_doc, "pymt", "pymt Documentation", [author], 1)] # -- Options for Texinfo output ---------------------------------------- @@ -167,7 +165,7 @@ ( master_doc, "pymt", - u"pymt Documentation", + "pymt Documentation", author, "pymt", "One line description of project.", diff --git a/docs/scripts/make_table.py b/docs/scripts/make_table.py index e0c6a3e5..330851d9 100755 --- a/docs/scripts/make_table.py +++ b/docs/scripts/make_table.py @@ -1,10 +1,10 @@ #! /usr/bin/env python import os import textwrap -from tabulate import tabulate import click import yaml +from tabulate import tabulate def construct_rows(notebook_index=None): @@ -20,7 +20,7 @@ def construct_rows(notebook_index=None): [ summary, "", - "|binder-{0}|".format(name), + f"|binder-{name}|", ] ) rows.append((name, summary)) @@ -59,12 +59,10 @@ def make_table(dest, notebook_index): footer = [] for name, notebooks in index.items(): footer.append( + f""" + .. |binder-{name}| image:: https://mybinder.org/badge_logo.svg + :target: https://mybinder.org/v2/gh/csdms/pymt.git/master?filepath=notebooks%2F{notebooks[0]} """ - .. |binder-{0}| image:: https://mybinder.org/badge_logo.svg - :target: https://mybinder.org/v2/gh/csdms/pymt.git/master?filepath=notebooks%2F{1} - """.format( - name, notebooks[0] - ) ) print(textwrap.dedent(os.linesep.join(footer)), file=dest) diff --git a/notebooks/conftest.py b/notebooks/conftest.py index 6925b834..39938e27 100644 --- a/notebooks/conftest.py +++ b/notebooks/conftest.py @@ -2,16 +2,15 @@ import pytest - _TEST_DIR = pathlib.Path(__file__).absolute().parent def collect_notebooks(src): p = pathlib.Path(src) if p.is_dir(): - return set([_p.absolute() for _p in iter_notebooks_in_dir(p, src)]) + return {_p.absolute() for _p in iter_notebooks_in_dir(p, src)} else: - raise ValueError("{0}: not a directory".format(src)) + raise ValueError(f"{src}: not a directory") def iter_notebooks_in_dir(path, root): diff --git a/notebooks/test_notebooks.py b/notebooks/test_notebooks.py index 27f0d207..d9db8cde 100644 --- a/notebooks/test_notebooks.py +++ b/notebooks/test_notebooks.py @@ -6,8 +6,8 @@ _exclude_file = pathlib.Path(__file__).absolute().parent / "exclude.yml" if _exclude_file.exists(): - with open(_exclude_file, "r") as fp: - _EXCLUDE = dict([(item["file"], item["reason"]) for item in yaml.safe_load(fp)]) + with open(_exclude_file) as fp: + _EXCLUDE = {item["file"]: item["reason"] for item in yaml.safe_load(fp)} else: _EXCLUDE = {} diff --git a/pymt/__init__.py b/pymt/__init__.py index 725248c9..7f79f3f1 100644 --- a/pymt/__init__.py +++ b/pymt/__init__.py @@ -1,6 +1,6 @@ -from ._version import __version__ - from gimli import UnitSystem + +from ._version import __version__ from .model_collection import ModelCollection MODELS = ModelCollection() diff --git a/pymt/errors.py b/pymt/errors.py index e05a40bd..a156521e 100644 --- a/pymt/errors.py +++ b/pymt/errors.py @@ -1,6 +1,3 @@ -#! /usr/bin/env python - - class PymtError(Exception): pass diff --git a/pymt/framework/bmi_bridge.py b/pymt/framework/bmi_bridge.py index 980898df..e1e0ef37 100644 --- a/pymt/framework/bmi_bridge.py +++ b/pymt/framework/bmi_bridge.py @@ -4,15 +4,15 @@ import os from pprint import pformat +import gimli import numpy as np import yaml -import gimli from deprecated import deprecated -from ..utils import as_cwd from ..errors import BmiError from ..units import transform_azimuth_to_math, transform_math_to_azimuth +from ..utils import as_cwd from .bmi_docstring import bmi_docstring from .bmi_mapper import GridMapperMixIn from .bmi_plot import quick_plot @@ -20,7 +20,6 @@ from .bmi_timeinterp import BmiTimeInterpolator from .bmi_ugrid import dataset_from_bmi_grid - UNITS = gimli.units diff --git a/pymt/framework/bmi_docstring.py b/pymt/framework/bmi_docstring.py index 0b9a7b74..2b7ebab0 100644 --- a/pymt/framework/bmi_docstring.py +++ b/pymt/framework/bmi_docstring.py @@ -1,9 +1,7 @@ -#! /usr/bin/env python import jinja2 from landlab.core.messages import format_message from model_metadata import MetadataNotFoundError, ModelMetadata - # {{ desc|trim|wordwrap(70) if desc }} _DOCSTRING = """ Basic Model Interface for {{ name }}. diff --git a/pymt/framework/bmi_mapper.py b/pymt/framework/bmi_mapper.py index 4dd0290b..e63df6e0 100644 --- a/pymt/framework/bmi_mapper.py +++ b/pymt/framework/bmi_mapper.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import warnings import numpy as np diff --git a/pymt/framework/bmi_plot.py b/pymt/framework/bmi_plot.py index d61667bb..b068a95a 100644 --- a/pymt/framework/bmi_plot.py +++ b/pymt/framework/bmi_plot.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import matplotlib.pyplot as plt import numpy as np diff --git a/pymt/framework/bmi_setup.py b/pymt/framework/bmi_setup.py index 0d85ed61..51da44b2 100644 --- a/pymt/framework/bmi_setup.py +++ b/pymt/framework/bmi_setup.py @@ -1,13 +1,12 @@ -#! /usr/bin/env python import os import tempfile import urllib import zipfile import yaml +from model_metadata import ModelMetadata from model_metadata.model_data_files import FileTemplate from model_metadata.model_setup import FileSystemLoader -from model_metadata import ModelMetadata from ..utils import as_cwd diff --git a/pymt/framework/bmi_timeinterp.py b/pymt/framework/bmi_timeinterp.py index 031c1227..9d2855aa 100644 --- a/pymt/framework/bmi_timeinterp.py +++ b/pymt/framework/bmi_timeinterp.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python from ..errors import BmiError from ..utils import as_cwd from .timeinterp import TimeInterpolator diff --git a/pymt/framework/bmi_ugrid.py b/pymt/framework/bmi_ugrid.py index 55de7905..197f3acb 100644 --- a/pymt/framework/bmi_ugrid.py +++ b/pymt/framework/bmi_ugrid.py @@ -2,8 +2,7 @@ import numpy as np import xarray as xr - -from landlab.graph import StructuredQuadGraph, UniformRectilinearGraph, RectilinearGraph +from landlab.graph import RectilinearGraph, StructuredQuadGraph, UniformRectilinearGraph COORDINATE_NAMES = ["z", "y", "x"] INDEX_NAMES = ["k", "j", "i"] diff --git a/pymt/framework/services.py b/pymt/framework/services.py index feaf9d05..758bc8c7 100644 --- a/pymt/framework/services.py +++ b/pymt/framework/services.py @@ -90,9 +90,7 @@ def register_component_class(name, if_exists="raise"): try: _COMPONENT_CLASSES[cls_name] = getattr(mod, cls_name) except (KeyError, AttributeError): - raise ImportError( - "cannot import component {} from {}".format(cls_name, module_name) - ) + raise ImportError(f"cannot import component {cls_name} from {module_name}") def register_component_instance(name, instance): diff --git a/pymt/framework/timeinterp.py b/pymt/framework/timeinterp.py index e235f51f..e0096891 100644 --- a/pymt/framework/timeinterp.py +++ b/pymt/framework/timeinterp.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import bisect from scipy.interpolate import interp1d diff --git a/pymt/grids/assertions.py b/pymt/grids/assertions.py index 40032716..b6dcd2ad 100644 --- a/pymt/grids/assertions.py +++ b/pymt/grids/assertions.py @@ -1,6 +1,3 @@ -#! /usr/bin/env - - def is_callable_method(obj, method): return hasattr(obj, method) and callable(getattr(obj, method)) diff --git a/pymt/grids/connectivity.py b/pymt/grids/connectivity.py index 0080199d..881f2eac 100644 --- a/pymt/grids/connectivity.py +++ b/pymt/grids/connectivity.py @@ -1,5 +1,3 @@ -#! /bin/env python - """ >>> get_connectivity((6, )) array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5]) diff --git a/pymt/grids/esmp.py b/pymt/grids/esmp.py index 97c06065..0c412b15 100644 --- a/pymt/grids/esmp.py +++ b/pymt/grids/esmp.py @@ -1,4 +1,3 @@ -#! /bin/env python """PyMT interface to ESMPy grids. **Examples** diff --git a/pymt/grids/field.py b/pymt/grids/field.py index d99db628..02d22f60 100644 --- a/pymt/grids/field.py +++ b/pymt/grids/field.py @@ -1,4 +1,3 @@ -#! /bin/env python import numpy as np from .igrid import CENTERING_CHOICES, CenteringValueError, DimensionError, IField diff --git a/pymt/grids/igrid.py b/pymt/grids/igrid.py index 0f32a17d..4f084c4b 100644 --- a/pymt/grids/igrid.py +++ b/pymt/grids/igrid.py @@ -22,7 +22,7 @@ def __init__(self, dim0, dim1): self.dst_dim = dim1 def __str__(self): - return "{} != {}".format(self.src_dim, self.dst_dim) + return f"{self.src_dim} != {self.dst_dim}" class CenteringValueError(Error): diff --git a/pymt/grids/map.py b/pymt/grids/map.py index 3e0237c2..07f24784 100644 --- a/pymt/grids/map.py +++ b/pymt/grids/map.py @@ -1,4 +1,3 @@ -#! /bin/env python """ Examples ======== diff --git a/pymt/grids/raster.py b/pymt/grids/raster.py index 24bf9e3e..74ed2170 100644 --- a/pymt/grids/raster.py +++ b/pymt/grids/raster.py @@ -1,4 +1,3 @@ -#! /bin/env python """ Examples -------- diff --git a/pymt/grids/rectilinear.py b/pymt/grids/rectilinear.py index f5b4a295..379ca029 100644 --- a/pymt/grids/rectilinear.py +++ b/pymt/grids/rectilinear.py @@ -1,5 +1,3 @@ -#! /bin/env python - """ Examples -------- diff --git a/pymt/grids/structured.py b/pymt/grids/structured.py index f3341134..e29b2ef2 100644 --- a/pymt/grids/structured.py +++ b/pymt/grids/structured.py @@ -1,5 +1,3 @@ -#! /bin/env python - """ Examples -------- diff --git a/pymt/grids/unstructured.py b/pymt/grids/unstructured.py index 91473df6..1f3032ee 100644 --- a/pymt/grids/unstructured.py +++ b/pymt/grids/unstructured.py @@ -1,4 +1,3 @@ -#! /bin/env python import numpy as np from .igrid import IGrid diff --git a/pymt/mappers/celltopoint.py b/pymt/mappers/celltopoint.py index 2a4f6e12..cc3659c1 100644 --- a/pymt/mappers/celltopoint.py +++ b/pymt/mappers/celltopoint.py @@ -1,5 +1,3 @@ -#! /bin/env python - import numpy as np from scipy.spatial import KDTree diff --git a/pymt/mappers/esmp.py b/pymt/mappers/esmp.py index 2178f360..9281f893 100644 --- a/pymt/mappers/esmp.py +++ b/pymt/mappers/esmp.py @@ -1,5 +1,3 @@ -#! /bin/env python - import numpy as np from ..grids.esmp import EsmpUnstructuredField diff --git a/pymt/mappers/imapper.py b/pymt/mappers/imapper.py index fafa6962..229c0920 100644 --- a/pymt/mappers/imapper.py +++ b/pymt/mappers/imapper.py @@ -1,6 +1,3 @@ -#! /bin/env python - - class MapperError(Exception): """Base class for error in this package.""" @@ -17,7 +14,7 @@ def __init__(self, dst, src): self._dst = dst def __str__(self): - return "Unable to map {} to {}".format(self._src, self._dst) + return f"Unable to map {self._src} to {self._dst}" class NoMapperError(MapperError): @@ -26,7 +23,7 @@ def __init__(self, dst, src): self._dst = dst def __str__(self): - return "No mapper to map {} to {}".format(self._src, self._dst) + return f"No mapper to map {self._src} to {self._dst}" class IGridMapper: diff --git a/pymt/mappers/mapper.py b/pymt/mappers/mapper.py index 996cc94d..cf7c6244 100644 --- a/pymt/mappers/mapper.py +++ b/pymt/mappers/mapper.py @@ -1,4 +1,3 @@ -#! /bin/env python """ Examples ======== diff --git a/pymt/mappers/pointtocell.py b/pymt/mappers/pointtocell.py index f9cea664..73fe32dc 100644 --- a/pymt/mappers/pointtocell.py +++ b/pymt/mappers/pointtocell.py @@ -1,5 +1,3 @@ -#! /bin/env python - from collections import defaultdict import numpy as np diff --git a/pymt/mappers/pointtopoint.py b/pymt/mappers/pointtopoint.py index 5b836e03..d17bb07e 100644 --- a/pymt/mappers/pointtopoint.py +++ b/pymt/mappers/pointtopoint.py @@ -1,5 +1,3 @@ -#! /bin/env python - import numpy as np from scipy.spatial import KDTree diff --git a/pymt/model_collection.py b/pymt/model_collection.py index 6f954230..127b664d 100644 --- a/pymt/model_collection.py +++ b/pymt/model_collection.py @@ -1,6 +1,7 @@ -import pkg_resources import traceback +import pkg_resources + from .framework.bmi_bridge import bmi_factory diff --git a/pymt/portprinter/port_printer.py b/pymt/portprinter/port_printer.py index 77a74152..72927b8f 100644 --- a/pymt/portprinter/port_printer.py +++ b/pymt/portprinter/port_printer.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python from configparser import ConfigParser from io import StringIO diff --git a/pymt/printers/nc/constants.py b/pymt/printers/nc/constants.py index 8856ac01..1f8453c2 100644 --- a/pymt/printers/nc/constants.py +++ b/pymt/printers/nc/constants.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os import warnings diff --git a/pymt/printers/nc/database.py b/pymt/printers/nc/database.py index e889111b..fc2b5006 100644 --- a/pymt/printers/nc/database.py +++ b/pymt/printers/nc/database.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python - import os from .ugrid import close as ugrid_close @@ -32,7 +30,7 @@ def open(self, path, var_name, **kwds): self._var_name = var_name self._path = path - self._template = "{}_%04d{}".format(root, ext) + self._template = f"{root}_%04d{ext}" self._point_count = None self._cell_count = None diff --git a/pymt/printers/nc/read.py b/pymt/printers/nc/read.py index 7a389c20..3579387f 100644 --- a/pymt/printers/nc/read.py +++ b/pymt/printers/nc/read.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python - from pymt.grids.grid_type import ( GridTypeRectilinear, GridTypeStructured, diff --git a/pymt/printers/nc/ugrid.py b/pymt/printers/nc/ugrid.py index 5e30948c..231367e8 100644 --- a/pymt/printers/nc/ugrid.py +++ b/pymt/printers/nc/ugrid.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os from ...grids import utils as gutils diff --git a/pymt/printers/nc/ugrid_read.py b/pymt/printers/nc/ugrid_read.py index dd0347bd..6a8c4f9c 100644 --- a/pymt/printers/nc/ugrid_read.py +++ b/pymt/printers/nc/ugrid_read.py @@ -1,6 +1,9 @@ -#! /usr/bin/env python -from ...grids import RectilinearField, StructuredField, UnstructuredField -from ...grids import utils as gutils +from ...grids import ( + RectilinearField, + StructuredField, + UnstructuredField, + utils as gutils, +) from .constants import open_netcdf diff --git a/pymt/printers/nc/write.py b/pymt/printers/nc/write.py index 2e5e2268..eaf16e11 100644 --- a/pymt/printers/nc/write.py +++ b/pymt/printers/nc/write.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python from warnings import warn from ...grids.assertions import is_rectilinear, is_structured diff --git a/pymt/services/constant/constant.py b/pymt/services/constant/constant.py index 49ccbdfd..e020ab27 100644 --- a/pymt/services/constant/constant.py +++ b/pymt/services/constant/constant.py @@ -1,4 +1,3 @@ -#! /bin/env python import numpy as np import yaml diff --git a/pymt/services/gridreader/gridreader.py b/pymt/services/gridreader/gridreader.py index 26827236..da80c92d 100644 --- a/pymt/services/gridreader/gridreader.py +++ b/pymt/services/gridreader/gridreader.py @@ -1,4 +1,3 @@ -#! /bin/env python import warnings import yaml @@ -95,6 +94,7 @@ def get_value(self, name): def get_abspath_or_url(filename, prefix=""): import os + from urlparse import urlparse, urlunparse parts = urlparse(filename) diff --git a/pymt/services/gridreader/time_series_names.py b/pymt/services/gridreader/time_series_names.py index aea1476b..59af5f58 100644 --- a/pymt/services/gridreader/time_series_names.py +++ b/pymt/services/gridreader/time_series_names.py @@ -1,7 +1,6 @@ import collections import re - _TIME_SERIES_NAME_RE_PATTERN = r"(?P[a-zA-Z_]+)@t=(?P\d+)$" _TIME_SERIES_NAME_RE = re.compile(_TIME_SERIES_NAME_RE_PATTERN) diff --git a/pymt/timeline.py b/pymt/timeline.py index 820b8e2a..a83b97f0 100644 --- a/pymt/timeline.py +++ b/pymt/timeline.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python """Execute events along a timeline. Examples diff --git a/pymt/utils/__init__.py b/pymt/utils/__init__.py index 73162334..29cce354 100644 --- a/pymt/utils/__init__.py +++ b/pymt/utils/__init__.py @@ -1,4 +1,3 @@ from .utils import as_cwd, err, out - __all__ = ["as_cwd", "err", "out"] diff --git a/pymt/utils/prefix.py b/pymt/utils/prefix.py index 3591f520..cef62143 100644 --- a/pymt/utils/prefix.py +++ b/pymt/utils/prefix.py @@ -54,4 +54,4 @@ def strip_prefix(name, prefix): if name.startswith(prefix): return name[len(prefix) :] else: - raise ValueError("{} does not start with {}".format(name, prefix)) + raise ValueError(f"{name} does not start with {prefix}") diff --git a/pymt/utils/utils.py b/pymt/utils/utils.py index e26c519a..1df56143 100644 --- a/pymt/utils/utils.py +++ b/pymt/utils/utils.py @@ -4,7 +4,6 @@ import click - out = partial(click.secho, bold=True, err=True) err = partial(click.secho, fg="red", err=True) diff --git a/scripts/changelog.py b/scripts/changelog.py index 6214aa8b..aad6753f 100755 --- a/scripts/changelog.py +++ b/scripts/changelog.py @@ -1,16 +1,15 @@ #! /usr/bin/env python -from __future__ import print_function import os import re import subprocess import sys from collections import OrderedDict, defaultdict -from pkg_resources import parse_version import click import jinja2 import m2r +from pkg_resources import parse_version __version__ = "0.1.1" @@ -53,7 +52,7 @@ def git_log(start=None, stop="HEAD"): # '--oneline', ] if start: - cmd.append("{start}..{stop}".format(start=start, stop=stop)) + cmd.append(f"{start}..{stop}") return subprocess.check_output(cmd).strip().decode("utf-8") @@ -89,8 +88,8 @@ def releases(ascending=True): def format_pr_message(message): m = re.match( "Merge pull request (?P#[0-9]+) " - "from (?P[\S]*)" - "(?P[\s\S]*$)", + r"from (?P[\S]*)" + r"(?P[\s\S]*$)", message, ) if m: @@ -100,7 +99,7 @@ def format_pr_message(message): def format_changelog_message(message): - m = re.match("(?P\w+)(?P[\s\S]*)$", message) + m = re.match(r"(?P\w+)(?P[\s\S]*)$", message) word = m.groupdict()["first"] if word in ("Add", "Fix", "Deprecate"): return word + "ed" + m.groupdict()["rest"] @@ -224,7 +223,7 @@ def main(output, quiet, verbose, format, force, batch): path_to_changelog = os.path.join(git_top_level(), "CHANGELOG." + format) if os.path.isfile(path_to_changelog) and not force: click.secho( - "{0} exists. Use --force to overwrite".format(path_to_changelog), + f"{path_to_changelog} exists. Use --force to overwrite", fg="red", err=True, ) @@ -233,7 +232,7 @@ def main(output, quiet, verbose, format, force, batch): with open(path_to_changelog, "w") as fp: fp.write(contents) click.secho( - "Fresh change log at {0}".format(path_to_changelog), bold=True, err=True + f"Fresh change log at {path_to_changelog}", bold=True, err=True ) diff --git a/scripts/prm2input.py b/scripts/prm2input.py index c613e7b0..ab5f310d 100755 --- a/scripts/prm2input.py +++ b/scripts/prm2input.py @@ -1,10 +1,6 @@ #! /usr/bin/env python -from __future__ import print_function - -import sys - -from cmt.scanners import InputParameterScanner, CmtScanner, MissingKeyError +from cmt.scanners import InputParameterScanner def main(): @@ -16,13 +12,13 @@ def main(): args = parser.parse_args() if len(args.file) == 1: - with open(args.file[0], "r") as f: + with open(args.file[0]) as f: scanner = InputParameterScanner(f) scanner.scan_file() print(scanner.fill_contents()) else: for file in args.file: - with open(file, "r") as f: + with open(file) as f: scanner = InputParameterScanner(f) scanner.scan_file() diff --git a/scripts/prm2template.py b/scripts/prm2template.py index aa9de079..e4a1517b 100755 --- a/scripts/prm2template.py +++ b/scripts/prm2template.py @@ -1,10 +1,6 @@ #! /usr/bin/env python -from __future__ import print_function - -import sys - -from cmt.scanners import InputParameterScanner, CmtScanner, MissingKeyError +from cmt.scanners import InputParameterScanner def main(): @@ -16,13 +12,13 @@ def main(): args = parser.parse_args() if len(args.file) == 1: - with open(args.file[0], "r") as f: + with open(args.file[0]) as f: scanner = InputParameterScanner(f) scanner.scan_file() print(scanner.contents()) else: for file in args.file: - with open(file, "r") as f: + with open(file) as f: scanner = InputParameterScanner(f) scanner.scan_file() diff --git a/scripts/prmscan.py b/scripts/prmscan.py index 7fe8d899..28025278 100755 --- a/scripts/prmscan.py +++ b/scripts/prmscan.py @@ -1,10 +1,6 @@ #! /usr/bin/env python -from __future__ import print_function - -import sys - -from cmt.scanners import InputParameterScanner, CmtScanner, MissingKeyError +from cmt.scanners import CmtScanner, InputParameterScanner def main(): diff --git a/scripts/vtu2ncu.py b/scripts/vtu2ncu.py index 6d346312..7e259211 100755 --- a/scripts/vtu2ncu.py +++ b/scripts/vtu2ncu.py @@ -1,10 +1,9 @@ #! /usr/bin/env python -import os import argparse -import cmt.vtk import cmt.nc +import cmt.vtk parser = argparse.ArgumentParser(description="Convert VTK file to NCU files") parser.add_argument("files", metavar="vtk_file", nargs="+", help="VTK formatted file") diff --git a/tests/component/__init__.py b/tests/component/__init__.py index 00325c4b..b671a5a7 100644 --- a/tests/component/__init__.py +++ b/tests/component/__init__.py @@ -1,5 +1,5 @@ def setup(): - from pymt.framework.services import register_component_classes, del_services + from pymt.framework.services import del_services, register_component_classes del_services() diff --git a/tests/component/conftest.py b/tests/component/conftest.py index a13e04b3..8066e61b 100644 --- a/tests/component/conftest.py +++ b/tests/component/conftest.py @@ -3,7 +3,7 @@ @pytest.fixture(scope="session") def with_no_components(): - from pymt.framework.services import register_component_classes, del_services + from pymt.framework.services import del_services, register_component_classes del_services() diff --git a/tests/events/conftest.py b/tests/events/conftest.py index 5bab04db..fe7be62e 100644 --- a/tests/events/conftest.py +++ b/tests/events/conftest.py @@ -4,9 +4,9 @@ @pytest.fixture(scope="session") def with_earth_and_air(): from pymt.framework.services import ( - register_component_classes, - instantiate_component, del_services, + instantiate_component, + register_component_classes, ) del_services() diff --git a/tests/framework/test_bmi_var_units.py b/tests/framework/test_bmi_var_units.py index d8ee596f..d3d5a98d 100644 --- a/tests/framework/test_bmi_var_units.py +++ b/tests/framework/test_bmi_var_units.py @@ -1,6 +1,5 @@ -import pytest - import numpy as np +import pytest from gimli import IncompatibleUnitsError, UnitNameError from numpy.testing import assert_array_equal diff --git a/tests/grids/test_assertions.py b/tests/grids/test_assertions.py index 5963810e..1c316613 100644 --- a/tests/grids/test_assertions.py +++ b/tests/grids/test_assertions.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python - import unittest from pymt.grids import ( diff --git a/tests/grids/test_esmp.py b/tests/grids/test_esmp.py index 464aa98a..99097ea6 100644 --- a/tests/grids/test_esmp.py +++ b/tests/grids/test_esmp.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python import unittest - import numpy as np import pytest from pytest import approx diff --git a/tests/grids/test_field.py b/tests/grids/test_field.py index 4e84578c..2790884f 100644 --- a/tests/grids/test_field.py +++ b/tests/grids/test_field.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python - import unittest import numpy as np diff --git a/tests/grids/test_raster.py b/tests/grids/test_raster.py index 8fe2945e..504760bf 100644 --- a/tests/grids/test_raster.py +++ b/tests/grids/test_raster.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python - import unittest import numpy as np diff --git a/tests/grids/test_rectilinear.py b/tests/grids/test_rectilinear.py index 509ab630..552fcac2 100644 --- a/tests/grids/test_rectilinear.py +++ b/tests/grids/test_rectilinear.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python - import unittest import numpy as np diff --git a/tests/mappers/test_mapper.py b/tests/mappers/test_mapper.py index c0293474..7edf7304 100644 --- a/tests/mappers/test_mapper.py +++ b/tests/mappers/test_mapper.py @@ -1,10 +1,10 @@ -#! /usr/bin/env python - import numpy as np from numpy.testing import assert_array_equal -from pymt.grids.map import UniformRectilinearMap as UniformRectilinear -from pymt.grids.map import UnstructuredPointsMap as UnstructuredPoints +from pymt.grids.map import ( + UniformRectilinearMap as UniformRectilinear, + UnstructuredPointsMap as UnstructuredPoints, +) from pymt.mappers import CellToPoint, PointToCell diff --git a/tests/mappers/test_pointtopoint.py b/tests/mappers/test_pointtopoint.py index e649fff6..f6b3d2aa 100644 --- a/tests/mappers/test_pointtopoint.py +++ b/tests/mappers/test_pointtopoint.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import numpy as np import pytest from numpy.testing import assert_array_almost_equal diff --git a/tests/portprinter/__init__.py b/tests/portprinter/__init__.py index f56b015c..17632795 100644 --- a/tests/portprinter/__init__.py +++ b/tests/portprinter/__init__.py @@ -1,8 +1,8 @@ def setup(): from pymt.framework.services import ( - register_component_classes, - instantiate_component, del_services, + instantiate_component, + register_component_classes, ) del_services() diff --git a/tests/portprinter/conftest.py b/tests/portprinter/conftest.py index 98c470a4..bd61babf 100644 --- a/tests/portprinter/conftest.py +++ b/tests/portprinter/conftest.py @@ -4,9 +4,9 @@ @pytest.fixture(scope="function") def with_two_components(): from pymt.framework.services import ( - register_component_classes, - instantiate_component, del_services, + instantiate_component, + register_component_classes, ) del_services() diff --git a/tests/portprinter/test_port_printer_queue.py b/tests/portprinter/test_port_printer_queue.py index b77160e5..d53339d2 100644 --- a/tests/portprinter/test_port_printer_queue.py +++ b/tests/portprinter/test_port_printer_queue.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os import xarray diff --git a/tests/portprinter/test_utils.py b/tests/portprinter/test_utils.py index f53c69d6..39b118f1 100644 --- a/tests/portprinter/test_utils.py +++ b/tests/portprinter/test_utils.py @@ -1,6 +1,3 @@ -#! /usr/bin/env python - - import unittest import numpy as np diff --git a/tests/printers/nc/test_database.py b/tests/printers/nc/test_database.py index aeee7760..5575f7ea 100644 --- a/tests/printers/nc/test_database.py +++ b/tests/printers/nc/test_database.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os import numpy as np diff --git a/tests/printers/nc/test_nc.py b/tests/printers/nc/test_nc.py index aa109c02..e514757d 100644 --- a/tests/printers/nc/test_nc.py +++ b/tests/printers/nc/test_nc.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os import numpy as np diff --git a/tests/printers/nc/test_nc_examples.py b/tests/printers/nc/test_nc_examples.py index 0832de94..8ee31896 100644 --- a/tests/printers/nc/test_nc_examples.py +++ b/tests/printers/nc/test_nc_examples.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os import numpy as np diff --git a/tests/test_models.py b/tests/test_models.py index 471dedea..e5d15a7e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import os import pytest diff --git a/tests/test_timeline.py b/tests/test_timeline.py index 2cc84195..4b29ec69 100644 --- a/tests/test_timeline.py +++ b/tests/test_timeline.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import pytest from pytest import approx diff --git a/tests/test_units.py b/tests/test_units.py index 079789d0..61066a10 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -3,11 +3,10 @@ import numpy as np import pytest -from gimli import IncompatibleUnitsError, UnitNameError, UnitStatus, UnitFormatting -from pymt.units import transform_azimuth_to_math, transform_math_to_azimuth - +from gimli import IncompatibleUnitsError, UnitFormatting, UnitNameError, UnitStatus from pymt import UnitSystem +from pymt.units import transform_azimuth_to_math, transform_math_to_azimuth @pytest.fixture