-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored kadykov/cupy-xarray #1
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
base: main
Are you sure you want to change the base?
Conversation
| print("Warning: build in %s is using versioneer.py from %s" | ||
| % (os.path.dirname(my_path), versioneer_py)) | ||
| print( | ||
| f"Warning: build in {os.path.dirname(my_path)} is using versioneer.py from {versioneer_py}" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_root refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| print("unable to run %s" % dispcmd) | ||
| print(f"unable to run {dispcmd}") | ||
| print(e) | ||
| return None, None | ||
| else: | ||
| if verbose: | ||
| print("unable to find command, tried %s" % (commands,)) | ||
| print(f"unable to find command, tried {commands}") | ||
| return None, None | ||
| stdout = process.communicate()[0].strip().decode() | ||
| if process.returncode != 0: | ||
| if verbose: | ||
| print("unable to run %s (error)" % dispcmd) | ||
| print("stdout was %s" % stdout) | ||
| print(f"unable to run {dispcmd} (error)") | ||
| print(f"stdout was {stdout}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run_command refactored with the following changes:
- Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring)
| mo = re.search(r'=\s*"(.*)"', line) | ||
| if mo: | ||
| keywords["refnames"] = mo.group(1) | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["refnames"] = mo[1] | ||
| if line.strip().startswith("git_full ="): | ||
| mo = re.search(r'=\s*"(.*)"', line) | ||
| if mo: | ||
| keywords["full"] = mo.group(1) | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["full"] = mo[1] | ||
| if line.strip().startswith("git_date ="): | ||
| mo = re.search(r'=\s*"(.*)"', line) | ||
| if mo: | ||
| keywords["date"] = mo.group(1) | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["date"] = mo[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function git_get_keywords refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups)
| print(f"""discarding '{",".join(refs - tags)}', no digits""") | ||
| if verbose: | ||
| print("likely tags: %s" % ",".join(sorted(tags))) | ||
| print(f'likely tags: {",".join(sorted(tags))}') |
There was a problem hiding this comment.
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 interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring)
| GITS = ["git"] | ||
| if sys.platform == "win32": | ||
| GITS = ["git.cmd", "git.exe"] | ||
|
|
||
| GITS = ["git.cmd", "git.exe"] if sys.platform == "win32" else ["git"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function git_pieces_from_vcs refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring) - Merge dictionary assignment with declaration [×3] (
merge-dict-assign) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups) - Inline variable that is only used once (
inline-variable) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# maybe improved later
| raise ValueError("unknown style '%s'" % style) | ||
| raise ValueError(f"unknown style '{style}'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function render refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| assert handlers, "unrecognized VCS '%s'" % cfg.VCS | ||
| assert handlers, f"unrecognized VCS '{cfg.VCS}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_versions refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring)
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_cmdclass refactored with the following changes:
- Replace interpolated string formatting with f-string [×10] (
replace-interpolation-with-fstring)
This removes the following comments ( why? ):
# "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION
# as FILEVERSION, but it can be used for PRODUCTVERSION, e.g.
# setup(console=[{
# nczeczulin reports that py2exe won't like the pep440-style string
# "product_version": versioneer.get_version(),
# ...
| print(" creating %s" % cfg.versionfile_source) | ||
| print(f" creating {cfg.versionfile_source}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function do_setup refactored with the following changes:
- Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring)
| for line in f.readlines(): | ||
| for line in f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function scan_setup_py refactored with the following changes:
- Iterate over files directly rather than using readlines() (
use-file-iterator)
| 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} |
There was a problem hiding this comment.
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)
| print("unable to run %s" % dispcmd) | ||
| print(f"unable to run {dispcmd}") | ||
| print(e) | ||
| return None, None | ||
| else: | ||
| if verbose: | ||
| print("unable to find command, tried %s" % (commands,)) | ||
| print(f"unable to find command, tried {commands}") | ||
| return None, None | ||
| stdout = process.communicate()[0].strip().decode() | ||
| if process.returncode != 0: | ||
| if verbose: | ||
| print("unable to run %s (error)" % dispcmd) | ||
| print("stdout was %s" % stdout) | ||
| print(f"unable to run {dispcmd} (error)") | ||
| print(f"stdout was {stdout}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run_command refactored with the following changes:
- Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring)
| print("Tried directories %s but none started with prefix %s" % | ||
| (str(rootdirs), parentdir_prefix)) | ||
| print( | ||
| f"Tried directories {rootdirs} but none started with prefix {parentdir_prefix}" | ||
| ) |
There was a problem hiding this comment.
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 interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Remove unnecessary calls to
str()from formatted values in f-strings (remove-str-from-fstring)
| mo = re.search(r'=\s*"(.*)"', line) | ||
| if mo: | ||
| keywords["refnames"] = mo.group(1) | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["refnames"] = mo[1] | ||
| if line.strip().startswith("git_full ="): | ||
| mo = re.search(r'=\s*"(.*)"', line) | ||
| if mo: | ||
| keywords["full"] = mo.group(1) | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["full"] = mo[1] | ||
| if line.strip().startswith("git_date ="): | ||
| mo = re.search(r'=\s*"(.*)"', line) | ||
| if mo: | ||
| keywords["date"] = mo.group(1) | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["date"] = mo[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function git_get_keywords refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups)
| print("discarding '%s', no digits" % ",".join(refs - tags)) | ||
| print(f"""discarding '{",".join(refs - tags)}', no digits""") | ||
| if verbose: | ||
| print("likely tags: %s" % ",".join(sorted(tags))) | ||
| print(f'likely tags: {",".join(sorted(tags))}') |
There was a problem hiding this comment.
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 interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring)
| rendered += "g%s" % pieces["short"] | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
| rendered += f'g{pieces["short"]}' | ||
| else: | ||
| # exception #1 | ||
| rendered = "0.post%d" % pieces["distance"] | ||
| if pieces["branch"] != "master": | ||
| rendered += ".dev0" | ||
| rendered += "+g%s" % pieces["short"] | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
| rendered += f'+g{pieces["short"]}' | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function render_pep440_post_branch refactored with the following changes:
- Split conditional into multiple branches [×2] (
split-or-ifs) - Merge duplicate blocks in conditional [×2] (
merge-duplicate-blocks) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring) - Hoist conditional out of nested conditional (
hoist-if-from-if) - Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Remove redundant conditional [×2] (
remove-redundant-if)
| if pieces["dirty"]: | ||
| rendered += ".dev0" | ||
| else: | ||
| # exception #1 | ||
| rendered = "0.post%d" % pieces["distance"] | ||
| if pieces["dirty"]: | ||
| rendered += ".dev0" | ||
| if pieces["dirty"]: | ||
| rendered += ".dev0" |
There was a problem hiding this comment.
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)
| raise ValueError("unknown style '%s'" % style) | ||
| raise ValueError(f"unknown style '{style}'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function render refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| @property | ||
| def is_cupy(self): | ||
| return all([da.cupy.is_cupy for da in self.ds.data_vars.values()]) | ||
| return all(da.cupy.is_cupy for da in self.ds.data_vars.values()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CupyDatasetAccessor.is_cupy refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| if self.is_cupy: | ||
| data_vars = {var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items()} | ||
| return Dataset( | ||
| data_vars=data_vars, | ||
| coords=self.ds.coords, | ||
| attrs=self.ds.attrs, | ||
| ) | ||
| else: | ||
| if not self.is_cupy: | ||
| return self.ds.as_numpy() | ||
| data_vars = {var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items()} | ||
| return Dataset( | ||
| data_vars=data_vars, | ||
| coords=self.ds.coords, | ||
| attrs=self.ds.attrs, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CupyDatasetAccessor.as_numpy refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run: