Skip to content

Commit

Permalink
use pathlib instead of os
Browse files Browse the repository at this point in the history
for some reason we need to cast these to str to make it work on some systems
  • Loading branch information
DaniBodor committed Feb 29, 2024
1 parent af86ade commit e51f1a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 3 additions & 4 deletions eit_dash/callbacks/load_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_parent_directory(stored_cwd, n_clicks, currentdir):
triggered_id = ctx.triggered_id
if triggered_id == ids.STORED_CWD:
return stored_cwd
return Path(currentdir).parent.as_posix()
return str(Path(currentdir).parent)


@callback(Output(ids.CWD_FILES, "children"), Input(ids.CWD, "children"))
Expand All @@ -227,16 +227,15 @@ def list_cwd_files(cwd):
files = sorted(os.listdir(path), key=str.lower)
for i, file in enumerate(files):
filepath = Path(file)

full_path = os.path.join(cwd, filepath.as_posix())
full_path = Path(cwd) / filepath

is_dir = Path(full_path).is_dir()
link = html.A(
[
html.Span(
file,
id={"type": "listed_file", "index": i},
title=full_path,
title=str(full_path),
style={"fontWeight": "bold"} if is_dir else {},
),
],
Expand Down
10 changes: 6 additions & 4 deletions eit_dash/pages/load.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path

import dash_bootstrap_components as dbc
from dash import dcc, html, register_page
Expand Down Expand Up @@ -96,9 +96,11 @@
[
dbc.Row(
[
dcc.Store(id=ids.STORED_CWD, data=os.getcwd()),
html.H5(html.B(html.A("⬆️ Parent directory", href="#", id=ids.PARENT_DIR))),
html.H3([html.Code(os.getcwd(), id=ids.CWD)]),
dcc.Store(id=ids.STORED_CWD, data=str(Path.cwd())),
html.H5(
html.B(html.A("⬆️ Parent directory", href="#", id=ids.PARENT_DIR)),
),
html.H3([html.Code(str(Path.cwd()), id=ids.CWD)]),
html.Br(),
html.Br(),
html.Div(id=ids.CWD_FILES, style=styles.FILE_BROWSER),
Expand Down

0 comments on commit e51f1a7

Please sign in to comment.