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

Add agnostic path for project files #5043

Open
FelixMiksonAramMeem opened this issue May 8, 2024 · 0 comments
Open

Add agnostic path for project files #5043

FelixMiksonAramMeem opened this issue May 8, 2024 · 0 comments

Comments

@FelixMiksonAramMeem
Copy link

DBT config yaml
Working with the magician on different operating systems (Win, Unix, Mac), we discovered that the paths to dbt models are saved differently in yaml files depending on this. for example, dbts\run_all.yaml in Win. Is it possible to make path formation independent of the operating system, at least when reading the config or running the pipeline?

https://files.slack.com/files-pri/T03GK6PEQP6-F0727SEC9FF/image.png
https://files.slack.com/files-pri/T03GK6PEQP6-F0727SBMN0M/image.png

Solution
Using pathlib instead of os.path
Refactoring File class methods (git)

Example

from pathlib import Path, PureWindowsPath
from platform import system


class AgnosticPath(Path):

    def __new__(cls, *args, **kwargs):
        new_path = PureWindowsPath(*args).parts
        if (system() != "Windows") and (len(new_path) > 0) and (new_path[0] in ("/", "\\")):
            new_path = ("/", *new_path[1:])
        return super().__new__(Path, *new_path, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant