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

Configure + enable stickler testing. #970

Merged
merged 3 commits into from
Nov 30, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stickler.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
linters:
flake8: { }
flake8:
6 changes: 4 additions & 2 deletions docs/make_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def find_projections():
for line in notes.split('\n'):
table.write(line.strip() + '\n')

prj_class_sorter = lambda cls: (PRJ_SORT_ORDER.get(cls.__name__, 100),
cls.__name__)
def prj_class_sorter(cls):
return (PRJ_SORT_ORDER.get(cls.__name__, 100),
cls.__name__)

for prj in sorted(find_projections(), key=prj_class_sorter):
name = prj.__name__

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@
# Commonly used sub-modules. Imported here to provide end-user
# convenience.
import cartopy.crs
import cartopy.feature
import cartopy.feature # noqa: F401 (flake8 = unused import)
5 changes: 2 additions & 3 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
from shapely.prepared import prep
import six

from cartopy._crs import CRS, Geocentric, Geodetic, Globe, PROJ4_VERSION
from cartopy._crs import CRS, Geodetic, Globe, PROJ4_VERSION
from cartopy._crs import Geocentric # noqa: F401 (flake8 = unused import)
import cartopy.trace


Expand Down Expand Up @@ -746,7 +747,6 @@ def quick_vertices_transform(self, vertices, src_crs):
mod = np.diff(src_crs.x_limits)[0]
bboxes, proj_offset = self._bbox_and_offset(src_crs)
x_lim = xs.min(), xs.max()
y_lim = ys.min(), ys.max()
for poly in bboxes:
Copy link
Member

Choose a reason for hiding this comment

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

@pp-mo What's happened to y_lim?

Copy link
Member Author

Choose a reason for hiding this comment

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

'y_lim' was not used, so flake8 complained about it, so I got rid of it.

There's a lot of that going on in this PR !

# Arbitrarily choose the number of moduli to look
# above and below the -180->180 range. If data is beyond
Expand Down Expand Up @@ -1184,7 +1184,6 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
globe=globe)

a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
b = np.float(self.globe.semiminor_axis or WGS84_SEMIMINOR_AXIS)
lon, lat = central_longitude + 180, - central_latitude + 0.01
Copy link
Member

Choose a reason for hiding this comment

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

@pp-mo And also what's happened to b (the semiminor axis)?

Copy link
Member Author

Choose a reason for hiding this comment

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

'b' also not used anywhere.
As it was identical, I suspect this one was a mistake from the first.

Copy link
Member

Choose a reason for hiding this comment

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

Identical to what?

Copy link
Member Author

Choose a reason for hiding this comment

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

Identical to 'a'.
If it was going to be useful, I'd expect it to be different in some way, but it's all just guesswork.

Copy link
Member

Choose a reason for hiding this comment

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

It's not identical to 'a', though. But I'm not sure it needs to be used anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see, it is not after all : more care required !

x, max_y = self.transform_point(lon, lat, PlateCarree())

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/examples/axes_grid_basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__tags__ = ['Miscellanea'] # noqa
__tags__ = ['Miscellanea']
"""
Using Cartopy and AxesGrid toolkit
----------------------------------
Expand Down
6 changes: 4 additions & 2 deletions lib/cartopy/geodesic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2015 - 2016, Met Office
# (C) British Crown Copyright 2015 - 2017, Met Office
#
# This file is part of cartopy.
#
Expand All @@ -16,4 +16,6 @@
# along with cartopy. If not, see <https://www.gnu.org/licenses/>.

from __future__ import (absolute_import, division, print_function)
from cartopy.geodesic._geodesic import Geodesic

# NOTE: noqa for flake8 = unused import
from cartopy.geodesic._geodesic import Geodesic # noqa: F401
8 changes: 4 additions & 4 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ def _image_url(self, tile):
"terrain": "t",
"only_streets": "h"}
url = self.url.format(
style=style_dict[self.style],
x=tile[0], X=tile[0],
y=tile[1], Y=tile[1],
z=tile[2], Z=tile[2])
style=style_dict[self.style],
x=tile[0], X=tile[0],
y=tile[1], Y=tile[1],
z=tile[2], Z=tile[2])
return url

def get_image(self, tile):
Expand Down
1 change: 0 additions & 1 deletion lib/cartopy/io/ogc_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ def default_projection(self):
'across all features (typenames).')
else:
default_urn = default_urn.pop()
default_srs = default_urn.id

if six.text_type(default_urn) not in _URN_TO_CRS:
raise ValueError('Unknown mapping from SRS/CRS_URN {!r} to '
Expand Down
12 changes: 6 additions & 6 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,15 +1790,15 @@ def streamplot(self, x, y, u, v, **kwargs):
regrid_shape = [int(25 * d) for d in density]
# The color and linewidth keyword arguments can be arrays so they will
# need to be gridded also.
c = kwargs.get('color', None)
l = kwargs.get('linewidth', None)
col = kwargs.get('color', None)
lw = kwargs.get('linewidth', None)
scalars = []
color_array = isinstance(c, np.ndarray)
linewidth_array = isinstance(l, np.ndarray)
color_array = isinstance(col, np.ndarray)
linewidth_array = isinstance(lw, np.ndarray)
if color_array:
scalars.append(c)
scalars.append(col)
if linewidth_array:
scalars.append(l)
scalars.append(lw)
# Do the regridding including any scalar fields.
target_extent = self.get_extent(self.projection)
gridded = vector_scalar_to_grid(t, self.projection, regrid_shape,
Expand Down
15 changes: 9 additions & 6 deletions lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def _north_south_formatted(latitude, num_format='g'):
hemisphere=_lat_heimisphere(latitude),
degree=_DEGREE_SYMBOL)


#: A formatter which turns longitude values into nice longitudes such as 110W
LONGITUDE_FORMATTER = mticker.FuncFormatter(lambda v, pos:
_east_west_formatted(v))
Expand Down Expand Up @@ -335,9 +336,10 @@ def _draw_gridliner(self, nx=None, ny=None, background_patch=None):
if self.xlines:
lines = []
for x in x_gridline_points:
l = list(zip(np.zeros(n_steps) + x,
np.linspace(min(y_ticks), max(y_ticks), n_steps)))
lines.append(l)
ticks = list(zip(
Copy link
Member

Choose a reason for hiding this comment

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

I could've sworn I'd written some optimization for this unfortunate type conversion; maybe I never made a PR out of it, but I can see if I can dig it up.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see a need to connect this with the issue at hand ?
We rather want to get this onto master so we can get on right now, since stickler is now complaining about various open PRs.

Copy link
Member

Choose a reason for hiding this comment

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

No, just a reminder to myself.

np.zeros(n_steps) + x,
np.linspace(min(y_ticks), max(y_ticks), n_steps)))
lines.append(ticks)

x_lc = mcollections.LineCollection(lines, **collection_kwargs)
self.xline_artists.append(x_lc)
Expand All @@ -346,9 +348,10 @@ def _draw_gridliner(self, nx=None, ny=None, background_patch=None):
if self.ylines:
lines = []
for y in y_ticks:
l = list(zip(np.linspace(min(x_ticks), max(x_ticks), n_steps),
np.zeros(n_steps) + y))
lines.append(l)
ticks = list(zip(
np.linspace(min(x_ticks), max(x_ticks), n_steps),
np.zeros(n_steps) + y))
lines.append(ticks)

y_lc = mcollections.LineCollection(lines, **collection_kwargs)
self.yline_artists.append(y_lc)
Expand Down
3 changes: 2 additions & 1 deletion lib/cartopy/mpl/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def path_segments(path, transform=None, remove_nans=False, clip=None,

"""
# XXX assigned to avoid a ValueError inside the mpl C code...
a = transform, remove_nans, clip, quantize, simplify, curves
a = (transform, # noqa: F841 (flake8 = assigned + unused : see above)
remove_nans, clip, quantize, simplify, curves)

# Series of cleanups and conversions to the path e.g. it
# can convert curved segments to line segments.
Expand Down
3 changes: 0 additions & 3 deletions lib/cartopy/sphinxext/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sys

from cartopy.sphinxext.summarise_package import walk_module
import cartopy.tests


def out_of_date(original_fname, target_fname):
Expand Down Expand Up @@ -202,8 +201,6 @@ def gallery_code(examples_mod_name):
# XXX The path is currently determined out of process by
# the plot directive. It would be nice to figure out the
# naming scheme to handle multiple plots in a single example.
img_path = 'examples/{}_00_00.png'.format(
mod_name.split('.')[-1])
thumb_path = 'examples/{}_00_00.thumb.png'.format(
mod_name.split('.')[-1])

Expand Down
2 changes: 0 additions & 2 deletions lib/cartopy/sphinxext/summarise_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import warnings
import six

import cartopy.tests


def walk_module(mod_name, exclude_folders=None):
"""
Expand Down
5 changes: 1 addition & 4 deletions lib/cartopy/tests/io/test_downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import contextlib
import os
import shutil
import warnings

import pytest
Expand Down Expand Up @@ -104,8 +103,6 @@ def test_from_config():
assert (r.url({'name': 'ocean'}) ==
'https://example.com/generic_ne/ocean.zip')

downloaders = cio.config['downloaders']

r = cio.Downloader.from_config(land_spec)
assert r is land_downloader

Expand Down Expand Up @@ -133,7 +130,7 @@ def test_downloading_simple_ascii(download_to_temp):
assert issubclass(w[0].category, cio.DownloadWarning)

with open(tmp_fname, 'r') as fh:
_ = fh.readline()
fh.readline()
assert fh.readline() == " * jQuery JavaScript Library v1.8.2\n"

# check that calling path again doesn't try re-downloading
Expand Down
1 change: 0 additions & 1 deletion lib/cartopy/tests/io/test_srtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import cartopy.crs as ccrs
import cartopy.io.srtm
from cartopy.tests.io.test_downloaders import download_to_temp


pytestmark = pytest.mark.skip('SRTM login not supported')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/cartopy/tests/mpl/test_img_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_regrid_image():
target_proj, target_x, target_y)

# Plot
fig = plt.figure(figsize=(10, 10))
plt.figure(figsize=(10, 10))
gs = mpl.gridspec.GridSpec(nrows=4, ncols=1,
hspace=1.5, wspace=0.5)
# Set up axes and title
Expand Down
5 changes: 2 additions & 3 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_global_scatter_wrap_no_transform():
@ImageTesting(['global_map'],
tolerance=16 if ccrs.PROJ4_VERSION < (4, 9) else 0.1)
def test_global_map():
ax = plt.axes(projection=ccrs.Robinson())
plt.axes(projection=ccrs.Robinson())
# ax.coastlines()
# ax.gridlines(5)

Expand Down Expand Up @@ -251,7 +251,7 @@ def test_pcolormesh_global_with_wrap2():
# make up some realistic data with bounds (such as data from the UM)
nx, ny = 36, 18
xbnds, xstep = np.linspace(0, 360, nx - 1, retstep=True, endpoint=True)
ybnds, ystep = np.linspace(-90, 90, nx - 1, retstep=True, endpoint=True)
ybnds, ystep = np.linspace(-90, 90, ny - 1, retstep=True, endpoint=True)
xbnds -= xstep / 2
ybnds -= ystep / 2
xbnds = np.append(xbnds, xbnds[-1] + xstep)
Expand Down Expand Up @@ -482,7 +482,6 @@ def test_barbs():
x2d, y2d = np.meshgrid(x, y)
u = 40 * np.cos(np.deg2rad(y2d))
v = 40 * np.cos(2. * np.deg2rad(x2d))
mag = (u**2 + v**2)**.5
plot_extent = [-60, 40, 30, 70]
plt.figure(figsize=(6, 6))
# plot on native projection
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/mpl/test_pseudo_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_savefig_tight():
data = np.exp(np.sin(np.deg2rad(x)) + np.cos(np.deg2rad(y)))
data = data[:-1, :-1]

ax = plt.subplot(211, projection=ccrs.Robinson())
plt.subplot(211, projection=ccrs.Robinson())
plt.pcolormesh(xbnds, ybnds, data, transform=ccrs.PlateCarree())
buf = io.BytesIO()
plt.savefig(buf, format='png', bbox_inches='tight')
Expand Down
1 change: 0 additions & 1 deletion lib/cartopy/tests/mpl/test_set_extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import matplotlib.pyplot as plt
import numpy as np
from numpy.testing import assert_array_almost_equal, assert_array_equal
import pytest

import cartopy.crs as ccrs

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/test_coastline.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def test_robust(self):
# for geometry in geometries:
for i, geometry in enumerate(geometries[93:]):
for line_string in geometry:
multi_line_string = projection.project_geometry(line_string)
projection.project_geometry(line_string)
1 change: 0 additions & 1 deletion lib/cartopy/tests/test_img_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from cartopy import config
import cartopy.io.img_tiles as cimgt
import cartopy.io.img_nest as cimg_nest
import cartopy.tests as tests


#: An integer version which should be increased if the test data needs
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/test_linear_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_three_points(self):
src_proj = ccrs.PlateCarree()
target_proj = ccrs.PlateCarree(180.0)
try:
_ = target_proj.project_geometry(linear_ring, src_proj)
target_proj.project_geometry(linear_ring, src_proj)
except ValueError:
pytest.fail("Failed to project LinearRing.")

Expand Down
4 changes: 2 additions & 2 deletions lib/cartopy/tests/test_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_polygon_boundary_attachment(self):
projection = ccrs.Robinson(170.6)
# This will raise an exception if the polygon/boundary intersection
# fails.
multi_polygon = projection.project_geometry(polygon)
projection.project_geometry(polygon)

def test_out_of_bounds(self):
# Check that a polygon that is completely out of the map boundary
Expand Down Expand Up @@ -74,7 +74,7 @@ class TestMisc(object):
def test_misc(self):
projection = ccrs.TransverseMercator(central_longitude=-90)
polygon = sgeom.Polygon([(-10, 30), (10, 60), (10, 50)])
multi_polygon = projection.project_geometry(polygon)
projection.project_geometry(polygon)

def test_small(self):
projection = ccrs.Mercator()
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ def test_invalid_coord_size(self):

def test_invalid_axis(self):
with pytest.raises(ValueError):
c_data = add_cyclic_point(self.data2d, axis=-3)
add_cyclic_point(self.data2d, axis=-3)
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
ignore = E402,\ # Due to conditional imports
E226,\ # Due to whitespace around operators (e.g. 2*x + 3)
E241 # Due to multiple spaces after comma
exclude = \
build, \
setup.py, \
docs/source/conf.py, \
docs/source/sphinxext/plot_directive.py