Conversation
| 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.
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() | ||
| if sys.version_info[0] >= 3: | ||
| stdout = stdout.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.
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[1] | ||
| if line.strip().startswith("git_full ="): | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["full"] = mo[1] | ||
| if line.strip().startswith("git_date ="): | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["date"] = mo[1] |
There was a problem hiding this comment.
Function git_get_keywords refactored with the following changes:
- Use
withwhen 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) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups)
| 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.
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.
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 [×5] (
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
| cmds = {} | ||
|
|
||
| # we add "version" to both distutils and setuptools | ||
| from distutils.core import Command | ||
|
|
||
|
|
There was a problem hiding this comment.
Function get_cmdclass refactored with the following changes:
- Move assignment closer to its usage within a block [×2] (
move-assign-in-block) - Replace interpolated string formatting with f-string [×9] (
replace-interpolation-with-fstring) - Merge dictionary assignment with declaration [×2] (
merge-dict-assign)
This removes the following comments ( why? ):
# "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION
# nczeczulin reports that py2exe won't like the pep440-style string
# as FILEVERSION, but it can be used for PRODUCTVERSION, e.g.
# ...
# setup(console=[{
# "product_version": versioneer.get_version(),
| print(" creating %s" % cfg.versionfile_source) | ||
| print(f" creating {cfg.versionfile_source}") |
There was a problem hiding this comment.
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.
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.
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() | ||
| if sys.version_info[0] >= 3: | ||
| stdout = stdout.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.
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.
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[1] | ||
| if line.strip().startswith("git_full ="): | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["full"] = mo[1] | ||
| if line.strip().startswith("git_date ="): | ||
| if mo := re.search(r'=\s*"(.*)"', line): | ||
| keywords["date"] = mo[1] |
There was a problem hiding this comment.
Function git_get_keywords refactored with the following changes:
- Use
withwhen 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) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups)
| 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.
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.
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 [×5] (
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
| if "+" in pieces.get("closest-tag", ""): | ||
| return "." | ||
| return "+" | ||
| return "." if "+" in pieces.get("closest-tag", "") else "+" |
There was a problem hiding this comment.
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)
| DATA = numpy.fft.ifftshift( | ||
| numpy.fft.irfft( | ||
| numpy.fft.ifftshift(data, axes=(-1))), | ||
| axes=(-1)) * data.shape[-1] * delta_f | ||
|
|
||
| return DATA | ||
| return ( | ||
| numpy.fft.ifftshift( | ||
| numpy.fft.irfft(numpy.fft.ifftshift(data, axes=(-1))), axes=(-1) | ||
| ) | ||
| * data.shape[-1] | ||
| * delta_f | ||
| ) |
There was a problem hiding this comment.
Function irft refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| DATA = numpy.fft.fftshift( | ||
| numpy.fft.rfft2( | ||
| numpy.fft.fftshift(data, axes=(-1,-2)) | ||
| ), axes=(-1,-2) | ||
| )*delta**2 | ||
|
|
||
| return DATA | ||
| return ( | ||
| numpy.fft.fftshift( | ||
| numpy.fft.rfft2(numpy.fft.fftshift(data, axes=(-1, -2))), | ||
| axes=(-1, -2), | ||
| ) | ||
| * delta**2 | ||
| ) |
There was a problem hiding this comment.
Function rft2 refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| DATA = numpy.fft.ifftshift( | ||
| return ( | ||
| numpy.fft.ifftshift( | ||
| numpy.fft.irfft2( | ||
| numpy.fft.ifftshift(data, axes=(-1,-2)), | ||
| axes=(-1,-2) | ||
| ), | ||
| axes=(-1,-2)) * (N * delta_f)**2 | ||
| return DATA | ||
| numpy.fft.ifftshift(data, axes=(-1, -2)), axes=(-1, -2) | ||
| ), | ||
| axes=(-1, -2), | ||
| ) | ||
| * (N * delta_f) ** 2 | ||
| ) |
There was a problem hiding this comment.
Function irft2 refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
||
| #If array is complex must do 2 interpolations | ||
| if array.dtype==numpy.complex64 or array.dtype==numpy.complex128: | ||
| if array.dtype in [numpy.complex64, numpy.complex128]: |
There was a problem hiding this comment.
Function zoom refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if array.dtype==numpy.complex64 or array.dtype==numpy.complex128: | ||
| if array.dtype in [numpy.complex64, numpy.complex128]: | ||
| realInterpObj = RectBivariateSpline( | ||
| numpy.arange(array.shape[0]), numpy.arange(array.shape[1]), | ||
| array.real, kx=order, ky=order) | ||
| imagInterpObj = RectBivariateSpline( | ||
| numpy.arange(array.shape[0]), numpy.arange(array.shape[1]), | ||
| array.imag, kx=order, ky=order) | ||
|
|
||
| return (realInterpObj(coordsY,coordsX) | ||
| + 1j*imagInterpObj(coordsY,coordsX)) | ||
|
|
There was a problem hiding this comment.
Function zoom_rbs refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| ''' | ||
| shape = numpy.array( data.shape ) | ||
|
|
There was a problem hiding this comment.
Function binImgs refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| #Compute propagated field | ||
| outputComplexAmp = Q3 * fouriertransform.ift2( | ||
| Q2 * fouriertransform.ft2(Q1 * inputComplexAmp/mag,inputSpacing), df1) | ||
| return outputComplexAmp | ||
| return Q3 * fouriertransform.ift2( | ||
| Q2 * fouriertransform.ft2(Q1 * inputComplexAmp / mag, inputSpacing), | ||
| df1, | ||
| ) |
There was a problem hiding this comment.
Function angularSpectrum refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
#Compute propagated field
| Uout = A*B*C | ||
|
|
||
| return Uout | ||
| return A*B*C |
There was a problem hiding this comment.
Function oneStepFresnel refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| Uout = A*B*C | ||
|
|
||
| return Uout | ||
| return A*B*C |
There was a problem hiding this comment.
Function twoStepFresnel refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| numpy.exp(1j * k / (2 * f) * (x2**2 + y2**2)) | ||
| / (1j * wvl * f) | ||
| * fouriertransform.ft2(Uin, d1) | ||
| ) |
There was a problem hiding this comment.
Function lensAgainst refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
#phase factor inside cancelled by the phase of the lens
#Evaluate the Fresnel-Kirchoff integral but with the quadratic
| phi = np.transpose(rebin(np.reshape(phi1, (npp, 1)), (npp, nr))) | ||
| return phi | ||
| return np.transpose(rebin(np.reshape(phi1, (npp, 1)), (npp, nr))) |
There was a problem hiding this comment.
Function polang refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| geom = {'px': px, 'py': py, 'cr': cr, 'cp': cp, | ||
| 'pincx': pincx, 'pincy': pincy, 'pincw': pincw, | ||
| 'ap': ap, 'ncp': ncp, 'ncmar': ncmar} | ||
|
|
||
| return geom | ||
| return { | ||
| 'px': px, | ||
| 'py': py, | ||
| 'cr': cr, | ||
| 'cp': cp, | ||
| 'pincx': pincx, | ||
| 'pincy': pincy, | ||
| 'pincw': pincw, | ||
| 'ap': ap, | ||
| 'ncp': ncp, | ||
| 'ncmar': ncmar, | ||
| } |
There was a problem hiding this comment.
Function pcgeom refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| assert (stf == 'kolmogorov') or (stf == 'kolstf') or (stf == 'vonKarman') \ | ||
| or (stf == 'karman') or (stf == 'vk') | ||
| assert stf in ['kolmogorov', 'kolstf', 'vonKarman', 'karman', 'vk'] |
There was a problem hiding this comment.
Function make_kl refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| else: | ||
| if m > 0: # j is even | ||
| Z = numpy.sqrt(2*(n+1)) * zernikeRadialFunc(n, m, R) * numpy.cos((m*theta)+rot) | ||
| else: #i is odd | ||
| m = abs(m) | ||
| Z = numpy.sqrt(2*(n+1)) * zernikeRadialFunc(n, m, R) * numpy.sin((m*theta)+rot) | ||
| elif m > 0: # j is even | ||
| Z = numpy.sqrt(2*(n+1)) * zernikeRadialFunc(n, m, R) * numpy.cos((m*theta)+rot) | ||
| else: #i is odd | ||
| m = abs(m) | ||
| Z = numpy.sqrt(2*(n+1)) * zernikeRadialFunc(n, m, R) * numpy.sin((m*theta)+rot) |
There was a problem hiding this comment.
Function zernike_nm refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| if j%2==0: | ||
| s=1 | ||
| else: | ||
| s=-1 | ||
| s = 1 if j%2==0 else -1 |
There was a problem hiding this comment.
Function zernIndex refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
aa70c0a to
b7c4ac4
Compare
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!