Octoframes / jupyter_capture_output

A cellmagic that captures celloutput such as text, image or video to files.
https://octoframes.github.io/jupyter_capture_output/
MIT License
31 stars 0 forks source link

Can't pass a proper path to --path #6

Closed 25shmeckles closed 1 year ago

25shmeckles commented 2 years ago

The following doesn't work.

path = "./log/mylog.txt" 
%%capture_text --path $path

It doesn't throw any error. It simply won't write any file. I have the impression that it has some issues with relative paths.

If I pass only the file namepath ="mylog.txt", it works as expected, and it writes a file in the same folder of the running notebook. However, I want to write the log in another folder. Of course, the folder exists. This is my tree:

.
├── Untitled.ipynb
├── log
├── tmp
└── tools.py
kolibril13 commented 2 years ago

This is a feature I did not implement yet, currently the path is passed only like this: https://github.com/Octoframes/jupyter_capture_output/blob/0fbade42e93f7915c310728cde9b5ac46776574d/jupyter_capture_output/co_cellmagic.py#L79 A starting point for an implementation will be this:

if path.exists():
    print("Path is there")
else: 
    print("Path will be created")
    path.mkdir()

I don't have time right now to think this completely through, but in end September I will have more free time to have a look on this.

25shmeckles commented 2 years ago

My problem is not about creating the directory. The directory exists. The problem is that the output gets written correctly to a file in the current working directory, but somehow it doesn't work if the path is pointing somewhere else.

So, with %%capture_text --path mylog.txt works but %%capture_text --path ./log/mylog.txt doesn't. The path exists, of course.

kolibril13 commented 2 years ago

okay, I see! I am planing to make a proper implementation of the path integration, probably end of September.

kolibril13 commented 1 year ago

@25shmeckles, I've just implemented a proper path system with pathlib, could you test this again with the latest jupyter_capture_output version (that is version 0.0.7) ? Here is a notebook that can be used for testing: https://github.com/Octoframes/jupyter_capture_output/blob/main/cap_example_notebook.ipynb

25shmeckles commented 1 year ago

It looks ok. It saves the log in the proper folder now, and it creates the folder structure if it doesn't exist. Good job!

kolibril13 commented 1 year ago

Glad to hear this. I am closing this issue now.