Skip to content
Closed
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
6 changes: 2 additions & 4 deletions pygmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,19 @@ def _get_ghostscript_version():

for gs_cmd in cmds:
try:
version = subprocess.check_output(
return subprocess.check_output(
[gs_cmd, "--version"], universal_newlines=True
).strip()
return version
Comment on lines -95 to -98
Copy link
Author

Choose a reason for hiding this comment

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

Function show_versions._get_ghostscript_version refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

except FileNotFoundError:
continue
return None

def _get_gmt_version():
"""Get GMT version."""
try:
version = subprocess.check_output(
return subprocess.check_output(
["gmt", "--version"], universal_newlines=True
).strip()
return version
Comment on lines -106 to -109
Copy link
Author

Choose a reason for hiding this comment

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

Function show_versions._get_gmt_version refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

except FileNotFoundError:
return None

Expand Down
23 changes: 9 additions & 14 deletions pygmt/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def get_keywords():
git_refnames = "$Format:%d$"
git_full = "$Format:%H$"
git_date = "$Format:%ci$"
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords
return {"refnames": git_refnames, "full": git_full, "date": git_date}
Copy link
Author

Choose a reason for hiding this comment

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

Function get_keywords refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



class VersioneerConfig:
Expand Down Expand Up @@ -117,7 +116,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
"""
rootdirs = []

for i in range(3):
for _ in range(3):
Comment on lines -120 to +119
Copy link
Author

Choose a reason for hiding this comment

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

Function versions_from_parentdir refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

dirname = os.path.basename(root)
if dirname.startswith(parentdir_prefix):
return {
Expand Down Expand Up @@ -187,11 +186,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
refs = {r.strip() for r in refnames.strip("()").split(",")}
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
Comment on lines -190 to +193
Copy link
Author

Choose a reason for hiding this comment

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

Function git_versions_from_keywords refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)
  • Replace list(), dict() or set() with comprehension (collection-builtin-to-comprehension)

if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
Expand All @@ -200,7 +199,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r"\d", r)])
tags = {r for r in refs if re.search(r"\d", r)}
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
Expand Down Expand Up @@ -352,13 +351,11 @@ def render_pep440(pieces):
if pieces["distance"] or pieces["dirty"]:
rendered += plus_or_dot(pieces)
rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"
else:
# exception #1
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"
if pieces["dirty"]:
rendered += ".dirty"
Comment on lines -355 to +358
Copy link
Author

Choose a reason for hiding this comment

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

Function render_pep440 refactored with the following changes:

  • Hoist conditional out of nested conditional (hoist-if-from-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

return rendered


Expand Down Expand Up @@ -417,13 +414,11 @@ def render_pep440_old(pieces):
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += ".post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
else:
# exception #1
rendered = "0.post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
if pieces["dirty"]:
rendered += ".dev0"
Comment on lines -420 to +421
Copy link
Author

Choose a reason for hiding this comment

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

Function render_pep440_old refactored with the following changes:

  • Hoist conditional out of nested conditional (hoist-if-from-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

return rendered


Expand Down
2 changes: 1 addition & 1 deletion pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def basemap(self, **kwargs):

"""
kwargs = self._preprocess(**kwargs)
if not ("B" in kwargs or "L" in kwargs or "T" in kwargs):
if "B" not in kwargs and "L" not in kwargs and "T" not in kwargs:
Copy link
Author

Choose a reason for hiding this comment

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

Function BasePlotting.basemap refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

raise GMTInvalidInput("At least one of B, L, or T must be specified.")
with Session() as lib:
lib.call_module("basemap", build_arg_string(kwargs))
Expand Down
5 changes: 2 additions & 3 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def dataarray_to_matrix(grid):
region.extend([coord.min(), coord.max()])
inc.append(coord_inc)

if any([i < 0 for i in inc]): # Sort grid when there are negative increments
if any(i < 0 for i in inc): # Sort grid when there are negative increments
Copy link
Author

Choose a reason for hiding this comment

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

Function dataarray_to_matrix refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)

inc = [abs(i) for i in inc]
grid = grid.sortby(variables=list(grid.dims), ascending=True)

Expand Down Expand Up @@ -155,8 +155,7 @@ def vectors_to_arrays(vectors):
True

"""
arrays = [as_c_contiguous(np.asarray(i)) for i in vectors]
return arrays
return [as_c_contiguous(np.asarray(i)) for i in vectors]
Copy link
Author

Choose a reason for hiding this comment

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

Function vectors_to_arrays refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



def as_c_contiguous(array):
Expand Down
10 changes: 3 additions & 7 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ def _parse_pad(self, family, kwargs):
"""
pad = kwargs.get("pad", None)
if pad is None:
if "MATRIX" in family:
pad = 0
else:
pad = self["GMT_PAD_DEFAULT"]
pad = 0 if "MATRIX" in family else self["GMT_PAD_DEFAULT"]
Copy link
Author

Choose a reason for hiding this comment

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

Function Session._parse_pad refactored with the following changes:

  • Swap positions of nested conditionals (swap-nested-ifs)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)
  • Replace if statement with if expression (assign-if-exp)

return pad

def _parse_constant(self, constant, valid, valid_modifiers=None):
Expand Down Expand Up @@ -666,8 +663,7 @@ def _parse_constant(self, constant, valid, valid_modifiers=None):
parts[1], str(valid_modifiers)
)
)
integer_value = sum(self[part] for part in parts)
return integer_value
return sum(self[part] for part in parts)
Comment on lines -669 to +666
Copy link
Author

Choose a reason for hiding this comment

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

Function Session._parse_constant refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


def _check_dtype_and_dim(self, array, ndim):
"""
Expand Down Expand Up @@ -1071,7 +1067,7 @@ def virtualfile_from_vectors(self, *vectors):

columns = len(arrays)
rows = len(arrays[0])
if not all(len(i) == rows for i in arrays):
if any(len(i) != rows for i in arrays):
Comment on lines -1074 to +1070
Copy link
Author

Choose a reason for hiding this comment

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

Function Session.virtualfile_from_vectors refactored with the following changes:

  • Invert any/all to simplify comparisons (invert-any-all)

raise GMTInvalidInput("All arrays must have same size.")

family = "GMT_IS_DATASET|GMT_VIA_VECTOR"
Expand Down
11 changes: 6 additions & 5 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ def _is_valid_resolution(resolution):
pygmt.exceptions.GMTInvalidInput: Invalid Earth relief resolution '01s'.

"""
valid_resolutions = ["01d"]
valid_resolutions.extend(
[f"{res:02d}m" for res in [60, 30, 20, 15, 10, 6, 5, 4, 3, 2, 1]]
)
valid_resolutions.extend([f"{res:02d}s" for res in [30, 15]])
valid_resolutions = [
"01d",
*[f"{res:02d}m" for res in [60, 30, 20, 15, 10, 6, 5, 4, 3, 2, 1]],
*[f"{res:02d}s" for res in [30, 15]],
]

Comment on lines -104 to +109
Copy link
Author

Choose a reason for hiding this comment

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

Function _is_valid_resolution refactored with the following changes:

  • Merge extend into list declaration (merge-list-extend)

if resolution not in valid_resolutions:
raise GMTInvalidInput(
"Invalid Earth relief resolution '{}'.".format(resolution)
Expand Down
9 changes: 3 additions & 6 deletions pygmt/datasets/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ def load_ocean_ridge_points():
The data table. Columns are longitude and latitude.
"""
fname = which("@ridge.txt", download="c")
data = pd.read_csv(
return pd.read_csv(
fname, sep=r"\s+", names=["longitude", "latitude"], skiprows=1, comment=">"
)
return data
Comment on lines -58 to -61
Copy link
Author

Choose a reason for hiding this comment

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

Function load_ocean_ridge_points refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



def load_sample_bathymetry():
Expand All @@ -78,10 +77,9 @@ def load_sample_bathymetry():
The data table. Columns are longitude, latitude, and bathymetry.
"""
fname = which("@tut_ship.xyz", download="c")
data = pd.read_csv(
return pd.read_csv(
fname, sep="\t", header=None, names=["longitude", "latitude", "bathymetry"]
)
return data
Comment on lines -81 to -84
Copy link
Author

Choose a reason for hiding this comment

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

Function load_sample_bathymetry refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



def load_usgs_quakes():
Expand All @@ -102,5 +100,4 @@ def load_usgs_quakes():

"""
fname = which("@usgs_quakes_22.txt", download="c")
data = pd.read_csv(fname)
return data
return pd.read_csv(fname)
Comment on lines -105 to +103
Copy link
Author

Choose a reason for hiding this comment

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

Function load_usgs_quakes refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

7 changes: 3 additions & 4 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def _activate_figure(self):
:meth:`pygmt.Figure.savefig` or :meth:`pygmt.Figure.psconvert` must be
made in order to get a file.
"""
# Passing format '-' tells pygmt.end to not produce any files.
fmt = "-"
with Session() as lib:
# Passing format '-' tells pygmt.end to not produce any files.
fmt = "-"
Comment on lines -86 to +88
Copy link
Author

Choose a reason for hiding this comment

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

Function Figure._activate_figure refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

lib.call_module("figure", "{} {}".format(self._name, fmt))

def _preprocess(self, **kwargs):
Expand Down Expand Up @@ -362,8 +362,7 @@ def _repr_png_(self):
Show a PNG preview if the object is returned in an interactive shell.
For the Jupyter notebook or IPython Qt console.
"""
png = self._preview(fmt="png", dpi=70, anti_alias=True, as_bytes=True)
return png
return self._preview(fmt="png", dpi=70, anti_alias=True, as_bytes=True)
Copy link
Author

Choose a reason for hiding this comment

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

Function Figure._repr_png_ refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


def _repr_html_(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def build_arg_string(kwargs):
else:
sorted_args.append("-{}{}".format(key, kwargs[key]))

arg_str = " ".join(sorted_args)
return arg_str
return " ".join(sorted_args)
Copy link
Author

Choose a reason for hiding this comment

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

Function build_arg_string refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



def is_nonstr_iter(value):
Expand Down
2 changes: 1 addition & 1 deletion pygmt/session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def begin():

Only meant to be used once for creating the global session.
"""
prefix = "pygmt-session"
with Session() as lib:
prefix = "pygmt-session"
Comment on lines -15 to +16
Copy link
Author

Choose a reason for hiding this comment

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

Function begin refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

lib.call_module("begin", prefix)
# pygmt relies on GMT modern mode with GMT_COMPATIBILITY at version 6
lib.call_module("set", "GMT_COMPATIBILITY 6")
Expand Down
2 changes: 1 addition & 1 deletion pygmt/sphinx_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __call__(self, block, block_vars, gallery_conf):
Called by sphinx-gallery to save the figures generated after running
code.
"""
image_names = list()
image_names = []
Copy link
Author

Choose a reason for hiding this comment

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

Function PyGMTScraper.__call__ refactored with the following changes:

  • Replace list() with [] (list-literal)

image_path_iterator = block_vars["image_path_iterator"]
figures = SHOWED_FIGURES
while figures:
Expand Down
37 changes: 17 additions & 20 deletions pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def test_destroy_session_fails():
def test_call_module():
"Run a command to see if call_module works"
data_fname = os.path.join(TEST_DATA_DIR, "points.txt")
out_fname = "test_call_module.txt"
with clib.Session() as lib:
out_fname = "test_call_module.txt"
Comment on lines -132 to +133
Copy link
Author

Choose a reason for hiding this comment

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

Function test_call_module refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -132 to +133
Copy link
Author

Choose a reason for hiding this comment

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

Function test_call_module refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

with GMTTempFile() as out_fname:
lib.call_module("info", "{} -C ->{}".format(data_fname, out_fname.name))
assert os.path.exists(out_fname.name)
Expand Down Expand Up @@ -321,10 +321,10 @@ def test_put_vector():
lib.put_vector(dataset, column=lib["GMT_X"], vector=x)
lib.put_vector(dataset, column=lib["GMT_Y"], vector=y)
lib.put_vector(dataset, column=lib["GMT_Z"], vector=z)
# Turns out wesn doesn't matter for Datasets
wesn = [0] * 6
# Save the data to a file to see if it's being accessed correctly
with GMTTempFile() as tmp_file:
# Turns out wesn doesn't matter for Datasets
wesn = [0] * 6
Comment on lines -324 to +327
Copy link
Author

Choose a reason for hiding this comment

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

Function test_put_vector refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -324 to +327
Copy link
Author

Choose a reason for hiding this comment

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

Function test_put_vector refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

lib.write_data(
"GMT_IS_VECTOR",
"GMT_IS_POINT",
Expand Down Expand Up @@ -396,10 +396,10 @@ def test_put_matrix():
)
data = np.arange(shape[0] * shape[1], dtype=dtype).reshape(shape)
lib.put_matrix(dataset, matrix=data)
# wesn doesn't matter for Datasets
wesn = [0] * 6
# Save the data to a file to see if it's being accessed correctly
with GMTTempFile() as tmp_file:
# wesn doesn't matter for Datasets
wesn = [0] * 6
Comment on lines -399 to +402
Copy link
Author

Choose a reason for hiding this comment

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

Function test_put_matrix refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -399 to +402
Copy link
Author

Choose a reason for hiding this comment

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

Function test_put_matrix refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

lib.write_data(
"GMT_IS_MATRIX",
"GMT_IS_POINT",
Expand Down Expand Up @@ -521,13 +521,13 @@ def test_virtual_file_fails():
def test_virtual_file_bad_direction():
"Test passing an invalid direction argument"
with clib.Session() as lib:
vfargs = (
"GMT_IS_DATASET|GMT_VIA_MATRIX",
"GMT_IS_POINT",
"GMT_IS_GRID", # The invalid direction argument
0,
)
with pytest.raises(GMTInvalidInput):
vfargs = (
"GMT_IS_DATASET|GMT_VIA_MATRIX",
"GMT_IS_POINT",
"GMT_IS_GRID", # The invalid direction argument
0,
)
Comment on lines -524 to +530
Copy link
Author

Choose a reason for hiding this comment

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

Function test_virtual_file_bad_direction refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -524 to +530
Copy link
Author

Choose a reason for hiding this comment

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

Function test_virtual_file_bad_direction refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

with lib.open_virtual_file(*vfargs):
print("This should have failed")

Expand Down Expand Up @@ -648,11 +648,11 @@ def test_virtualfile_from_vectors_pandas():

def test_virtualfile_from_vectors_arraylike():
"Pass array-like vectors to a dataset"
size = 13
x = list(range(0, size, 1))
y = tuple(range(size, size * 2, 1))
z = range(size * 2, size * 3, 1)
with clib.Session() as lib:
size = 13
x = list(range(0, size, 1))
y = tuple(range(size, size * 2, 1))
z = range(size * 2, size * 3, 1)
Comment on lines -651 to +655
Copy link
Author

Choose a reason for hiding this comment

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

Function test_virtualfile_from_vectors_arraylike refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -651 to +655
Copy link
Author

Choose a reason for hiding this comment

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

Function test_virtualfile_from_vectors_arraylike refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

with lib.virtualfile_from_vectors(x, y, z) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", "{} ->{}".format(vfile, outfile.name))
Expand Down Expand Up @@ -834,12 +834,9 @@ def test_fails_for_wrong_version():
"Make sure the clib.Session raises an exception if GMT is too old"

# Mock GMT_Get_Default to return an old version
def mock_defaults(api, name, value): # pylint: disable=unused-argument
def mock_defaults(api, name, value): # pylint: disable=unused-argument
"Return an old version"
if name == b"API_VERSION":
value.value = b"5.4.3"
else:
value.value = b"bla"
value.value = b"5.4.3" if name == b"API_VERSION" else b"bla"
Comment on lines -837 to +839
Copy link
Author

Choose a reason for hiding this comment

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

Function test_fails_for_wrong_version.mock_defaults refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -837 to +839
Copy link
Author

Choose a reason for hiding this comment

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

Function test_fails_for_wrong_version.mock_defaults refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

return 0

lib = clib.Session()
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_contour_fail_no_data(data):
# is not given:
for variable in product([None, data[:, 0]], repeat=3):
# Filter one valid configuration:
if not any(item is None for item in variable):
if all(item is not None for item in variable):
Copy link
Author

Choose a reason for hiding this comment

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

Function test_contour_fail_no_data refactored with the following changes:

  • Simplify inverted any() and all() calls

Copy link
Author

Choose a reason for hiding this comment

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

Function test_contour_fail_no_data refactored with the following changes:

  • Invert any/all to simplify comparisons (invert-any-all)

continue
with pytest.raises(GMTInvalidInput):
fig.contour(
Expand Down
8 changes: 4 additions & 4 deletions pygmt/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def test_legend_specfile():
Test specfile functionality.
"""

specfile_contents = """
with GMTTempFile() as specfile:

with open(specfile.name, "w") as file:
specfile_contents = """
Comment on lines -81 to +84
Copy link
Author

Choose a reason for hiding this comment

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

Function test_legend_specfile refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -81 to +84
Copy link
Author

Choose a reason for hiding this comment

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

Function test_legend_specfile refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

G -0.1i
H 24 Times-Roman My Map Legend
D 0.2i 1p
Expand All @@ -105,9 +108,6 @@ def test_legend_specfile():
T so we may have to adjust the box height to get the right size box.
"""

with GMTTempFile() as specfile:

with open(specfile.name, "w") as file:
file.write(specfile_contents)

fig = Figure()
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_sphinx_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_pygmtscraper():
"Make sure the scraper finds the figures and removes them from the pool."

showed = SHOWED_FIGURES.copy()
for _ in range(len(SHOWED_FIGURES)):
for SHOWED_FIGURE in SHOWED_FIGURES:
Copy link
Author

Choose a reason for hiding this comment

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

Function test_pygmtscraper refactored with the following changes:

  • Simplify generator expression
  • Replace index in for loop with direct reference

Copy link
Author

Choose a reason for hiding this comment

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

Function test_pygmtscraper refactored with the following changes:

  • Simplify generator expression (simplify-generator)
  • Replace index in for loop with direct reference (for-index-replacement)

SHOWED_FIGURES.pop()
try:
fig = Figure()
Expand All @@ -31,7 +31,7 @@ def test_pygmtscraper():
with TemporaryDirectory(dir=os.getcwd()) as tmpdir:
conf = {"src_dir": "meh"}
fname = os.path.join(tmpdir, "meh.png")
block_vars = {"image_path_iterator": (i for i in [fname])}
block_vars = {"image_path_iterator": iter([fname])}
assert not os.path.exists(fname)
scraper(None, block_vars, conf)
assert os.path.exists(fname)
Expand Down
Loading