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

Added a node to keep track of files #647

Merged
merged 2 commits into from
Nov 8, 2023
Merged

Conversation

pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Nov 7, 2023

This PR adds a FileNode that watches the filesystem for changes and gets marked as outdated if there is some change.

This is a step towards having auto-updatable plots, for example.

The way it works is that you simply initialize it with a path and then pass it to any argument that expects a path, and it will be like passing directly the path, except with the functionality of listening for updates.

from sisl.nodes import Node, FileNode
import time

# Write something to file
with open("testfile", "w") as f:
    f.write("HELLO")

# Create a FileNode
n = FileNode("testfile")

# Define a file reader node that prints the contents of the file
@Node.from_func
def print_contents(path):
    print("printing contents...")
    with open(path, "r") as f:
        print(f.read())

# And initialize it by passing the FileNode as an input
printer = print_contents(path=n)

print("---RUNNING NODE")

# Run the printer node
printer.get()

print("--- SET AUTOMATIC UPDATING")

# Now set it to automatically update on changes to upstream inputs
printer.context.update(lazy=False)

print("--- APPENDING TO FILE")

# Append to the file which will trigger the update.
with open("testfile", "a") as f:
    f.write("\nBYE")

# Give some time for the printer to react before exiting
time.sleep(1)
---RUNNING NODE
printing contents...
HELLO
--- SET AUTOMATIC UPDATING
--- APPENDING TO FILE
printing contents...
HELLO
BYE
  • Added tests for new/changed functions?
  • Ran isort . and black . at top-level

super().__init__(*args, **kwargs)
self.callback_obj = callback_obj

def _run_method(self, method_name, event):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
@zerothi
Copy link
Owner

zerothi commented Nov 7, 2023

Linting failed

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Attention: 48 lines in your changes are missing coverage. Please review.

Comparison is base (f7a3485) 87.73% compared to head (1d7229f) 87.65%.
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #647      +/-   ##
==========================================
- Coverage   87.73%   87.65%   -0.08%     
==========================================
  Files         362      364       +2     
  Lines       48436    48520      +84     
==========================================
+ Hits        42496    42532      +36     
- Misses       5940     5988      +48     
Files Coverage Δ
src/sisl/nodes/__init__.py 100.00% <100.00%> (ø)
src/sisl/nodes/tests/test_file_nodes.py 58.82% <58.82%> (ø)
src/sisl/nodes/file_nodes.py 37.87% <37.87%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zerothi zerothi merged commit 5339e68 into zerothi:main Nov 8, 2023
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants