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

Py source consistency using isort and pyupgrade tools, rm unused imports #163

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,7 +24,6 @@

import pymt


if os.environ.get("READTHEDOCS", ""):
# RTD doesn't use the repo's Makefile to build docs.
import subprocess
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -147,15 +145,15 @@
# (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")
]


# -- Options for manual page output ------------------------------------

# 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 ----------------------------------------
Expand All @@ -167,7 +165,7 @@
(
master_doc,
"pymt",
u"pymt Documentation",
"pymt Documentation",
author,
"pymt",
"One line description of project.",
Expand Down
12 changes: 5 additions & 7 deletions docs/scripts/make_table.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -20,7 +20,7 @@ def construct_rows(notebook_index=None):
[
summary,
"",
"|binder-{0}|".format(name),
f"|binder-{name}|",
]
)
rows.append((name, summary))
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions notebooks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions notebooks/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
4 changes: 2 additions & 2 deletions pymt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ._version import __version__

from gimli import UnitSystem

from ._version import __version__
from .model_collection import ModelCollection

MODELS = ModelCollection()
Expand Down
3 changes: 0 additions & 3 deletions pymt/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#! /usr/bin/env python


class PymtError(Exception):

pass
Expand Down
5 changes: 2 additions & 3 deletions pymt/framework/bmi_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
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
from .bmi_setup import SetupMixIn
from .bmi_timeinterp import BmiTimeInterpolator
from .bmi_ugrid import dataset_from_bmi_grid


UNITS = gimli.units


Expand Down
2 changes: 0 additions & 2 deletions pymt/framework/bmi_docstring.py
Original file line number Diff line number Diff line change
@@ -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 }}.
Expand Down
1 change: 0 additions & 1 deletion pymt/framework/bmi_mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
import warnings

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion pymt/framework/bmi_plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np

Expand Down
3 changes: 1 addition & 2 deletions pymt/framework/bmi_setup.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion pymt/framework/bmi_timeinterp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
from ..errors import BmiError
from ..utils import as_cwd
from .timeinterp import TimeInterpolator
Expand Down
3 changes: 1 addition & 2 deletions pymt/framework/bmi_ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 1 addition & 3 deletions pymt/framework/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pymt/framework/timeinterp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
import bisect

from scipy.interpolate import interp1d
Expand Down
3 changes: 0 additions & 3 deletions pymt/grids/assertions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#! /usr/bin/env


def is_callable_method(obj, method):
return hasattr(obj, method) and callable(getattr(obj, method))

Expand Down
2 changes: 0 additions & 2 deletions pymt/grids/connectivity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

"""
>>> get_connectivity((6, ))
array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5])
Expand Down
1 change: 0 additions & 1 deletion pymt/grids/esmp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/env python
"""PyMT interface to ESMPy grids.

**Examples**
Expand Down
1 change: 0 additions & 1 deletion pymt/grids/field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/env python
import numpy as np

from .igrid import CENTERING_CHOICES, CenteringValueError, DimensionError, IField
Expand Down
2 changes: 1 addition & 1 deletion pymt/grids/igrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pymt/grids/map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/env python
"""
Examples
========
Expand Down
1 change: 0 additions & 1 deletion pymt/grids/raster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/env python
"""
Examples
--------
Expand Down
2 changes: 0 additions & 2 deletions pymt/grids/rectilinear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

"""
Examples
--------
Expand Down
2 changes: 0 additions & 2 deletions pymt/grids/structured.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

"""
Examples
--------
Expand Down
1 change: 0 additions & 1 deletion pymt/grids/unstructured.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/env python
import numpy as np

from .igrid import IGrid
Expand Down
2 changes: 0 additions & 2 deletions pymt/mappers/celltopoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

import numpy as np
from scipy.spatial import KDTree

Expand Down
2 changes: 0 additions & 2 deletions pymt/mappers/esmp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

import numpy as np

from ..grids.esmp import EsmpUnstructuredField
Expand Down
7 changes: 2 additions & 5 deletions pymt/mappers/imapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#! /bin/env python


class MapperError(Exception):
"""Base class for error in this package."""

Expand All @@ -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):
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion pymt/mappers/mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/env python
"""
Examples
========
Expand Down
2 changes: 0 additions & 2 deletions pymt/mappers/pointtocell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

from collections import defaultdict

import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions pymt/mappers/pointtopoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /bin/env python

import numpy as np
from scipy.spatial import KDTree

Expand Down
3 changes: 2 additions & 1 deletion pymt/model_collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pkg_resources
import traceback

import pkg_resources

from .framework.bmi_bridge import bmi_factory


Expand Down
1 change: 0 additions & 1 deletion pymt/portprinter/port_printer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
from configparser import ConfigParser
from io import StringIO

Expand Down
1 change: 0 additions & 1 deletion pymt/printers/nc/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
import os
import warnings

Expand Down
4 changes: 1 addition & 3 deletions pymt/printers/nc/database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

import os

from .ugrid import close as ugrid_close
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pymt/printers/nc/read.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env python

from pymt.grids.grid_type import (
GridTypeRectilinear,
GridTypeStructured,
Expand Down
1 change: 0 additions & 1 deletion pymt/printers/nc/ugrid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env python
import os

from ...grids import utils as gutils
Expand Down
9 changes: 6 additions & 3 deletions pymt/printers/nc/ugrid_read.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down