Skip to content
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

Slightly less ruff #526

Merged
merged 15 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,3 @@ jobs:
- uses: astral-sh/ruff-action@v1
with:
args: check --select I --fix --diff
ruff-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v1
with:
args: format --diff
6 changes: 2 additions & 4 deletions pyiron_workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
- GUI on top for code-lite/code-free visual scripting
"""

# deactivate: imported but unused
# flake8: noqa: F401

from ._version import get_versions

__version__ = get_versions()["version"]

# API

# User entry point
from pyiron_workflow.workflow import Workflow # ruff: isort: skip

# Node developer entry points
from pyiron_workflow.channels import NOT_DATA
from pyiron_workflow.find import (
Expand All @@ -62,4 +61,3 @@
TypeNotFoundError,
available_backends,
)
from pyiron_workflow.workflow import Workflow
13 changes: 1 addition & 12 deletions pyiron_workflow/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from __future__ import annotations

from abc import ABC
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from functools import lru_cache

from executorlib import Executor as ExecutorlibExecutor
from pyiron_snippets.dotdict import DotDict
Expand All @@ -32,7 +30,6 @@ class Creator(metaclass=Singleton):
"""

def __init__(self):

# Standard lib
self.ProcessPoolExecutor = ProcessPoolExecutor
self.ThreadPoolExecutor = ThreadPoolExecutor
Expand All @@ -44,35 +41,30 @@ def __init__(self):
self.function_node = function_node

@property
@lru_cache(maxsize=1)
def standard(self):
from pyiron_workflow.nodes import standard

return standard

@property
@lru_cache(maxsize=1)
def for_node(self):
from pyiron_workflow.nodes.for_loop import for_node

return for_node

@property
@lru_cache(maxsize=1)
def macro_node(self):
from pyiron_workflow.nodes.macro import macro_node

return macro_node

@property
@lru_cache(maxsize=1)
def Workflow(self):
from pyiron_workflow.workflow import Workflow

return Workflow

@property
@lru_cache(maxsize=1)
def meta(self):
from pyiron_workflow.nodes.transform import inputs_to_list, list_to_outputs

Expand All @@ -84,7 +76,6 @@ def meta(self):
)

@property
@lru_cache(maxsize=1)
def transformer(self):
from pyiron_workflow.nodes.transform import (
dataclass_node,
Expand Down Expand Up @@ -117,21 +108,19 @@ class Wrappers(metaclass=Singleton):
as_function_node = staticmethod(as_function_node)

@property
@lru_cache(maxsize=1)
def as_macro_node(self):
from pyiron_workflow.nodes.macro import as_macro_node

return as_macro_node

@property
@lru_cache(maxsize=1)
def as_dataclass_node(self):
from pyiron_workflow.nodes.transform import as_dataclass_node

return as_dataclass_node


class HasCreator(ABC):
class HasCreator:
"""
A mixin class for creator (including both class-like and decorator).
"""
Expand Down
2 changes: 1 addition & 1 deletion pyiron_workflow/mixin/has_interface_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pyiron_workflow.channels import Channel


class UsesState(ABC):
class UsesState:
"""
A mixin for any class using :meth:`__getstate__` or :meth:`__setstate__`.

Expand Down
2 changes: 1 addition & 1 deletion pyiron_workflow/mixin/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _readiness_error_message(self) -> str:

@staticmethod
def _parse_executor(
executor: StdLibExecutor | (callable[..., StdLibExecutor], tuple, dict)
executor: StdLibExecutor | (callable[..., StdLibExecutor], tuple, dict),
) -> StdLibExecutor:
"""
If you've already got an executor, you're done. But if you get callable and
Expand Down
1 change: 0 additions & 1 deletion pyiron_workflow/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ def _before_run(
self.inputs.fetch()

if self.use_cache and self.cache_hit: # Read and use cache

if self.parent is None and emit_ran_signal:
self.emit()
elif self.parent is not None:
Expand Down
1 change: 0 additions & 1 deletion pyiron_workflow/nodes/for_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ def _collect_output_as_dataframe(self, iter_maps):
self.dataframe.outputs.df.value_receiver = self.outputs.df

for n, channel_map in enumerate(iter_maps):

row_collector = self._build_row_collector_node(n)
for label, i in channel_map.items():
row_collector.inputs[label] = self.children[label][i]
Expand Down
2 changes: 1 addition & 1 deletion pyiron_workflow/nodes/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _build_inputs_preview(cls) -> dict[str, tuple[Any | None, Any | NOT_DATA]]:

@staticmethod
def hash_specification(
input_specification: list[str] | dict[str, tuple[Any | None, Any | NOT_DATA]]
input_specification: list[str] | dict[str, tuple[Any | None, Any | NOT_DATA]],
):
"""For generating unique subclass names."""

Expand Down
2 changes: 0 additions & 2 deletions pyiron_workflow/output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import ast
import inspect
import re
from functools import lru_cache
from textwrap import dedent


Expand Down Expand Up @@ -57,7 +56,6 @@ def node_return(self):
return None

@property
@lru_cache(maxsize=1)
def source(self):
return self.dedented_source_string.split("\n")[:-1]

Expand Down
1 change: 0 additions & 1 deletion pyiron_workflow/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def _parse_filename(self, node: Node | None, filename: str | Path | None = None)


class PickleStorage(StorageInterface):

_PICKLE = ".pckl"
_CLOUDPICKLE = ".cpckl"

Expand Down
4 changes: 2 additions & 2 deletions pyiron_workflow/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _set_run_connections_according_to_linear_dag(nodes: dict[str, Node]) -> list


def set_run_connections_according_to_linear_dag(
nodes: dict[str, Node]
nodes: dict[str, Node],
) -> tuple[list[tuple[SignalChannel, SignalChannel]], list[Node]]:
"""
Given a set of nodes that all have the same parent, have no upstream data
Expand Down Expand Up @@ -194,7 +194,7 @@ def _set_run_connections_according_to_dag(nodes: dict[str, Node]) -> list[Node]:


def set_run_connections_according_to_dag(
nodes: dict[str, Node]
nodes: dict[str, Node],
) -> tuple[list[tuple[SignalChannel, SignalChannel]], list[Node]]:
"""
Given a set of nodes that all have the same parent, have no upstream data
Expand Down
1 change: 0 additions & 1 deletion pyiron_workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def _after_node_setup(
autorun: bool = False,
**kwargs,
):

for node in args:
self.add_child(node)
super()._after_node_setup(
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ select = [
"I",
]
ignore = ["E501"] #ignore line-length violations

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore unused imports in init files -- we specify APIs this way
Comment on lines +88 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure if the generalization here is necessary, but I am ok with it.

2 changes: 1 addition & 1 deletion tests/benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
Timed tests to make sure critical components stay sufficiently efficient.
"""
"""
2 changes: 1 addition & 1 deletion tests/benchmark/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ def test_nothing(self):
self.assertTrue(True)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
Large and potentially slower tests to check how the pieces fit together.
"""
"""
34 changes: 12 additions & 22 deletions tests/integration/test_output_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ class TestOutputInjection(unittest.TestCase):
"""
I.e. the process of inserting new nodes on-the-fly by modifying output channels"
"""

def setUp(self) -> None:
self.wf = Workflow("injection")
self.int = Workflow.create.standard.UserInput(42, autorun=True)
self.list = Workflow.create.standard.UserInput(
list(range(10)), autorun=True
)
self.list = Workflow.create.standard.UserInput(list(range(10)), autorun=True)

def test_equality(self):
with self.subTest("True expressions"):
Expand Down Expand Up @@ -76,7 +75,7 @@ def test_algebra(self):
(x // 43, 0 * x),
((x + 1) % x, x + 1 - x),
(-x, -1 * x),
(+x, (-x)**2 / x),
(+x, (-x) ** 2 / x),
(x, abs(-x)),
]:
with self.subTest(f"{lhs.label} == {rhs.label}"):
Expand Down Expand Up @@ -127,29 +126,24 @@ def test_casts(self):
self.assertEqual(self.int.value, round(self.float).value)

def test_access(self):

self.dict = Workflow.create.standard.UserInput(
{"foo": 42}, autorun=True
)
self.dict = Workflow.create.standard.UserInput({"foo": 42}, autorun=True)

class Something:
myattr = 1

self.obj = Workflow.create.standard.UserInput(
Something(), autorun=True
)
self.obj = Workflow.create.standard.UserInput(Something(), autorun=True)

self.assertIsInstance(self.list[0].value, int)
self.assertEqual(5, self.list[:5].len().value)
self.assertEqual(4, self.list[1:5].len().value)
self.assertEqual(3, self.list[-3:].len().value)
self.assertEqual(2, self.list[1:5:2].len().value)

self.assertEqual(42, self.dict["foo"].value)
self.assertEqual(1, self.obj.myattr.value)

def test_chaining(self):
self.assertFalse((self.list[:self.int//42][0] != 0).value)
self.assertFalse((self.list[: self.int // 42][0] != 0).value)

def test_repeated_access_in_parent_scope(self):
wf = Workflow("output_manipulation")
Expand All @@ -162,13 +156,9 @@ def test_repeated_access_in_parent_scope(self):
self.assertIs(
a,
b,
msg="The same operation should re-access an existing node in the parent"
)
self.assertIsNot(
a,
c,
msg="Unique operations should yield unique nodes"
msg="The same operation should re-access an existing node in the parent",
)
self.assertIsNot(a, c, msg="Unique operations should yield unique nodes")

def test_without_parent(self):
d1 = self.list[5]
Expand All @@ -179,14 +169,14 @@ def test_without_parent(self):
d1,
d2,
msg="Outside the scope of a parent, we can't expect to re-access an "
"equivalent node"
"equivalent node",
)
self.assertEqual(
d1.label,
d2.label,
msg="Equivalent operations should nonetheless generate equal labels"
msg="Equivalent operations should nonetheless generate equal labels",
)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
11 changes: 5 additions & 6 deletions tests/integration/test_parallel_speedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class TestSpeedup(unittest.TestCase):
def test_speedup(self):

def make_workflow(label):
wf = Workflow(label)
wf.a = Workflow.create.standard.Sleep(t)
Expand Down Expand Up @@ -36,7 +35,7 @@ def make_workflow(label):
dt_cached_serial,
0.01 * t,
msg="The cache should be trivially fast compared to actual execution of "
"a sleep node"
"a sleep node",
)

wf = make_workflow("parallel")
Expand Down Expand Up @@ -65,13 +64,13 @@ def make_workflow(label):
0.5 * dt_serial,
msg=f"Expected the parallel solution to be at least 2x faster, but got"
f"{dt_parallel} and {dt_serial} for parallel and serial times, "
f"respectively"
f"respectively",
)
self.assertLess(
dt_cached_parallel,
0.01 * t,
msg="The cache should be trivially fast compared to actual execution of "
"a sleep node"
"a sleep node",
)

def test_executor_instructions(self):
Expand All @@ -95,9 +94,9 @@ def test_executor_instructions(self):
1.1 * t,
msg="Expected the sleeps to run in parallel with minimal overhead (since "
"it's just a thread pool executor) -- the advantage is that the "
"constructors should survive (de)serialization"
"constructors should survive (de)serialization",
)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
Loading
Loading