Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jun 24, 2020

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -132 to +133
out_fname = "test_call_module.txt"
with clib.Session() as lib:
out_fname = "test_call_module.txt"
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 -324 to +327
# 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
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 -399 to +402
# 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
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 -519 to +530
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,
)
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 -646 to +655
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)
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 -832 to +839
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"
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

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

Comment on lines -78 to +84
specfile_contents = """
with GMTTempFile() as specfile:

with open(specfile.name, "w") as file:
specfile_contents = """
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


showed = [fig for fig in SHOWED_FIGURES]
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

@sourcery-ai sourcery-ai bot force-pushed the sourcery/master branch from f63f29d to 45abfc0 Compare June 24, 2020 00:30
@sourcery-ai sourcery-ai bot force-pushed the sourcery/master branch from 45abfc0 to e0a5cc0 Compare July 12, 2020 09:38
@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 12, 2020

Sourcery Code Quality Report (beta)

✅ Merging this PR will increase code quality in the affected files by 0.02 out of 10.

Before After Change
Quality 8.25 8.27 0.02
Complexity 2.78 2.68 -0.1
Method Length 67.41 66.93 -0.49
Lines 6853 6827 -26
Changed files Quality Before Quality After Quality Change
versioneer.py 7.78 7.81 0.03 ⬆️
pygmt/init.py 7.91 7.94 0.03 ⬆️
pygmt/_version.py 7.78 7.84 0.06 ⬆️
pygmt/base_plotting.py 7.45 7.45 0.0
pygmt/figure.py 8.82 8.82 0.01 ⬆️
pygmt/session_management.py 9.64 9.64 0.0
pygmt/sphinx_gallery.py 9.07 9.08 0.01 ⬆️
pygmt/clib/conversion.py 8.95 8.97 0.01 ⬆️
pygmt/clib/session.py 8.37 8.38 0.01 ⬆️
pygmt/datasets/earth_relief.py 8.24 8.28 0.04 ⬆️
pygmt/datasets/tutorial.py 9.43 9.47 0.04 ⬆️
pygmt/helpers/utils.py 8.6 8.61 0.01 ⬆️
pygmt/tests/test_clib.py 8.41 8.41 0.01 ⬆️
pygmt/tests/test_contour.py 8.79 8.79 0.0
pygmt/tests/test_legend.py 8.89 8.89 0.0
pygmt/tests/test_sphinx_gallery.py 8.24 8.29 0.05 ⬆️

Here are some functions in these files that still need a tune-up:

File Function Quality Recommendation
pygmt/base_plotting.py BasePlotting.text 3.36 Split out functionality
versioneer.py do_setup 3.55 Split out functionality
versioneer.py git_pieces_from_vcs 3.84 Split out functionality
versioneer.py get_cmdclass 3.84 Split out functionality
pygmt/_version.py git_pieces_from_vcs 3.84 Split out functionality

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it via email or our Gitter!

Comment on lines -992 to +996
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)}
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)

Comment on lines -1144 to +1148
if line.strip().startswith(versionfile_source):
if "export-subst" in line.strip().split()[1:]:
present = True
if (
line.strip().startswith(versionfile_source)
and "export-subst" in line.strip().split()[1:]
):
present = 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 do_vcs_install refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

Comment on lines -1167 to +1169
for i in range(3):
for _ in range(3):
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)

Comment on lines -1250 to +1257
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"
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)

Comment on lines -1316 to +1320
if pieces["dirty"]:
rendered += ".dev0"
else:
# exception #1
rendered = "0.post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
if pieces["dirty"]:
rendered += ".dev0"
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)

Comment on lines -15 to +16
prefix = "pygmt-session"
with Session() as lib:
prefix = "pygmt-session"
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)

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)

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)

"""
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)

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)

Comment on lines -669 to +666
integer_value = sum(self[part] for part in parts)
return integer_value
return sum(self[part] for part in parts)
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)

Comment on lines -1074 to +1070
if not all(len(i) == rows for i in arrays):
if any(len(i) != rows for i in arrays):
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)

Comment on lines -104 to +109
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]],
]

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)

Comment on lines -58 to -61
data = pd.read_csv(
return pd.read_csv(
fname, sep=r"\s+", names=["longitude", "latitude"], skiprows=1, comment=">"
)
return data
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)

Comment on lines -81 to -84
data = pd.read_csv(
return pd.read_csv(
fname, sep="\t", header=None, names=["longitude", "latitude", "bathymetry"]
)
return data
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)

Comment on lines -651 to +655
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)
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)

Comment on lines -837 to +839
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"
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)

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:

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

Comment on lines -81 to +84
specfile_contents = """
with GMTTempFile() as specfile:

with open(specfile.name, "w") as file:
specfile_contents = """
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)


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 (simplify-generator)
  • Replace index in for loop with direct reference (for-index-replacement)

weiji14 added a commit to GenericMappingTools/pygmt that referenced this pull request Jul 12, 2020
@weiji14 weiji14 closed this Feb 12, 2021
@weiji14 weiji14 deleted the sourcery/master branch February 12, 2021 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant