Skip to content

Commit

Permalink
MNT: Add config for isort and run on code
Browse files Browse the repository at this point in the history
This matches our previous configuration as closely as possible. Most of
the changes here either compress some lines or pick up a few imports
that weren't quite right.
  • Loading branch information
dopplershift committed Jul 7, 2021
1 parent c073e24 commit 32cec8d
Show file tree
Hide file tree
Showing 29 changed files with 63 additions and 66 deletions.
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
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
6 changes: 3 additions & 3 deletions src/metpy/plots/_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"""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
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
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
4 changes: 2 additions & 2 deletions tests/units/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import pandas as pd
import pytest

from metpy.testing import assert_array_almost_equal, assert_array_equal
from metpy.testing import assert_nan
from metpy.testing import (assert_array_almost_equal, assert_array_equal, # noqa: F401
assert_nan)
from metpy.units import check_units, concatenate, pandas_dataframe_to_unit_arrays, units


Expand Down

0 comments on commit 32cec8d

Please sign in to comment.