Skip to content

Commit

Permalink
Merge pull request #487 from dbt-labs/fix/os-identification
Browse files Browse the repository at this point in the history
  • Loading branch information
b-per authored Sep 5, 2024
2 parents 34209f6 + e7f241a commit 9b88dc7
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions macros/get_directory_pattern.sql
Original file line number Diff line number Diff line change
@@ -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("\\" not 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 %}

Expand All @@ -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 %}

0 comments on commit 9b88dc7

Please sign in to comment.