Skip to content
Closed
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
16 changes: 8 additions & 8 deletions airflow/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ def mkdirs(path, mode):
:param path: The directory to create
:param mode: The mode to give to the directory e.g. 0o755, ignores umask
"""
import warnings

warnings.warn(
f"This function is deprecated. Please use `pathlib.Path({path}).mkdir`",
RemovedInAirflow3Warning,
stacklevel=2,
)
Path(path).mkdir(mode=mode, parents=True, exist_ok=True)
try:
o_umask = os.umask(0)
os.makedirs(path, mode)
except OSError:
if not os.path.isdir(path):
raise
finally:
os.umask(o_umask)


ZIP_REGEX = re.compile(rf"((.*\.zip){re.escape(os.sep)})?(.*)")
Expand Down
13 changes: 12 additions & 1 deletion tests/utils/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@
import os
import os.path
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest import mock
from uuid import uuid4

import pytest

from airflow.utils.file import correct_maybe_zipped, find_path_from_directory, open_maybe_zipped
from airflow.utils.file import correct_maybe_zipped, find_path_from_directory, mkdirs, open_maybe_zipped
from tests.models import TEST_DAGS_FOLDER


def test_mkdirs():
with TemporaryDirectory() as tmpdir:
path = os.path.join(tmpdir, str(uuid4()), str(uuid4()))
mkdirs(path, 0o777)

mode = oct(os.stat(path).st_mode)[-3:]
assert mode == "777"


class TestCorrectMaybeZipped:
@mock.patch("zipfile.is_zipfile")
def test_correct_maybe_zipped_normal_file(self, mocked_is_zipfile):
Expand Down