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 heisentest by ignoring the basepath #11993

Merged
merged 1 commit into from
Nov 2, 2020
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
7 changes: 4 additions & 3 deletions airflow/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ def find_path_from_directory(
for file in files: # type: ignore
if file == ignore_file_name:
continue
file_path = os.path.join(root, str(file))
if any(re.findall(p, file_path) for p in patterns):
abs_file_path = os.path.join(root, str(file))
rel_file_path = os.path.join(os.path.relpath(root, str(base_dir_path)), str(file))
if any(p.search(rel_file_path) for p in patterns):
continue
yield str(file_path)
yield str(abs_file_path)


def list_py_file_paths(directory: str,
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ A ``.airflowignore`` file specifies the directories or files in ``DAG_FOLDER``
or ``PLUGINS_FOLDER`` that Airflow should intentionally ignore.
Each line in ``.airflowignore`` specifies a regular expression pattern,
and directories or files whose names (not DAG id) match any of the patterns
would be ignored (under the hood,``re.findall()`` is used to match the pattern).
would be ignored (under the hood,``Pattern.search()`` is used to match the pattern).
Overall it works like a ``.gitignore`` file.
Use the ``#`` character to indicate a comment; all characters
on a line following a ``#`` will be ignored.
Expand Down
9 changes: 3 additions & 6 deletions tests/plugins/test_plugin_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import unittest
from unittest.mock import patch

import pytest

from airflow import settings
from airflow.utils.file import find_path_from_directory

Expand All @@ -38,10 +36,11 @@ def setUp(self):
"""
Make tmp folder and files that should be ignored. And set base path.
"""
self.test_dir = tempfile.mkdtemp()
# Temp dir name includes an ignored token "not", but it shouldn't matter since it's in the base path.
self.test_dir = tempfile.mkdtemp(prefix="onotole")
self.test_file = os.path.join(self.test_dir, 'test_file.txt')
self.plugin_folder_path = os.path.join(self.test_dir, 'test_ignore')
os.mkdir(os.path.join(self.test_dir, "test_ignore"))
os.mkdir(self.plugin_folder_path)
os.mkdir(os.path.join(self.plugin_folder_path, "subdir1"))
os.mkdir(os.path.join(self.plugin_folder_path, "subdir2"))
files_content = [
Expand All @@ -67,8 +66,6 @@ def tearDown(self):
"""
shutil.rmtree(self.test_dir)

# See the issue: https://github.com/apache/airflow/issues/10988
@pytest.mark.heisentests
def test_find_not_should_ignore_path(self):
"""
Test that the .airflowignore work and whether the file is properly ignored.
Expand Down