-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REF: Replace os.path with pathlib.Path in pandas_web.py #61604
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
base: main
Are you sure you want to change the base?
Conversation
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.
Looks good, but we need to make everything that is a path a pathlib object when it's first created. Not create it as a string and cast it for every operation.
@@ -100,20 +100,17 @@ def blog_add_posts(context): | |||
posts = [] | |||
# posts from the file system | |||
if context["blog"]["posts_path"]: | |||
posts_path = os.path.join( | |||
context["source_path"], *context["blog"]["posts_path"].split("/") | |||
posts_path = pathlib.Path(context["source_path"]) / pathlib.Path( |
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.
I don't think the second one needs to be a pathlib object if tbe first it's already one, it should work if it's a string
@@ -394,7 +391,7 @@ def get_context(config_fname: str, **kwargs): | |||
with open(config_fname, encoding="utf-8") as f: |
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.
Shouldn't config_fname be a pathlib too?
@@ -414,9 +411,9 @@ def get_source_files(source_path: str) -> typing.Generator[str, None, None]: | |||
Generate the list of files present in the source directory. | |||
""" | |||
for root, dirs, fnames in os.walk(source_path): |
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.
If you make source_path a pathlib I don't think you need to convert later.
try: | ||
json.load(f) | ||
except json.JSONDecodeError as e: | ||
raise RuntimeError( | ||
f"Invalid versions.json: {e}. Ensure it is valid JSON." | ||
) from e | ||
|
||
config_fname = os.path.join(source_path, "config.yml") | ||
config_fname = pathlib.Path(source_path) / "config.yml" |
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.
You are making source_path a pathlib twice. Ideally we want paths to be a pathlib since they are created. Not create them as str and convert when there is an operation. For everything that is a path, also config_path and others
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_path)) | ||
|
||
for fname in get_source_files(source_path): | ||
if os.path.normpath(fname) in context["main"]["ignore"]: | ||
if str(pathlib.Path(fname)) in context["main"]["ignore"]: |
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.
I think there is an attribute for that, right?
Replaces
os.path
withpathlib.Path
inpandas_web.py
, as suggested by @datapythonista in 61578. No functional changes, verified site generation remains correct