Skip to content

Commit

Permalink
Replace "absolute()" with "resolve()" in pathlib objects (#23675)
Browse files Browse the repository at this point in the history
TIL that absolute() is an undocumented in Pathlib and that we
should use resolve() instead.

So this is it.

(cherry picked from commit 094e50e)
  • Loading branch information
potiuk authored and ephraimbuddy committed May 21, 2022
1 parent fdc098e commit 403a3f0
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion airflow/providers/amazon/aws/hooks/batch_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def default_config(self) -> Dict:
:rtype: Dict
"""
if self._default_config is None:
config_path = Path(__file__).with_name("batch_waiters.json").absolute()
config_path = Path(__file__).with_name("batch_waiters.json").resolve()
with open(config_path) as config_file:
self._default_config = json.load(config_file)
return deepcopy(self._default_config) # avoid accidental mutation
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
read_from_cache_file,
)

AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/tests/test_find_airflow_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from airflow_breeze.utils.path_utils import find_airflow_sources_root_to_operate_on

ACTUAL_AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
ACTUAL_AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
ROOT_PATH = Path(Path(__file__).root)


Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/pre_commit/pre_commit_breeze_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from rich.console import Console

AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].resolve()
BREEZE_IMAGES_DIR = AIRFLOW_SOURCES_DIR / "images" / "breeze"
BREEZE_SOURCES_DIR = AIRFLOW_SOURCES_DIR / "dev" / "breeze" / "src"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

errors = []

MY_DIR_PATH = Path(__file__).parent.absolute()
MY_DIR_PATH = Path(__file__).parent.resolve()

SOURCE_DIR_PATH = MY_DIR_PATH.parents[2].absolute()
SOURCE_DIR_PATH = MY_DIR_PATH.parents[2].resolve()
BUILD_ARGS_REF_PATH = SOURCE_DIR_PATH / "docs" / "docker-stack" / "build-arg-ref.rst"
GLOBAL_CONSTANTS_PATH = SOURCE_DIR_PATH / "dev" / "breeze" / "src" / "airflow_breeze" / "global_constants.py"

Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_check_pre_commit_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.absolute())) # make sure common_precommit_utils is imported
sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported

from collections import defaultdict # noqa: E402
from functools import lru_cache # noqa: E402
Expand All @@ -38,7 +38,7 @@

console = Console(width=400, color_system="standard")

AIRFLOW_SOURCES_PATH = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES_PATH = Path(__file__).parents[3].resolve()
AIRFLOW_BREEZE_SOURCES_PATH = AIRFLOW_SOURCES_PATH / "dev" / "breeze"
PRE_COMMIT_IDS_PATH = AIRFLOW_BREEZE_SOURCES_PATH / "src" / "airflow_breeze" / "pre_commit_ids.py"
PRE_COMMIT_YAML_FILE = AIRFLOW_SOURCES_PATH / ".pre-commit-config.yaml"
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
f"To run this script, run the ./{__file__} command"
)

AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow")

if __name__ == '__main__':
sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src"))
sys.path.insert(0, str(Path(__file__).parents[3].resolve() / "dev" / "breeze" / "src"))
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH

AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pathlib import Path
from typing import List

AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].resolve()


def insert_content(file_path: Path, content: List[str], header: str, footer: str, file_name: str):
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_insert_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from pathlib import Path
from textwrap import wrap

AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].resolve()

sys.path.insert(0, str(Path(__file__).parent.absolute())) # make sure common_precommit_utils is imported
sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported
sys.path.insert(0, str(AIRFLOW_SOURCES_DIR)) # make sure setup is imported from Airflow
# flake8: noqa: F401

Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_migration_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
f"To run this script, run the ./{__file__} command"
)

AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow")

if __name__ == '__main__':
sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src"))
sys.path.insert(0, str(Path(__file__).parents[3].resolve() / "dev" / "breeze" / "src"))
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH

AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7"
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
)


AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow")

if __name__ == '__main__':
sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src"))
sys.path.insert(0, str(Path(__file__).parents[3].resolve() / "dev" / "breeze" / "src"))
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH

AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7"
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_ui_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
f"To run this script, run the ./{__file__} command"
)

AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow")
AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7"

if __name__ == '__main__':
sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src"))
sys.path.insert(0, str(Path(__file__).parents[3].resolve() / "dev" / "breeze" / "src"))
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH

AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
f"To execute this script, run ./{__file__} [FILE] ..."
)

AIRFLOW_SOURCES_ROOT = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES_ROOT = Path(__file__).parents[3].resolve()
BREEZE_SOURCES_ROOT = AIRFLOW_SOURCES_ROOT / "dev" / "breeze"


Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/pre_commit_www_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
f"To run this script, run the ./{__file__} command"
)

AIRFLOW_SOURCES = Path(__file__).parents[3].absolute()
AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow")
AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7"

if __name__ == '__main__':
sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src"))
sys.path.insert(0, str(Path(__file__).parents[3].resolve() / "dev" / "breeze" / "src"))
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH

AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7"
Expand Down
2 changes: 1 addition & 1 deletion scripts/in_container/run_migration_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from alembic.script import Script

airflow_version = re.match(r'(\d+\.\d+\.\d+).*', _airflow_version).group(1) # type: ignore
project_root = Path(__file__).parents[2].absolute()
project_root = Path(__file__).parents[2].resolve()


def replace_text_between(file: Path, start: str, end: str, replacement_text: str):
Expand Down
4 changes: 2 additions & 2 deletions scripts/in_container/verify_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

console = Console(width=400, color_system="standard")

AIRFLOW_SOURCES_ROOT = Path(__file__).parents[2].absolute()
AIRFLOW_SOURCES_ROOT = Path(__file__).parents[2].resolve()
PROVIDERS_PATH = AIRFLOW_SOURCES_ROOT / "airflow" / "providers"


Expand Down Expand Up @@ -835,7 +835,7 @@ def add_all_namespaced_packages(
:param provider_path:
:param provider_prefix:
"""
main_path = Path(provider_path).absolute()
main_path = Path(provider_path).resolve()
for candidate_path in main_path.rglob("*"):
if candidate_path.name == "__pycache__":
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/dag_processing/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_callbacks, clear_db_dags, clear_db_runs, clear_db_serialized_dags

TEST_DAG_FOLDER = pathlib.Path(__file__).parents[1].absolute() / 'dags'
TEST_DAG_FOLDER = pathlib.Path(__file__).parents[1].resolve() / 'dags'

DEFAULT_DATE = timezone.datetime(2016, 1, 1)

Expand Down
4 changes: 2 additions & 2 deletions tests/executors/test_kubernetes_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def test_invalid_executor_config(self, mock_get_kube_client, mock_kubernetes_job
@mock.patch('airflow.executors.kubernetes_executor.AirflowKubernetesScheduler.run_pod_async')
@mock.patch('airflow.executors.kubernetes_executor.get_kube_client')
def test_pod_template_file_override_in_executor_config(self, mock_get_kube_client, mock_run_pod_async):
current_folder = pathlib.Path(__file__).parent.absolute()
current_folder = pathlib.Path(__file__).parent.resolve()
template_file = str(
(current_folder / "kubernetes_executor_template_files" / "basic_template.yaml").absolute()
(current_folder / "kubernetes_executor_template_files" / "basic_template.yaml").resolve()
)

mock_kube_client = mock.patch('kubernetes.client.CoreV1Api', autospec=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_db_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_no_models_missing(self):
"""
import pkgutil

proj_root = Path(__file__).parents[2].absolute()
proj_root = Path(__file__).parents[2].resolve()
mods = list(
f"airflow.models.{name}"
for _, name, _ in pkgutil.iter_modules([str(proj_root / 'airflow/models')])
Expand Down

0 comments on commit 403a3f0

Please sign in to comment.