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(ingestion): use raw strings for regexes #5006

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions metadata-ingestion/src/datahub/configuration/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def resolve_element(element: str) -> str:
if re.search("(\$\{).+(\})", element): # noqa: W605
if re.search(r"(\$\{).+(\})", element):
return expandvars(element, nounset=True)
elif element.startswith("$"):
try:
Expand All @@ -22,16 +22,16 @@ def resolve_element(element: str) -> str:
return element


def resolve_list(ele_list: list) -> list:
new_v = []
def _resolve_list(ele_list: list) -> list:
new_v: list = []
for ele in ele_list:
if isinstance(ele, str):
new_v.append(resolve_element(ele)) # type:ignore
new_v.append(resolve_element(ele))
elif isinstance(ele, list):
new_v.append(resolve_list(ele)) # type:ignore
new_v.append(_resolve_list(ele))
elif isinstance(ele, dict):
resolve_env_variables(ele)
new_v.append(resolve_env_variables(ele)) # type:ignore
new_v.append(resolve_env_variables(ele))
else:
new_v.append(ele)
return new_v
Expand All @@ -42,7 +42,7 @@ def resolve_env_variables(config: dict) -> dict:
if isinstance(v, dict):
resolve_env_variables(v)
elif isinstance(v, list):
config[k] = resolve_list(v)
config[k] = _resolve_list(v)
elif isinstance(v, str):
config[k] = resolve_element(v)
return config
Expand Down
2 changes: 1 addition & 1 deletion metadata-ingestion/src/datahub/ingestion/source/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class DBTConfig(StatefulIngestionConfigBase):
)
owner_extraction_pattern: Optional[str] = Field(
default=None,
description='Regex string to extract owner from the dbt node using the `(?P<name>...) syntax` of the [match object](https://docs.python.org/3/library/re.html#match-objects), where the group name must be `owner`. Examples: (1)`r"(?P<owner>(.*)): (\w+) (\w+)"` will extract `jdoe` as the owner from `"jdoe: John Doe"` (2) `r"@(?P<owner>(.*))"` will extract `alice` as the owner from `"@alice"`.', # noqa: W605
description='Regex string to extract owner from the dbt node using the `(?P<name>...) syntax` of the [match object](https://docs.python.org/3/library/re.html#match-objects), where the group name must be `owner`. Examples: (1)`r"(?P<owner>(.*)): (\\w+) (\\w+)"` will extract `jdoe` as the owner from `"jdoe: John Doe"` (2) `r"@(?P<owner>(.*))"` will extract `alice` as the owner from `"@alice"`.',
)
aws_connection: Optional[AwsConnectionConfig] = Field(
default=None,
Expand Down
4 changes: 1 addition & 3 deletions metadata-ingestion/src/datahub/ingestion/source/s3/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ def validate_path_spec(cls, values: Dict) -> Dict[str, Any]:
compiled_include_tmp = parse.compile(values["_parsable_include"])
values["_compiled_include"] = compiled_include_tmp
logger.debug(f'Setting _compiled_include: {values["_compiled_include"]}')
values["_glob_include"] = re.sub(
"\{[^}]+\}", "*", values["include"] # noqa: W605
)
values["_glob_include"] = re.sub(r"\{[^}]+\}", "*", values["include"])
logger.debug(f'Setting _glob_include: {values.get("_glob_include")}')

if values.get("table_name") is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def gen_folder_key(self, abs_path):
)

def get_prefix(self, relative_path: str) -> str:
index = re.search("[\*|\{]", relative_path) # noqa: W605
index = re.search(r"[\*|\{]", relative_path)
if index:
return relative_path[: index.start()]
else:
Expand Down