-
Notifications
You must be signed in to change notification settings - Fork 3
Add mkdir to as_path
#736
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
Add mkdir to as_path
#736
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #736 +/- ##
==========================================
+ Coverage 92.29% 92.74% +0.44%
==========================================
Files 34 34
Lines 3726 3694 -32
==========================================
- Hits 3439 3426 -13
+ Misses 287 268 -19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I thought this was a pretty neat implementation, but then with the following code I encountered a problem: from pyiron_workflow import Workflow
import uuid
from pathlib import Path
@Workflow.wrap.as_function_node
def generate_working_directory(path):
working_directory = Path(path) / Path(uuid.uuid4().hex)
working_directory.mkdir(exist_ok=True, parents=True)
return working_directory
@Workflow.wrap.as_function_node
def write_hello(working_directory, file_name="my_file.txt"):
full_path = Path(working_directory) / Path(file_name)
with open(full_path, "w") as f:
f.write("hello")
return full_path
@Workflow.wrap.as_macro_node
def example_macro(macro, file_name="my_file.txt"):
path = macro.as_path(mkdir=True)
macro.working_directory = generate_working_directory(path)
macro.message = write_hello(working_directory=macro.working_directory, file_name=file_name)
return macro.message
wf = Workflow("wf")
wf.macro = example_macro()This created a directory called |
…rticularly related to this PR, but I guess it's still good to cover it)
Indeed it did. Code decorated with I don't see anything wrong with the code you add in this PR, but I don't think it solves the problem you're trying to solve the way you want to solve it. I like from pyiron_workflow import Workflow
import uuid
from pathlib import Path
@Workflow.wrap.as_function_node
def generate_working_directory(path):
working_directory = Path(path) / Path(uuid.uuid4().hex)
working_directory.mkdir(exist_ok=True, parents=True)
return working_directory
@Workflow.wrap.as_function_node
def write_hello(working_directory, file_name="my_file.txt"):
full_path = Path(working_directory) / Path(file_name)
with open(full_path, "w") as f:
f.write("hello")
return full_path
@Workflow.wrap.as_macro_node
def example_macro(macro, path, file_name="my_file.txt"):
macro.working_directory = generate_working_directory(path)
macro.message = write_hello(working_directory=macro.working_directory, file_name=file_name)
return macro.message
wf = Workflow("wf")
wf.macro = example_macro()
wf.macro.inputs.path = wf.macro.as_path()
wf()
>>> {'macro__message': PosixPath('/.../wf/macro/7fabb56f040645bca06f139ec7bb09cf/my_file.txt')} |
|
ok then maybe the current one is pretty ok, so I made it now again ready for review |
liamhuber
left a comment
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.
@samwaseda there is absolutely nothing wrong with this, but I don't yet see how we will use it so my brain is waving a YAGNI yellow flags are waving.
ok let's see how people are gonna react, but I'm relatively sure that people will like to have a straightforward way to get a folder where they can freely store whatever they want. At the same time it was a bit confusing for me that |
Force delete with `delete_even_if_not_empty`
First item in the list of #735