-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
print('pytest arguments: {}'.format(args)) | ||
print(f'pytest arguments: {args}') |
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.
Lines 14-14
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
print("Warning: build in %s is using versioneer.py from %s" | ||
% (os.path.dirname(me), versioneer_py)) | ||
print( | ||
f"Warning: build in {os.path.dirname(me)} 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 = p.communicate()[0].strip().decode() | ||
if p.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
)
f = open(versionfile_abs, "r") | ||
for line in f.readlines(): | ||
if line.strip().startswith("git_refnames ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["refnames"] = mo.group(1) | ||
if line.strip().startswith("git_full ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["full"] = mo.group(1) | ||
if line.strip().startswith("git_date ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["date"] = mo.group(1) | ||
f.close() | ||
with open(versionfile_abs, "r") as f: | ||
for line in f: | ||
if line.strip().startswith("git_refnames ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["refnames"] = mo.group(1) | ||
if line.strip().startswith("git_full ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["full"] = mo.group(1) | ||
if line.strip().startswith("git_date ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["date"] = mo.group(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
with
when opening file to ensure closure (ensure-file-closed
) - Iterate over files directly rather than using readlines() (
use-file-iterator
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
)
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)} |
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 list(), dict() or set() with comprehension [×3] (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator [×3] (
comprehension-to-generator
) - Replace interpolated string formatting with f-string [×3] (
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? ):
# nczeczulin reports that py2exe won't like the pep440-style string
# ...
# setup(console=[{
# "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION
# "product_version": versioneer.get_version(),
# as FILEVERSION, but it can be used for PRODUCTVERSION, e.g.
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
)
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 = p.communicate()[0].strip().decode() | ||
if p.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
)
for i in range(3): | ||
for _ in range(3): | ||
dirname = os.path.basename(root) | ||
if dirname.startswith(parentdir_prefix): | ||
return {"version": dirname[len(parentdir_prefix):], | ||
"full-revisionid": None, | ||
"dirty": False, "error": None, "date": None} | ||
else: | ||
rootdirs.append(root) | ||
root = os.path.dirname(root) # up a level | ||
rootdirs.append(root) | ||
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}" | ||
) |
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 unused for index with underscore (
for-index-underscore
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
f = open(versionfile_abs, "r") | ||
for line in f.readlines(): | ||
if line.strip().startswith("git_refnames ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["refnames"] = mo.group(1) | ||
if line.strip().startswith("git_full ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["full"] = mo.group(1) | ||
if line.strip().startswith("git_date ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["date"] = mo.group(1) | ||
f.close() | ||
with open(versionfile_abs, "r") as f: | ||
for line in f: | ||
if line.strip().startswith("git_refnames ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["refnames"] = mo.group(1) | ||
if line.strip().startswith("git_full ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["full"] = mo.group(1) | ||
if line.strip().startswith("git_date ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["date"] = mo.group(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
with
when opening file to ensure closure (ensure-file-closed
) - Iterate over files directly rather than using readlines() (
use-file-iterator
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
)
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)} |
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 list(), dict() or set() with comprehension [×3] (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator [×3] (
comprehension-to-generator
) - 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"] | ||
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, | ||
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] | ||
# if there isn't one, this yields HEX[-dirty] (no NUM) | ||
describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", | ||
"--always", "--long", | ||
"--match", "%s*" % tag_prefix], | ||
cwd=root) | ||
describe_out, rc = run_command( | ||
GITS, | ||
[ | ||
"describe", | ||
"--tags", | ||
"--dirty", | ||
"--always", | ||
"--long", | ||
"--match", | ||
f"{tag_prefix}*", | ||
], | ||
cwd=root, | ||
) |
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
else
branch (introduce-default-else
) - Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring
) - Merge dictionary assignment with declaration [×3] (
merge-dict-assign
) - 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
if "+" in pieces.get("closest-tag", ""): | ||
return "." | ||
return "+" | ||
return "." if "+" in pieces.get("closest-tag", "") else "+" |
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 plus_or_dot
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
status = webbrowser.open(url, location) | ||
return status | ||
return webbrowser.open(url, location) |
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 DesktopBot.browse
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(presses): | ||
for _ in range(presses): |
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 DesktopBot.tab
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for i in range(presses): | ||
for _ in range(presses): |
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 DesktopBot.enter
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
key_value = keys_map.get(key, None) | ||
if key_value: | ||
if key_value := keys_map.get(key, None): |
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 DesktopBot.type_keys_with_interval
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
dialog = find_window(self.app, waiting_time, **selectors) | ||
return dialog | ||
return find_window(self.app, waiting_time, **selectors) |
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 DesktopBot.find_app_window
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
element = find_element(self.app, from_parent_window, waiting_time, **selectors) | ||
return element | ||
return find_element(self.app, from_parent_window, waiting_time, **selectors) |
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 DesktopBot.find_app_element
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(clicks): | ||
for _ in range(clicks): |
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 _mouse_click
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
app = Application(backend=backend).connect(**connection_selectors) | ||
return app | ||
return Application(backend=backend).connect(**connection_selectors) |
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 connect
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if USE_FIND_MULTIPLE: | ||
# Using Find Parallel | ||
for index, row in df.iterrows(): | ||
for index, row in df.iterrows(): | ||
if USE_FIND_MULTIPLE: |
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 Bot.action
refactored with the following changes:
- Hoist for/while loops out of nested conditionals (
hoist-loop-from-if
)
This removes the following comments ( why? ):
# Using Find Serial Mode
# Using Find Parallel
Branch
main
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
main
branch, then run:Help us improve this pull request!