From 41c9a26061a94dfad78afb7754eb9b8aa418fc96 Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:29:50 +0200 Subject: [PATCH 1/2] Check path in graph rather than env var for os identification --- macros/get_directory_pattern.sql | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/macros/get_directory_pattern.sql b/macros/get_directory_pattern.sql index 8ad21ec8..e35d27a6 100644 --- a/macros/get_directory_pattern.sql +++ b/macros/get_directory_pattern.sql @@ -1,11 +1,19 @@ -- these macros will read a user’s home environment and detect whether a computer’s operating system is Windows based or Mac/Linux, and display the right directory pattern. +{% macro is_os_mac_or_linux() %} + {% for val in graph.nodes.values() %} + {{ return("/" in val.get("original_file_path","")) }} + {% endfor %} + {{ return(true) }} +{% endmacro %} + {% macro get_directory_pattern() %} - {%- set env_var_home_exists = env_var("HOME", "not_set") != "not_set" -%} - {%- set on_mac_or_linux = env_var_home_exists and "\\\\" not in env_var("HOME") -%} - {%- if on_mac_or_linux -%} - {{ return("/") }} - {% else %} - {{ return("\\\\") }} + {% if execute %} + {%- set on_mac_or_linux = dbt_project_evaluator.is_os_mac_or_linux() -%} + {%- if on_mac_or_linux -%} + {{ return("/") }} + {% else %} + {{ return("\\\\") }} + {% endif %} {% endif %} {% endmacro %} @@ -15,11 +23,12 @@ {% endmacro %} {% macro get_dbtreplace_directory_pattern() %} - {%- set env_var_home_exists = env_var("HOME", "not_set") != "not_set" -%} - {%- set on_mac_or_linux = env_var_home_exists and "\\\\" not in env_var("HOME") -%} - {%- if on_mac_or_linux -%} - {{ dbt.replace("file_path", "regexp_replace(file_path,'.*/','')", "''") }} - {% else %} - {{ dbt.replace("file_path", "regexp_replace(file_path,'.*\\\\\\\\','')", "''") }} + {% if execute %} + {%- set on_mac_or_linux = dbt_project_evaluator.is_os_mac_or_linux() -%} + {%- if on_mac_or_linux -%} + {{ dbt.replace("file_path", "regexp_replace(file_path,'.*/','')", "''") }} + {% else %} + {{ dbt.replace("file_path", "regexp_replace(file_path,'.*\\\\\\\\','')", "''") }} + {% endif %} {% endif %} {% endmacro %} \ No newline at end of file From e7f241a604971531277b207ec858fc4e1c9aa04e Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:33:21 +0200 Subject: [PATCH 2/2] Change the default to MacOS/Unix --- macros/get_directory_pattern.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/get_directory_pattern.sql b/macros/get_directory_pattern.sql index e35d27a6..e16caefb 100644 --- a/macros/get_directory_pattern.sql +++ b/macros/get_directory_pattern.sql @@ -1,7 +1,7 @@ -- these macros will read a user’s home environment and detect whether a computer’s operating system is Windows based or Mac/Linux, and display the right directory pattern. {% macro is_os_mac_or_linux() %} {% for val in graph.nodes.values() %} - {{ return("/" in val.get("original_file_path","")) }} + {{ return("\\" not in val.get("original_file_path","")) }} {% endfor %} {{ return(true) }} {% endmacro %}