-
Notifications
You must be signed in to change notification settings - Fork 24
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
formatting python via black #792
Changes from 1 commit
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||||||
import math | ||||||||||||||||||
import numpy as np | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def all_iterables(*args): | ||||||||||||||||||
""" | ||||||||||||||||||
return true if all arguments are either lists or tuples | ||||||||||||||||||
|
@@ -12,7 +13,9 @@ def none_iterable(*args): | |||||||||||||||||
""" | ||||||||||||||||||
return true if none of the arguments are either lists or tuples | ||||||||||||||||||
""" | ||||||||||||||||||
Comment on lines
13
to
15
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. The docstring for - 14:
- """
- 15:
- return true if none of the arguments are either lists or tuples
+ 14: """
+ 15: return true if none of the arguments are either lists or tuples
+ 16: """ Committable suggestion
Suggested change
|
||||||||||||||||||
return all([not isinstance(arg, list) and not isinstance(arg, tuple) for arg in args]) | ||||||||||||||||||
return all( | ||||||||||||||||||
[not isinstance(arg, list) and not isinstance(arg, tuple) for arg in args] | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def equal_size(*args): | ||||||||||||||||||
|
@@ -51,7 +54,7 @@ def is_nd_array(arg): | |||||||||||||||||
return isinstance(arg, np.ndarray) | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def np_array_ify(arg, size = 1): | ||||||||||||||||||
def np_array_ify(arg, size=1): | ||||||||||||||||||
if is_scalar(arg): | ||||||||||||||||||
return np.asarray([arg] * size) | ||||||||||||||||||
if not is_nd_array(arg): | ||||||||||||||||||
|
@@ -62,7 +65,7 @@ def np_array_ify(arg, size = 1): | |||||||||||||||||
refinement_ratio = 2 | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def not_in_keywords_list(kwd_list,**kwargs): | ||||||||||||||||||
def not_in_keywords_list(kwd_list, **kwargs): | ||||||||||||||||||
""" | ||||||||||||||||||
return the list of kwargs keys that are not in 'kwd_list' | ||||||||||||||||||
""" | ||||||||||||||||||
Comment on lines
+68
to
71
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. The docstring for - 69:
- """
- 70:
- return the list of kwargs keys that are not in 'kwd_list'
+ 69: """
+ 70: return the list of kwargs keys that are not in 'kwd_list'
+ 71: """ Committable suggestion
Suggested change
|
||||||||||||||||||
|
@@ -76,23 +79,26 @@ def check_mandatory_keywords(mandatory_kwd_list, **kwargs): | |||||||||||||||||
""" | ||||||||||||||||||
return those of mandatory_kwd_list not found in the kwargs keys | ||||||||||||||||||
""" | ||||||||||||||||||
Comment on lines
79
to
81
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. The docstring for - 80:
- """
- 81:
- return those of mandatory_kwd_list not found in the kwargs keys
+ 80: """
+ 81: return those of mandatory_kwd_list not found in the kwargs keys
+ 82: """ Committable suggestion
Suggested change
|
||||||||||||||||||
keys = [k for k in kwargs.keys()] | ||||||||||||||||||
keys = [k for k in kwargs.keys()] | ||||||||||||||||||
check = [(mk, mk in keys) for mk in mandatory_kwd_list] | ||||||||||||||||||
return [mk[0] for mk in check if mk[1] is False] | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def fp_equal(a, b, atol=1e-6): | ||||||||||||||||||
return math.isclose(a, b, abs_tol=atol) | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def fp_less_equal(a, b, atol=1e-6): | ||||||||||||||||||
return fp_equal(a, b, atol=atol) or a < b | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def fp_gtr_equal(a, b, atol=1e-6): | ||||||||||||||||||
return fp_equal(a, b, atol=atol) or a > b | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
class FloatingPoint_comparator: | ||||||||||||||||||
def __init__(self, fp, atol=1e-6): | ||||||||||||||||||
self.fp = fp | ||||||||||||||||||
self.fp = fp | ||||||||||||||||||
self.atol = atol | ||||||||||||||||||
|
||||||||||||||||||
def __eq__(self, other): | ||||||||||||||||||
|
@@ -120,27 +126,33 @@ def run_cli_cmd(cmd, shell=True, capture_output=True, check=False, print_cmd=Fal | |||||||||||||||||
https://docs.python.org/3/library/subprocess.html | ||||||||||||||||||
""" | ||||||||||||||||||
import subprocess | ||||||||||||||||||
|
||||||||||||||||||
if print_cmd: | ||||||||||||||||||
print(f"running: {cmd}") | ||||||||||||||||||
try: | ||||||||||||||||||
return subprocess.run(cmd, shell=shell, capture_output=capture_output, check=check) | ||||||||||||||||||
except subprocess.CalledProcessError as e: # only triggers on failure if check=True | ||||||||||||||||||
return subprocess.run( | ||||||||||||||||||
cmd, shell=shell, capture_output=capture_output, check=check | ||||||||||||||||||
) | ||||||||||||||||||
except subprocess.CalledProcessError as e: # only triggers on failure if check=True | ||||||||||||||||||
raise RuntimeError(decode_bytes(e.stderr)) | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def git_hashes(N=1): | ||||||||||||||||||
return decode_bytes(run_cli_cmd(f"git log -{N} --pretty=format:%h").stdout).splitlines() | ||||||||||||||||||
return decode_bytes( | ||||||||||||||||||
run_cli_cmd(f"git log -{N} --pretty=format:%h").stdout | ||||||||||||||||||
).splitlines() | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def top_git_hash(): | ||||||||||||||||||
hashes = git_hashes(1) | ||||||||||||||||||
if len(hashes) > 0: | ||||||||||||||||||
return hashes[0] | ||||||||||||||||||
return "master" # github actions fails? | ||||||||||||||||||
return "master" # github actions fails? | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def print_trace(): | ||||||||||||||||||
import sys, traceback | ||||||||||||||||||
|
||||||||||||||||||
_, _, tb = sys.exc_info() | ||||||||||||||||||
traceback.print_tb(tb) | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -158,4 +170,3 @@ def deep_copy(item, memo, excludes=[]): | |||||||||||||||||
else: | ||||||||||||||||||
setattr(that, key, deepcopy(value, memo)) | ||||||||||||||||||
return that | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
# continue to use override if set | ||
_cpp_lib_override = None | ||
|
||
|
||
def cpp_lib(override=None): | ||
import importlib | ||
|
||
|
@@ -21,12 +21,14 @@ def cpp_lib(override=None): | |
|
||
def cpp_etc_lib(): | ||
import importlib | ||
|
||
return importlib.import_module("pybindlibs.cpp_etc") | ||
Comment on lines
22
to
+24
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. The |
||
|
||
|
||
def splitter_type(dim, interp, n_particles): | ||
return getattr(cpp_lib(), f"Splitter_{dim}_{interp}_{n_particles}") | ||
|
||
|
||
def create_splitter(dim, interp, n_particles): | ||
return splitter_type(dim, interp, n_particles)() | ||
|
||
|
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.
The docstring for
all_iterables
should be inside the function body for proper association with the function.Committable suggestion