-
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 develop branch #1
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from taipy.gui import Gui | ||
|
||
# Random data set | ||
data = [random.random() for i in range(500)] | ||
data = [random.random() for _ in range(500)] | ||
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. Lines
|
||
|
||
options = { | ||
# Enable the cumulative histogram | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from taipy.gui import Gui | ||
|
||
# Random data set | ||
data = {"Count": [random.random() for i in range(100)]} | ||
data = {"Count": [random.random() for _ in range(100)]} | ||
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. Lines
|
||
|
||
page = """ | ||
# Histograms - Horizontal | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from taipy.gui import Gui | ||
|
||
# Random set of 100 samples | ||
samples = {"x": [random.gauss() for i in range(100)]} | ||
samples = {"x": [random.gauss() for _ in range(100)]} | ||
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. Lines
|
||
|
||
# Use the same data for both traces | ||
data = [samples, samples] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from taipy.gui import Gui | ||
|
||
# Random data set | ||
data = [random.random() for i in range(100)] | ||
data = [random.random() for _ in range(100)] | ||
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. Lines
|
||
|
||
# Normalize to show bin probabilities | ||
options = {"histnorm": "probability"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,10 @@ | |
from taipy.gui import Gui | ||
|
||
# Data set made of two series of random numbers | ||
data = [{"x": [random.random() + 1 for i in range(100)]}, {"x": [random.random() + 1.1 for i in range(100)]}] | ||
data = [ | ||
{"x": [random.random() + 1 for _ in range(100)]}, | ||
{"x": [random.random() + 1.1 for _ in range(100)]}, | ||
] | ||
Comment on lines
-21
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. Lines
|
||
|
||
options = [ | ||
# First data set displayed as semi-transparent, green bars | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from taipy import Gui | ||
|
||
# Random data set | ||
data = [random.gauss(0, 5) for i in range(1000)] | ||
data = [random.gauss(0, 5) for _ in range(1000)] | ||
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. Lines
|
||
|
||
page = """ | ||
# Histogram - Simple | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,10 @@ | |
from taipy.gui import Gui | ||
|
||
# Data set made of two series of random numbers | ||
data = {"A": [random.random() for i in range(200)], "B": [random.random() for i in range(200)]} | ||
data = { | ||
"A": [random.random() for _ in range(200)], | ||
"B": [random.random() for _ in range(200)], | ||
} | ||
Comment on lines
-21
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. Lines
|
||
|
||
# Names of the two traces | ||
names = ["A samples", "B samples"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,10 @@ | |
# Data set: the first 10 elements of the Fibonacci sequence | ||
n_numbers = 10 | ||
fibonacci = [0, 1] | ||
for i in range(2, n_numbers): | ||
fibonacci.append(fibonacci[i - 1] + fibonacci[i - 2]) | ||
|
||
data = {"index": [i for i in range(1, n_numbers + 1)], "fibonacci": fibonacci} | ||
fibonacci.extend( | ||
fibonacci[i - 1] + fibonacci[i - 2] for i in range(2, n_numbers) | ||
) | ||
data = {"index": list(range(1, n_numbers + 1)), "fibonacci": fibonacci} | ||
Comment on lines
-21
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. Lines
|
||
|
||
page = """ | ||
# TreeMap - Simple | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,11 @@ def func_with_doc(section, attribute_name, default, configuration_methods, add_t | |
|
||
for exposed_configuration_method, configuration_method in configuration_methods: | ||
annotation = " @staticmethod\n" | ||
sign = " def " + exposed_configuration_method + str(signature(configuration_method)) + ":\n" | ||
doc = ' """' + configuration_method.__doc__ + '"""\n' | ||
sign = ( | ||
f" def {exposed_configuration_method}{str(signature(configuration_method))}" | ||
+ ":\n" | ||
) | ||
doc = f' """{configuration_method.__doc__}' + '"""\n' | ||
Comment on lines
-46
to
+50
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
|
||
content = " pass\n\n" | ||
f.write(annotation + sign + doc + content) | ||
return func(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,11 +68,9 @@ def __update_sections(self, entity_config, other_entity_configs): | |
entity_config[self.DEFAULT_KEY] = other_entity_configs[self.DEFAULT_KEY] | ||
for cfg_id, sub_config in other_entity_configs.items(): | ||
if cfg_id != self.DEFAULT_KEY: | ||
if cfg_id in entity_config: | ||
entity_config[cfg_id]._update(sub_config._to_dict(), entity_config.get(self.DEFAULT_KEY)) | ||
else: | ||
if cfg_id not in entity_config: | ||
entity_config[cfg_id] = copy(sub_config) | ||
entity_config[cfg_id]._update(sub_config._to_dict(), entity_config.get(self.DEFAULT_KEY)) | ||
entity_config[cfg_id]._update(sub_config._to_dict(), entity_config.get(self.DEFAULT_KEY)) | ||
Comment on lines
-71
to
+73
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
|
||
self.__point_nested_section_to_self(sub_config) | ||
|
||
def __point_nested_section_to_self(self, section): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,25 +56,25 @@ def _stringify(cls, as_dict): | |
if as_dict is None: | ||
return None | ||
if isinstance(as_dict, Section): | ||
return as_dict.id + ":SECTION" | ||
return f"{as_dict.id}:SECTION" | ||
if isinstance(as_dict, Scope): | ||
return as_dict.name + ":SCOPE" | ||
return f"{as_dict.name}:SCOPE" | ||
if isinstance(as_dict, Frequency): | ||
return as_dict.name + ":FREQUENCY" | ||
return f"{as_dict.name}:FREQUENCY" | ||
if isinstance(as_dict, bool): | ||
return str(as_dict) + ":bool" | ||
return f"{str(as_dict)}:bool" | ||
if isinstance(as_dict, int): | ||
return str(as_dict) + ":int" | ||
return f"{str(as_dict)}:int" | ||
if isinstance(as_dict, float): | ||
return str(as_dict) + ":float" | ||
return f"{str(as_dict)}:float" | ||
if isinstance(as_dict, datetime): | ||
return as_dict.isoformat() + ":datetime" | ||
return f"{as_dict.isoformat()}:datetime" | ||
if isinstance(as_dict, timedelta): | ||
return cls._timedelta_to_str(as_dict) + ":timedelta" | ||
return f"{cls._timedelta_to_str(as_dict)}:timedelta" | ||
if inspect.isfunction(as_dict) or isinstance(as_dict, types.BuiltinFunctionType): | ||
return as_dict.__module__ + "." + as_dict.__name__ + ":function" | ||
return f"{as_dict.__module__}.{as_dict.__name__}:function" | ||
if inspect.isclass(as_dict): | ||
return as_dict.__module__ + "." + as_dict.__qualname__ + ":class" | ||
return f"{as_dict.__module__}.{as_dict.__qualname__}:class" | ||
Comment on lines
-59
to
+77
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
|
||
if isinstance(as_dict, dict): | ||
return {str(key): cls._stringify(val) for key, val in as_dict.items()} | ||
if isinstance(as_dict, list): | ||
|
@@ -115,8 +115,7 @@ def _pythonify(cls, val): | |
r"^(.+):(\bbool\b|\bstr\b|\bint\b|\bfloat\b|\bdatetime\b||\btimedelta\b|" | ||
r"\bfunction\b|\bclass\b|\bSCOPE\b|\bFREQUENCY\b|\bSECTION\b)?$" | ||
) | ||
match = re.fullmatch(TYPE_PATTERN, str(val)) | ||
if match: | ||
if match := re.fullmatch(TYPE_PATTERN, str(val)): | ||
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
|
||
actual_val = match.group(1) | ||
dynamic_type = match.group(2) | ||
if dynamic_type == "SECTION": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,17 +51,16 @@ def _check_children( | |
config_value, | ||
f"{config_key} field of {parent_config_class.__name__} `{config_id}` is empty.", | ||
) | ||
else: | ||
if not ( | ||
(isinstance(config_value, List) or isinstance(config_value, Set)) | ||
and all(map(lambda x: isinstance(x, child_config_class), config_value)) | ||
): | ||
self._error( | ||
config_key, | ||
config_value, | ||
f"{config_key} field of {parent_config_class.__name__} `{config_id}` must be populated with a list " | ||
f"of {child_config_class.__name__} objects.", | ||
) | ||
elif not ( | ||
(isinstance(config_value, (List, Set))) | ||
and all(map(lambda x: isinstance(x, child_config_class), config_value)) | ||
): | ||
self._error( | ||
config_key, | ||
config_value, | ||
f"{config_key} field of {parent_config_class.__name__} `{config_id}` must be populated with a list " | ||
f"of {child_config_class.__name__} objects.", | ||
) | ||
Comment on lines
-54
to
+63
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 _check_existing_config_id(self, config): | ||
if not config.id: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ def _check_if_is_blocking(*args, **kwargs): | |
" modifying the Configuration. For more information, please refer to:" | ||
" https://docs.taipy.io/en/latest/manuals/running_services/#running-core." | ||
) | ||
cls.__logger.error("ConfigurationUpdateBlocked: " + error_message) | ||
cls.__logger.error(f"ConfigurationUpdateBlocked: {error_message}") | ||
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 ConfigurationUpdateBlocked(error_message) | ||
|
||
return f(*args, **kwargs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,7 @@ def _replace_templates(cls, template, type=str, required=True, default=None): | |
def _replace_template(cls, template, type, required, default): | ||
if "ENV" not in str(template): | ||
return template | ||
match = re.fullmatch(cls._PATTERN, str(template)) | ||
if match: | ||
if match := re.fullmatch(cls._PATTERN, str(template)): | ||
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
|
||
var = match.group(1) | ||
dynamic_type = match.group(3) | ||
val = os.environ.get(var) | ||
|
@@ -77,7 +76,7 @@ def _to_bool(val: str) -> bool: | |
possible_values = ["true", "false"] | ||
if str.lower(val) not in possible_values: | ||
raise InconsistentEnvVariableError("{val} is not a Boolean.") | ||
return str.lower(val) == "true" or not (str.lower(val) == "false") | ||
return str.lower(val) == "true" or str.lower(val) != "false" | ||
Comment on lines
-80
to
+79
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
|
||
|
||
@staticmethod | ||
def _to_int(val: str) -> int: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,11 +178,10 @@ def _register_default(cls, default_section: Section): | |
cls._default_config._unique_sections[default_section.name]._update(default_section._to_dict()) | ||
else: | ||
cls._default_config._unique_sections[default_section.name] = default_section | ||
elif def_sections := cls._default_config._sections.get(default_section.name, None): | ||
def_sections[default_section.id] = default_section | ||
else: | ||
if def_sections := cls._default_config._sections.get(default_section.name, None): | ||
def_sections[default_section.id] = default_section | ||
else: | ||
cls._default_config._sections[default_section.name] = {default_section.id: default_section} | ||
cls._default_config._sections[default_section.name] = {default_section.id: default_section} | ||
Comment on lines
+181
to
+184
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
|
||
cls._serializer._section_class[default_section.name] = default_section.__class__ # type: ignore | ||
cls.__json_serializer._section_class[default_section.name] = default_section.__class__ # type: ignore | ||
cls._compile_configs() | ||
|
@@ -195,14 +194,13 @@ def _register(cls, section): | |
cls._python_config._unique_sections[section.name]._update(section._to_dict()) | ||
else: | ||
cls._python_config._unique_sections[section.name] = section | ||
else: | ||
if sections := cls._python_config._sections.get(section.name, None): | ||
if sections.get(section.id, None): | ||
sections[section.id]._update(section._to_dict()) | ||
else: | ||
sections[section.id] = section | ||
elif sections := cls._python_config._sections.get(section.name, None): | ||
if sections.get(section.id, None): | ||
sections[section.id]._update(section._to_dict()) | ||
else: | ||
cls._python_config._sections[section.name] = {section.id: section} | ||
sections[section.id] = section | ||
else: | ||
cls._python_config._sections[section.name] = {section.id: section} | ||
Comment on lines
+197
to
+203
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
|
||
cls._serializer._section_class[section.name] = section.__class__ | ||
cls.__json_serializer._section_class[section.name] = section.__class__ | ||
cls._compile_configs() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,27 +32,32 @@ def _append_to_backup_file(new_file_path: str): | |
|
||
|
||
def _remove_from_backup_file(to_remove_file_path: str): | ||
if preserve_file_path := os.getenv(__BACKUP_FILE_PATH_ENVIRONMENT_VARIABLE_NAME, None): | ||
storage_folder = os.path.abspath(Config.core.storage_folder) + os.sep | ||
if not os.path.abspath(to_remove_file_path).startswith(storage_folder): | ||
try: | ||
with open(preserve_file_path, "r+") as f: | ||
old_backup = f.read() | ||
to_remove_file_path = to_remove_file_path + "\n" | ||
|
||
# To avoid removing the file path of different data nodes that are pointing | ||
# to the same file. We will only replace the file path only once. | ||
if old_backup.startswith(to_remove_file_path): | ||
new_backup = old_backup.replace(to_remove_file_path, "", 1) | ||
else: | ||
new_backup = old_backup.replace("\n" + to_remove_file_path, "\n", 1) | ||
|
||
if new_backup is not old_backup: | ||
f.seek(0) | ||
f.write(new_backup) | ||
f.truncate() | ||
except Exception: | ||
pass | ||
if not ( | ||
preserve_file_path := os.getenv( | ||
__BACKUP_FILE_PATH_ENVIRONMENT_VARIABLE_NAME, None | ||
) | ||
): | ||
return | ||
storage_folder = os.path.abspath(Config.core.storage_folder) + os.sep | ||
if not os.path.abspath(to_remove_file_path).startswith(storage_folder): | ||
try: | ||
with open(preserve_file_path, "r+") as f: | ||
old_backup = f.read() | ||
to_remove_file_path += "\n" | ||
|
||
# To avoid removing the file path of different data nodes that are pointing | ||
# to the same file. We will only replace the file path only once. | ||
if old_backup.startswith(to_remove_file_path): | ||
new_backup = old_backup.replace(to_remove_file_path, "", 1) | ||
else: | ||
new_backup = old_backup.replace("\n" + to_remove_file_path, "\n", 1) | ||
|
||
if new_backup is not old_backup: | ||
f.seek(0) | ||
f.write(new_backup) | ||
f.truncate() | ||
except Exception: | ||
pass | ||
Comment on lines
-35
to
+60
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 _replace_in_backup_file(old_file_path: str, new_file_path: str): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,6 @@ def parse_arguments(cls): | |
@classmethod | ||
def __add_taipy_prefix(cls, key: str): | ||
if key.startswith("--no-"): | ||
return key[:5] + "taipy-" + key[5:] | ||
return f"{key[:5]}taipy-{key[5:]}" | ||
|
||
return key[:2] + "taipy-" + key[2:] | ||
return f"{key[:2]}taipy-{key[2:]}" | ||
Comment on lines
-116
to
+118
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
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ def __init__(self, src: _Node, dest: _Node): | |
|
||
class _DAG: | ||
def __init__(self, dag: nx.DiGraph): | ||
self._sorted_nodes = list(nodes for nodes in nx.topological_generations(dag)) | ||
self._sorted_nodes = list(nx.topological_generations(dag)) | ||
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
|
||
self._length, self._width = self.__compute_size() | ||
self._grid_length, self._grid_width = self.__compute_grid_size() | ||
self._nodes = self.__compute_nodes() | ||
|
@@ -54,7 +54,7 @@ def edges(self) -> List[_Edge]: | |
return self._edges | ||
|
||
def __compute_size(self) -> Tuple[int, int]: | ||
return len(self._sorted_nodes), max([len(i) for i in self._sorted_nodes]) | ||
return len(self._sorted_nodes), max(len(i) for i in self._sorted_nodes) | ||
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 __compute_grid_size(self) -> Tuple[int, int]: | ||
if self._width == 1: | ||
|
@@ -65,8 +65,7 @@ def __compute_grid_size(self) -> Tuple[int, int]: | |
|
||
def __compute_nodes(self) -> Dict[str, _Node]: | ||
nodes = {} | ||
x = 0 | ||
for same_lvl_nodes in self._sorted_nodes: | ||
for x, same_lvl_nodes in enumerate(self._sorted_nodes): | ||
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
|
||
lcl_wdt = len(same_lvl_nodes) | ||
is_max = lcl_wdt != self.width | ||
if self.width != 1: | ||
|
@@ -77,14 +76,13 @@ def __compute_nodes(self) -> Dict[str, _Node]: | |
for node in same_lvl_nodes: | ||
y += y_incr | ||
nodes[node.id] = _Node(node, x, y) | ||
x += 1 | ||
return nodes | ||
|
||
def __compute_edges(self, dag) -> List[_Edge]: | ||
edges = [] | ||
for edge in dag.edges(): | ||
edges.append(_Edge(self.nodes[edge[0].id], self.nodes[edge[1].id])) | ||
return edges | ||
return [ | ||
_Edge(self.nodes[edge[0].id], self.nodes[edge[1].id]) | ||
for edge in dag.edges() | ||
] | ||
Comment on lines
-84
to
+85
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
|
||
|
||
@staticmethod | ||
def __lcm(*integers) -> int: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ class _Entity: | |
|
||
def __enter__(self): | ||
self._is_in_context = True | ||
self._in_context_attributes_changed_collector = list() | ||
self._in_context_attributes_changed_collector = [] | ||
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 self | ||
|
||
def __exit__(self, exc_type, exc_value, exc_traceback): | ||
|
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
25-40
refactored with the following changes:for-index-underscore
)This removes the following comments ( why? ):