You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "eumiro (via GitHub)" <gi...@apache.org> on 2023/08/23 04:25:06 UTC
[GitHub] [airflow] eumiro commented on a diff in pull request #33592: Use str.splitlines() to split lines
eumiro commented on code in PR #33592:
URL: https://github.com/apache/airflow/pull/33592#discussion_r1302466405
##########
airflow/utils/file.py:
##########
@@ -215,21 +215,21 @@ def _find_path_from_directory(
ignore_file_path = Path(root) / ignore_file_name
if ignore_file_path.is_file():
- with open(ignore_file_path) as ifile:
- lines_no_comments = [re2.sub(r"\s*#.*", "", line) for line in ifile.read().split("\n")]
- # append new patterns and filter out "None" objects, which are invalid patterns
- patterns += [
- p
- for p in [
- ignore_rule_type.compile(line, Path(base_dir_path), ignore_file_path)
- for line in lines_no_comments
- if line
- ]
- if p is not None
+ lines = ignore_file_path.read_text().splitlines()
Review Comment:
How about
```python
ignore_file_path = Path(root) / ignore_file_name
if ignore_file_path.is_file():
uniq_patterns = {}
with ignore_file_path.open() as f:
for line in f:
line = line.strip()
if line and not line.startswith("#"):
pattern = ignore_rule_type.compile(line, Path(base_dir_path), ignore_file_path)
if pattern:
uniq_patterns[pattern] = None
# evaluation order of patterns is important with negation
# so that later patterns can override earlier patterns
patterns = list(uniq_patterns)
```
This probably describes the steps even better, and shows that the `ignore_rule_type.compile` is called before the patterns are filtered via `uniq` (dict).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org