-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,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} | ||
|
|
||
|
|
||
| class VersioneerConfig: | ||
|
|
@@ -96,18 +95,18 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, | |
| if e.errno == errno.ENOENT: | ||
| continue | ||
| if verbose: | ||
| 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}") | ||
|
Comment on lines
-99
to
+109
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return None, process.returncode | ||
| return stdout, process.returncode | ||
|
|
||
|
|
@@ -131,8 +130,9 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): | |
| root = os.path.dirname(root) # up a level | ||
|
|
||
| if verbose: | ||
| 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}" | ||
| ) | ||
|
Comment on lines
-134
to
+135
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| raise NotThisMethod("rootdir doesn't start with parentdir_prefix") | ||
|
|
||
|
|
||
|
|
@@ -148,17 +148,14 @@ def git_get_keywords(versionfile_abs): | |
| with open(versionfile_abs, "r") as fobj: | ||
| for line in fobj: | ||
| if line.strip().startswith("git_refnames ="): | ||
| 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] | ||
|
Comment on lines
-151
to
+158
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| except OSError: | ||
| pass | ||
| return keywords | ||
|
|
@@ -202,9 +199,9 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): | |
| # "stabilization", as well as "HEAD" and "master". | ||
| tags = {r for r in refs if re.search(r'\d', r)} | ||
| if verbose: | ||
| 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))}') | ||
|
Comment on lines
-205
to
+204
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for ref in sorted(tags): | ||
| # sorting will prefer e.g. "2.0" over "2.0rc1" | ||
| if ref.startswith(tag_prefix): | ||
|
|
@@ -215,7 +212,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): | |
| if not re.match(r'\d', r): | ||
| continue | ||
| if verbose: | ||
| print("picking %s" % r) | ||
| print(f"picking {r}") | ||
| return {"version": r, | ||
| "full-revisionid": keywords["full"].strip(), | ||
| "dirty": False, "error": None, | ||
|
|
@@ -236,10 +233,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command): | |
| expanded, and _version.py hasn't already been rewritten with a short | ||
| version string, meaning we're inside a checked out source tree. | ||
| """ | ||
| GITS = ["git"] | ||
| if sys.platform == "win32": | ||
| GITS = ["git.cmd", "git.exe"] | ||
|
|
||
| GITS = ["git.cmd", "git.exe"] if sys.platform == "win32" else ["git"] | ||
|
Comment on lines
-239
to
+236
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| # GIT_DIR can interfere with correct operation of Versioneer. | ||
| # It may be intended to be passed to the Versioneer-versioned project, | ||
| # but that should not change where we get our version from. | ||
|
|
@@ -251,7 +245,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command): | |
| hide_stderr=True) | ||
| if rc != 0: | ||
| if verbose: | ||
| print("Directory %s not under git control" % root) | ||
| print(f"Directory {root} not under git control") | ||
| raise NotThisMethod("'git rev-parse --git-dir' returned error") | ||
|
|
||
| # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] | ||
|
|
@@ -269,11 +263,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command): | |
| raise NotThisMethod("'git rev-parse' failed") | ||
| full_out = full_out.strip() | ||
|
|
||
| pieces = {} | ||
| pieces["long"] = full_out | ||
| pieces["short"] = full_out[:7] # maybe improved later | ||
| pieces["error"] = None | ||
|
|
||
| pieces = {"long": full_out, "short": full_out[:7], "error": None} | ||
| branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], | ||
| cwd=root) | ||
| # --abbrev-ref was added in git-1.6.3 | ||
|
|
@@ -324,26 +314,23 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command): | |
| mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) | ||
| if not mo: | ||
| # unparsable. Maybe git-describe is misbehaving? | ||
| pieces["error"] = ("unable to parse git-describe output: '%s'" | ||
| % describe_out) | ||
| pieces["error"] = f"unable to parse git-describe output: '{describe_out}'" | ||
| return pieces | ||
|
|
||
| # tag | ||
| full_tag = mo.group(1) | ||
| full_tag = mo[1] | ||
| if not full_tag.startswith(tag_prefix): | ||
| if verbose: | ||
| fmt = "tag '%s' doesn't start with prefix '%s'" | ||
| print(fmt % (full_tag, tag_prefix)) | ||
| pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" | ||
| % (full_tag, tag_prefix)) | ||
| print(f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'") | ||
| pieces["error"] = f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'" | ||
| return pieces | ||
| pieces["closest-tag"] = full_tag[len(tag_prefix):] | ||
|
|
||
| # distance: number of commits since tag | ||
| pieces["distance"] = int(mo.group(2)) | ||
| pieces["distance"] = int(mo[2]) | ||
|
|
||
| # commit: short hex revision ID | ||
| pieces["short"] = mo.group(3) | ||
| pieces["short"] = mo[3] | ||
|
|
||
| else: | ||
| # HEX: no tags | ||
|
|
@@ -363,9 +350,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command): | |
|
|
||
| def plus_or_dot(pieces): | ||
| """Return a + if we don't already have one, else return a .""" | ||
| if "+" in pieces.get("closest-tag", ""): | ||
| return "." | ||
| return "+" | ||
| return "." if "+" in pieces.get("closest-tag", "") else "+" | ||
|
Comment on lines
-366
to
+353
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def render_pep440(pieces): | ||
|
|
@@ -382,14 +367,12 @@ 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
-385
to
+375
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return rendered | ||
|
|
||
|
|
||
|
|
@@ -409,17 +392,15 @@ def render_pep440_branch(pieces): | |
| rendered += ".dev0" | ||
| rendered += plus_or_dot(pieces) | ||
| rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
|
Comment on lines
-412
to
-413
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| else: | ||
| # exception #1 | ||
| rendered = "0" | ||
| if pieces["branch"] != "master": | ||
| rendered += ".dev0" | ||
| rendered += "+untagged.%d.g%s" % (pieces["distance"], | ||
| pieces["short"]) | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
| return rendered | ||
|
|
||
|
|
||
|
|
@@ -474,13 +455,13 @@ def render_pep440_post(pieces): | |
| if pieces["dirty"]: | ||
| rendered += ".dev0" | ||
| rendered += plus_or_dot(pieces) | ||
| rendered += "g%s" % pieces["short"] | ||
| rendered += f'g{pieces["short"]}' | ||
| else: | ||
| # exception #1 | ||
| rendered = "0.post%d" % pieces["distance"] | ||
| if pieces["dirty"]: | ||
| rendered += ".dev0" | ||
| rendered += "+g%s" % pieces["short"] | ||
| rendered += f'+g{pieces["short"]}' | ||
|
Comment on lines
-477
to
+464
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return rendered | ||
|
|
||
|
|
||
|
|
@@ -499,17 +480,15 @@ def render_pep440_post_branch(pieces): | |
| if pieces["branch"] != "master": | ||
| rendered += ".dev0" | ||
| rendered += plus_or_dot(pieces) | ||
| 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" | ||
|
Comment on lines
-502
to
+491
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return rendered | ||
|
|
||
|
|
||
|
|
@@ -525,13 +504,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
-528
to
+511
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return rendered | ||
|
|
||
|
|
||
|
|
@@ -604,7 +581,7 @@ def render(pieces, style): | |
| elif style == "git-describe-long": | ||
| rendered = render_git_describe_long(pieces) | ||
| else: | ||
| raise ValueError("unknown style '%s'" % style) | ||
| raise ValueError(f"unknown style '{style}'") | ||
|
Comment on lines
-607
to
+584
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return {"version": rendered, "full-revisionid": pieces["long"], | ||
| "dirty": pieces["dirty"], "error": None, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,22 +113,21 @@ def __init__(self, ds): | |
|
|
||
| @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()) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def as_cupy(self): | ||
| data_vars = {var: da.as_cupy() for var, da in self.ds.data_vars.items()} | ||
| return Dataset(data_vars=data_vars, coords=self.ds.coords, attrs=self.ds.attrs) | ||
|
|
||
| def as_numpy(self): | ||
| 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, | ||
| ) | ||
|
Comment on lines
-123
to
+130
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| # Attach the `as_cupy` methods to the top level `Dataset` and `Dataarray` objects. | ||
|
|
||
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_keywordsrefactored with the following changes:inline-immediately-returned-variable)