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

Set up isort #1947

Merged
merged 4 commits into from
Jul 7, 2021
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
3 changes: 2 additions & 1 deletion ci/linting_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ flake8-builtins==1.5.3
flake8-comprehensions==3.5.0
flake8-continuation==1.0.5
flake8-copyright==0.2.2
flake8-import-order==0.18.1
flake8-isort==4.0.0
isort==5.9.1
flake8-mutable==1.2.0
flake8-pep3101==1.3.0
flake8-print==4.0.0
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import metpy


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use resolve() to make it absolute, like shown here.
Expand Down
1 change: 0 additions & 1 deletion docs/override_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path
import sys


modules_to_skip = ['metpy.xarray']


Expand Down
1 change: 0 additions & 1 deletion examples/plots/Simple_Sounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from metpy.plots import add_metpy_logo, SkewT
from metpy.units import units


###########################################

# Change default to be better for skew-T
Expand Down
4 changes: 2 additions & 2 deletions examples/plots/Station_Plot_with_Layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

from metpy.calc import wind_components
from metpy.cbook import get_test_data
from metpy.plots import (add_metpy_logo, simple_layout, StationPlot,
StationPlotLayout, wx_code_map)
from metpy.plots import (add_metpy_logo, simple_layout, StationPlot, StationPlotLayout,
wx_code_map)
from metpy.units import units

###########################################
Expand Down
1 change: 0 additions & 1 deletion examples/plots/upperair_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import metpy.plots as mpplots
from metpy.units import units


########################################
# **Getting the data**
#
Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_scheme = "post-release"

[tool.isort]
line_length = 95
known_first_party = ["metpy", "flake8_metpy"]
force_single_line = false
reverse_relative = true
use_parentheses = true
force_sort_within_sections = true
order_by_type = false
sort_relative_in_force_sorted_sections = true
combine_as_imports = true
combine_star = true
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ max-line-length = 95

[flake8]
max-line-length = 95
application-import-names = metpy flake8_metpy
import-order-style = google
copyright-check = True
copyright-author = MetPy Developers
inline-quotes = single
Expand Down
1 change: 1 addition & 0 deletions src/metpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@

from ._version import get_version # noqa: E402
from .xarray import * # noqa: F401, F403, E402

__version__ = get_version()
del get_version
4 changes: 2 additions & 2 deletions src/metpy/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def get_version():
version_scheme='post-release')
except (ImportError, LookupError):
try:
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version
except ImportError: # Can remove when we require Python > 3.7
from importlib_metadata import version, PackageNotFoundError
from importlib_metadata import PackageNotFoundError, version

try:
return version(__package__)
Expand Down
1 change: 1 addition & 0 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def _get_bound_pressure_height(pressure, bound, height=None, interpolate=True):
"""
# avoid circular import if basic.py ever imports something from tools.py
from .basic import height_to_pressure_std, pressure_to_height_std

# Make sure pressure is monotonically decreasing
sort_inds = np.argsort(pressure)[::-1]
pressure = pressure[sort_inds]
Expand Down
1 change: 1 addition & 0 deletions src/metpy/interpolate/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def interpolate_to_isosurface(level_var, interp_var, level, bottom_up_search=Tru

"""
from ..calc import find_bounding_indices

# Find index values above and below desired interpolated surface value
above, below, good = find_bounding_indices(level_var, [level], axis=0,
from_below=bottom_up_search)
Expand Down
17 changes: 3 additions & 14 deletions src/metpy/plots/_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
# SPDX-License-Identifier: BSD-3-Clause
"""Functionality that we have upstreamed or will upstream into matplotlib."""

# See if we should monkey-patch Barbs for better pivot
from matplotlib.axes import Axes # noqa: E402, I100, I202
import matplotlib.transforms as transforms
import numpy as np

# See if we need to patch in our own scattertext implementation
from matplotlib.axes import Axes # noqa: E402, I100, I202
if not hasattr(Axes, 'scattertext'):
import matplotlib.cbook as cbook
import matplotlib.transforms as mtransforms
from matplotlib import rcParams
from matplotlib.artist import allow_rasterization
import matplotlib.cbook as cbook
from matplotlib.text import Text
import matplotlib.transforms as mtransforms

def scattertext(self, x, y, texts, loc=(0, 0), **kw):
"""Add text to the axes.
Expand Down Expand Up @@ -67,16 +66,6 @@ def scattertext(self, x, y, texts, loc=(0, 0), **kw):
'clip_on': False}
new_kw.update(kw)

# Default to centered on point--special case it to keep transform
# simpler.
# t = new_kw['transform']
# if loc == (0, 0):
# trans = t
# else:
# x0, y0 = loc
# trans = t + mtransforms.Affine2D().translate(x0, y0)
# new_kw['transform'] = trans

# Handle masked arrays
x, y, texts = cbook.delete_masked_points(x, y, texts)

Expand Down
1 change: 1 addition & 0 deletions src/metpy/plots/cartopy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, name, scale, **kwargs):
def geometries(self):
"""Return an iterator of (shapely) geometries for this feature."""
import cartopy.io.shapereader as shapereader

# Ensure that the associated files are in the cache
fname = f'{self.name}_{self.scaler.scale}'
for extension in ['.dbf', '.shx']:
Expand Down
4 changes: 2 additions & 2 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from traitlets import (Any, Bool, Float, HasTraits, Instance, Int, List, observe, TraitError,
Tuple, Unicode, Union, validate)

from . import ctables
from . import wx_symbols
from . import ctables, wx_symbols
from .cartopy_utils import import_cartopy
from .station_plot import StationPlot
from ..calc import reduce_point_density
Expand Down Expand Up @@ -483,6 +482,7 @@ def lookup_projection(projection_code):
def lookup_map_feature(feature_name):
"""Get a Cartopy map feature based on a name."""
import cartopy.feature as cfeature

from . import cartopy_utils

name = feature_name.upper()
Expand Down
4 changes: 2 additions & 2 deletions src/metpy/plots/wx_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""

try:
from importlib.resources import (files as importlib_resources_files,
as_file as importlib_resources_as_file)
from importlib.resources import (as_file as importlib_resources_as_file,
files as importlib_resources_files)
except ImportError: # Can remove when we require Python > 3.8
from importlib_resources import (files as importlib_resources_files,
as_file as importlib_resources_as_file)
Expand Down
6 changes: 3 additions & 3 deletions src/metpy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import pytest
import xarray as xr

from metpy.calc import wind_components
from metpy.cbook import get_test_data
from metpy.deprecation import MetpyDeprecationWarning
from .calc import wind_components
from .cbook import get_test_data
from .deprecation import MetpyDeprecationWarning
from .units import units


Expand Down
5 changes: 1 addition & 4 deletions src/metpy/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ._vendor.xarray import either_dict_or_kwargs, expanded_indexer, is_dict_like
from .units import DimensionalityError, UndefinedUnitError, units

__all__ = []
__all__ = ('MetPyDataArrayAccessor', 'MetPyDatasetAccessor', 'grid_deltas_from_dataarray')
metpy_axes = ['time', 'vertical', 'y', 'latitude', 'x', 'longitude']

# Define the criteria for coordinate matches
Expand Down Expand Up @@ -1541,6 +1541,3 @@ def wrapper(*args, **kwargs):

return func(*bound_args.args, **bound_args.kwargs)
return wrapper


__all__ = ('MetPyDataArrayAccessor', 'MetPyDatasetAccessor', 'grid_deltas_from_dataarray')
2 changes: 1 addition & 1 deletion tests/calc/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pressure_to_height_std, sigma_to_pressure, smooth_circular,
smooth_gaussian, smooth_n_point, smooth_rectangular, smooth_window,
wind_components, wind_direction, wind_speed, windchill)
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal)
from metpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
from metpy.units import units


Expand Down
7 changes: 3 additions & 4 deletions tests/calc/test_calc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
import xarray as xr

from metpy.calc import (angle_to_direction, find_bounding_indices, find_intersections,
first_derivative, get_layer, get_layer_heights, gradient,
laplacian, lat_lon_grid_deltas, nearest_intersection_idx, parse_angle,
first_derivative, get_layer, get_layer_heights, gradient, laplacian,
lat_lon_grid_deltas, nearest_intersection_idx, parse_angle,
pressure_to_height_std, reduce_point_density, resample_nn_1d,
second_derivative)
from metpy.calc.tools import (_delete_masked_points, _get_bound_pressure_height,
_greater_or_close, _less_or_close, _next_non_masked_element,
_remove_nans, azimuth_range_to_lat_lon, BASE_DEGREE_MULTIPLIER,
DIR_STRS, UND)
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal)
from metpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
from metpy.units import units
from metpy.xarray import grid_deltas_from_dataarray


FULL_CIRCLE_DEGREES = np.arange(0, 360, BASE_DEGREE_MULTIPLIER.m) * units.degree


Expand Down
3 changes: 1 addition & 2 deletions tests/calc/test_cross_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from metpy.calc import (absolute_momentum, cross_section_components, normal_component,
tangential_component, unit_vectors_from_cross_section)
from metpy.calc.cross_sections import (distances_from_cross_section,
latitude_from_cross_section)
from metpy.calc.cross_sections import distances_from_cross_section, latitude_from_cross_section
from metpy.cbook import get_test_data
from metpy.interpolate import cross_section
from metpy.testing import assert_array_almost_equal, assert_xarray_allclose, needs_cartopy
Expand Down
4 changes: 2 additions & 2 deletions tests/calc/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import xarray as xr

from metpy.calc import (bulk_shear, bunkers_storm_motion, critical_angle,
mean_pressure_weighted, precipitable_water,
significant_tornado, supercell_composite)
mean_pressure_weighted, precipitable_water, significant_tornado,
supercell_composite)
from metpy.testing import assert_almost_equal, assert_array_almost_equal, get_upper_air_data
from metpy.units import concatenate, units

Expand Down
14 changes: 7 additions & 7 deletions tests/calc/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import pytest
import xarray as xr

from metpy.calc import (absolute_vorticity, advection, ageostrophic_wind,
divergence, frontogenesis, geostrophic_wind, inertial_advective_wind,
lat_lon_grid_deltas, montgomery_streamfunction,
potential_temperature, potential_vorticity_baroclinic,
potential_vorticity_barotropic, q_vector, shearing_deformation,
static_stability, storm_relative_helicity, stretching_deformation,
total_deformation, vorticity, wind_components)
from metpy.calc import (absolute_vorticity, advection, ageostrophic_wind, divergence,
frontogenesis, geostrophic_wind, inertial_advective_wind,
lat_lon_grid_deltas, montgomery_streamfunction, potential_temperature,
potential_vorticity_baroclinic, potential_vorticity_barotropic,
q_vector, shearing_deformation, static_stability,
storm_relative_helicity, stretching_deformation, total_deformation,
vorticity, wind_components)
from metpy.constants import g, Re
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal,
get_test_data)
Expand Down
22 changes: 9 additions & 13 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
isentropic_interpolation_as_dataset, lcl, lfc, lifted_index,
mixed_layer, mixed_layer_cape_cin, mixed_parcel, mixing_ratio,
mixing_ratio_from_relative_humidity,
mixing_ratio_from_specific_humidity, moist_lapse,
moist_static_energy, most_unstable_cape_cin, most_unstable_parcel,
parcel_profile, parcel_profile_with_lcl,
parcel_profile_with_lcl_as_dataset, potential_temperature,
psychrometric_vapor_pressure_wet,
relative_humidity_from_dewpoint,
relative_humidity_from_mixing_ratio,
mixing_ratio_from_specific_humidity, moist_lapse, moist_static_energy,
most_unstable_cape_cin, most_unstable_parcel, parcel_profile,
parcel_profile_with_lcl, parcel_profile_with_lcl_as_dataset,
potential_temperature, psychrometric_vapor_pressure_wet,
relative_humidity_from_dewpoint, relative_humidity_from_mixing_ratio,
relative_humidity_from_specific_humidity,
relative_humidity_wet_psychrometric,
saturation_equivalent_potential_temperature,
saturation_mixing_ratio,
saturation_equivalent_potential_temperature, saturation_mixing_ratio,
saturation_vapor_pressure, showalter_index,
specific_humidity_from_dewpoint,
specific_humidity_from_mixing_ratio, static_stability,
surface_based_cape_cin, temperature_from_potential_temperature,
thickness_hydrostatic,
specific_humidity_from_dewpoint, specific_humidity_from_mixing_ratio,
static_stability, surface_based_cape_cin,
temperature_from_potential_temperature, thickness_hydrostatic,
thickness_hydrostatic_from_relative_humidity, vapor_pressure,
vertical_velocity, vertical_velocity_pressure,
virtual_potential_temperature, virtual_temperature,
Expand Down
3 changes: 1 addition & 2 deletions tests/interpolate/test_interpolate_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import pytest

from metpy.interpolate import (interpolate_to_grid, remove_nan_observations,
remove_observations_below_value,
remove_repeat_coordinates)
remove_observations_below_value, remove_repeat_coordinates)
from metpy.interpolate.tools import barnes_weights, calc_kappa, cressman_weights


Expand Down
3 changes: 1 addition & 2 deletions tests/interpolate/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from metpy.interpolate import (interpolate_to_points, inverse_distance_to_points,
natural_neighbor_to_points)
from metpy.interpolate.geometry import dist_2, find_natural_neighbors
from metpy.interpolate.points import (barnes_point, cressman_point,
natural_neighbor_point)
from metpy.interpolate.points import barnes_point, cressman_point, natural_neighbor_point

logging.getLogger('metpy.interpolate.points').setLevel(logging.ERROR)

Expand Down
1 change: 1 addition & 0 deletions tests/plots/test_cartopy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_us_states_scales(ccrs):
def test_cartopy_stub(monkeypatch):
"""Test that the CartoPy stub will issue an error if CartoPy is not present."""
import sys

# This makes sure that cartopy is not found
monkeypatch.setitem(sys.modules, 'cartopy.crs', None)

Expand Down
1 change: 0 additions & 1 deletion tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from metpy.testing import needs_cartopy
from metpy.units import units


MPL_VERSION = matplotlib.__version__[:3]


Expand Down
1 change: 0 additions & 1 deletion tests/plots/test_skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from metpy.plots import Hodograph, SkewT
from metpy.units import units


MPL_VERSION = matplotlib.__version__[:3]


Expand Down
5 changes: 2 additions & 3 deletions tests/plots/test_station_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import pandas as pd
import pytest

from metpy.plots import (current_weather, high_clouds, nws_layout, simple_layout,
sky_cover, StationPlot, StationPlotLayout)
from metpy.plots import (current_weather, high_clouds, nws_layout, simple_layout, sky_cover,
StationPlot, StationPlotLayout)
from metpy.units import units


MPL_VERSION = matplotlib.__version__[:3]


Expand Down
11 changes: 3 additions & 8 deletions tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal,
get_test_data)
from metpy.units import DimensionalityError, units
from metpy.xarray import (
add_grid_arguments_from_xarray,
add_vertical_dim_from_xarray,
check_axis,
check_matching_coordinates,
grid_deltas_from_dataarray,
preprocess_and_wrap
)
from metpy.xarray import (add_grid_arguments_from_xarray, add_vertical_dim_from_xarray,
check_axis, check_matching_coordinates, grid_deltas_from_dataarray,
preprocess_and_wrap)


@pytest.fixture
Expand Down