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(ingest/s3): Converting windows style path to posix one on local fs #8757

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

treff7es
Copy link
Contributor

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

@github-actions github-actions bot added the ingestion PR or Issue related to the ingestion of metadata label Aug 30, 2023
# We need to make sure the path is in posix style which is not true on windows
full_path = PurePath(
os.path.normpath(os.path.join(root, file))
).as_posix()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need both os.path.normpath and PurePath.as_posix ?

From docs, both do similar things.
https://docs.python.org/3/library/os.path.html#os.path.normpath
https://docs.python.org/3/library/pathlib.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I get it right doesn't do the same thing even though there are similarities:

  1. normpath ->
os.path.normpath() method in Python is used to normalize the specified path. All redundant separator and up-level references are collapsed in the process of path normalization. 

For example: A//B, A/B/, A/./B and A/foo/../B all will be normalized to A/B. 

On Windows operating system, any forward slash (‘/’) in the path is converted to backslash (‘\’).

This is needed to make the dir separator consistent and also it simplifies the path (which I think is a good thing)
2. PurePath's as_posix turns the path to a UNIX path and uses unix type dir separators which is what s3 source and the urn expects

Copy link
Collaborator

@mayurinehate mayurinehate Aug 31, 2023

Choose a reason for hiding this comment

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

right they aren't same. Sounds like normpath does something more than as_posix, but yet it already does everything that as_posix might be doing ? (linux like / separators) .

I'm okay to keep both, just trying to understand this better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately normpath just sets the dir separators consistently but on Windows, it is the opposite as on UNIX (which we actually need).
Purepath creates the path based on the os you run (on windows, it will treat the path as WindowsPath while on Unix, it will be UnixPath), and if you run as_posix on it then you will get the UNIX path separators that we need.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Didn't understand the value add of PurePath.as_posix over os.path.normpath but the change seems better than original code.

Copy link
Collaborator

@mayurinehate mayurinehate left a comment

Choose a reason for hiding this comment

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

lgtm

@treff7es treff7es merged commit 0a869dd into datahub-project:master Sep 26, 2023
48 of 49 checks passed
@treff7es treff7es deleted the s3_fix_local_fs_windows branch September 26, 2023 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ingestion PR or Issue related to the ingestion of metadata
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants