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

fix: Issue #1253 (problems editing Jupyter Notebooks) #1255

Merged
merged 2 commits into from Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions snakemake/notebook.py
Expand Up @@ -42,12 +42,12 @@ def draft(self, listen):

nb["cells"].append(nbformat.v4.new_code_cell("# start coding here"))

os.makedirs(os.path.dirname(self.local_path), exist_ok=True)
os.makedirs(os.path.dirname(str(self.local_path)), exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use self.local_path.get_path_or_uri() here? That is more idiomatic with the new API.

Copy link
Contributor

Choose a reason for hiding this comment

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

And in all str() occurrences below as well.


with open(self.local_path, "wb") as out:
with open(str(self.local_path), "wb") as out:
out.write(nbformat.writes(nb).encode())

self.source = open(self.local_path).read()
self.source = open(str(self.local_path)).read()

self.evaluate(edit=listen)

Expand Down Expand Up @@ -101,7 +101,7 @@ def execute_script(self, fname, edit=None):
for cell in nb["cells"]:
cell["outputs"] = []

nbformat.write(nb, self.local_path)
nbformat.write(nb, str(self.local_path))

def insert_preamble_cell(self, preamble, notebook):
import nbformat
Expand Down
2 changes: 1 addition & 1 deletion snakemake/script.py
Expand Up @@ -393,7 +393,7 @@ def evaluate(self, edit=False):

@property
def local_path(self):
path = self.path[7:]
path = str(self.path)#[7:]
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, I'd rather rely on the SourceFile methods for checking whether the path is absolute or not and so on.

if not os.path.isabs(path):
return smart_join(self.basedir, path)
return path
Expand Down