Skip to content

Commit 61d1dbb

Browse files
Move FSHook/PackageIndexHook/SubprocessHook to standard provider (apache#42506)
* move hooks to standard providers * fix document build and adding hooks to provider yaml file * adding fshook tests * marking as db test * doc reference update to subprocess hook
1 parent 6e3118a commit 61d1dbb

File tree

15 files changed

+94
-16
lines changed

15 files changed

+94
-16
lines changed

airflow/operators/bash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from typing import TYPE_CHECKING, Any, Callable, Container, Sequence, cast
2525

2626
from airflow.exceptions import AirflowException, AirflowSkipException
27-
from airflow.hooks.subprocess import SubprocessHook
2827
from airflow.models.baseoperator import BaseOperator
28+
from airflow.providers.standard.hooks.subprocess import SubprocessHook
2929
from airflow.utils.operator_helpers import context_to_airflow_vars
3030
from airflow.utils.types import ArgNotSet
3131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
File renamed without changes.

airflow/hooks/subprocess.py airflow/providers/standard/hooks/subprocess.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def run_command(
5252
:param env: Optional dict containing environment variables to be made available to the shell
5353
environment in which ``command`` will be executed. If omitted, ``os.environ`` will be used.
5454
Note, that in case you have Sentry configured, original variables from the environment
55-
will also be passed to the subprocess with ``SUBPROCESS_`` prefix. See
56-
:doc:`/administration-and-deployment/logging-monitoring/errors` for details.
55+
will also be passed to the subprocess with ``SUBPROCESS_`` prefix. See:
56+
https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/logging-monitoring/errors.html for details.
5757
:param output_encoding: encoding to use for decoding stdout
5858
:param cwd: Working directory to run the command in.
5959
If None (default), the command is run in a temporary directory.

airflow/providers/standard/provider.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ sensors:
5050
- airflow.providers.standard.sensors.time_delta
5151
- airflow.providers.standard.sensors.time
5252
- airflow.providers.standard.sensors.weekday
53+
54+
hooks:
55+
- integration-name: Standard
56+
python-modules:
57+
- airflow.providers.standard.hooks.filesystem
58+
- airflow.providers.standard.hooks.package_index
59+
- airflow.providers.standard.hooks.subprocess

airflow/providers_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
from packaging.utils import canonicalize_name
3737

3838
from airflow.exceptions import AirflowOptionalProviderFeatureException
39-
from airflow.hooks.filesystem import FSHook
40-
from airflow.hooks.package_index import PackageIndexHook
39+
from airflow.providers.standard.hooks.filesystem import FSHook
40+
from airflow.providers.standard.hooks.package_index import PackageIndexHook
4141
from airflow.typing_compat import ParamSpec
4242
from airflow.utils import yaml
4343
from airflow.utils.entry_points import entry_points_with_dist

airflow/sensors/filesystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from airflow.configuration import conf
2727
from airflow.exceptions import AirflowException
28-
from airflow.hooks.filesystem import FSHook
28+
from airflow.providers.standard.hooks.filesystem import FSHook
2929
from airflow.sensors.base import BaseSensorOperator
3030
from airflow.triggers.base import StartTriggerArgs
3131
from airflow.triggers.file import FileTrigger

docs/apache-airflow/administration-and-deployment/logging-monitoring/errors.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Impact of Sentry on Environment variables passed to Subprocess Hook
9696

9797
When Sentry is enabled, by default it changes the standard library to pass all environment variables to
9898
subprocesses opened by Airflow. This changes the default behaviour of
99-
:class:`airflow.hooks.subprocess.SubprocessHook` - always all environment variables are passed to the
99+
:class:`airflow.providers.standard.hooks.subprocess.SubprocessHook` - always all environment variables are passed to the
100100
subprocess executed with specific set of environment variables. In this case not only the specified
101101
environment variables are passed but also all existing environment variables are passed with
102102
``SUBPROCESS_`` prefix added. This happens also for all other subprocesses.

docs/apache-airflow/operators-and-hooks-ref.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ For details see: :doc:`apache-airflow-providers:operators-and-hooks-ref/index`.
106106
* - Hooks
107107
- Guides
108108

109-
* - :mod:`airflow.hooks.filesystem`
109+
* - :mod:`airflow.providers.standard.hooks.filesystem`
110110
-
111111

112-
* - :mod:`airflow.hooks.subprocess`
112+
* - :mod:`airflow.providers.standard.hooks.subprocess`
113113
-
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
from __future__ import annotations
19+
20+
import pytest
21+
22+
from airflow.providers.standard.hooks.filesystem import FSHook
23+
24+
pytestmark = pytest.mark.db_test
25+
26+
27+
class TestFSHook:
28+
def test_get_ui_field_behaviour(self):
29+
fs_hook = FSHook()
30+
assert fs_hook.get_ui_field_behaviour() == {
31+
"hidden_fields": ["host", "schema", "port", "login", "password", "extra"],
32+
"relabeling": {},
33+
"placeholders": {},
34+
}
35+
36+
def test_get_path(self):
37+
fs_hook = FSHook(fs_conn_id="fs_default")
38+
39+
assert fs_hook.get_path() == "/"

tests/hooks/test_package_index.py tests/providers/standard/hooks/test_package_index.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
import pytest
2323

24-
from airflow.hooks.package_index import PackageIndexHook
2524
from airflow.models.connection import Connection
25+
from airflow.providers.standard.hooks.package_index import PackageIndexHook
2626

2727

2828
class MockConnection(Connection):
@@ -73,7 +73,7 @@ def mock_get_connection(monkeypatch: pytest.MonkeyPatch, request: pytest.Fixture
7373
password: str | None = testdata.get("password", None)
7474
expected_result: str | None = testdata.get("expected_result", None)
7575
monkeypatch.setattr(
76-
"airflow.hooks.package_index.PackageIndexHook.get_connection",
76+
"airflow.providers.standard.hooks.package_index.PackageIndexHook.get_connection",
7777
lambda *_: MockConnection(host, login, password),
7878
)
7979
return expected_result
@@ -104,7 +104,7 @@ class MockProc:
104104

105105
return MockProc()
106106

107-
monkeypatch.setattr("airflow.hooks.package_index.subprocess.run", mock_run)
107+
monkeypatch.setattr("airflow.providers.standard.hooks.package_index.subprocess.run", mock_run)
108108

109109
hook_instance = PackageIndexHook()
110110
if mock_get_connection:

tests/hooks/test_subprocess.py tests/providers/standard/hooks/test_subprocess.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import pytest
2828

29-
from airflow.hooks.subprocess import SubprocessHook
29+
from airflow.providers.standard.hooks.subprocess import SubprocessHook
3030

3131
OS_ENV_KEY = "SUBPROCESS_ENV_TEST"
3232
OS_ENV_VAL = "this-is-from-os-environ"
@@ -81,11 +81,11 @@ def test_return_value(self, val, expected):
8181

8282
@mock.patch.dict("os.environ", clear=True)
8383
@mock.patch(
84-
"airflow.hooks.subprocess.TemporaryDirectory",
84+
"airflow.providers.standard.hooks.subprocess.TemporaryDirectory",
8585
return_value=MagicMock(__enter__=MagicMock(return_value="/tmp/airflowtmpcatcat")),
8686
)
8787
@mock.patch(
88-
"airflow.hooks.subprocess.Popen",
88+
"airflow.providers.standard.hooks.subprocess.Popen",
8989
return_value=MagicMock(stdout=MagicMock(readline=MagicMock(side_effect=StopIteration), returncode=0)),
9090
)
9191
def test_should_exec_subprocess(self, mock_popen, mock_temporary_directory):

tests/sensors/test_filesystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
@pytest.mark.skip_if_database_isolation_mode # Test is broken in db isolation mode
4141
class TestFileSensor:
4242
def setup_method(self):
43-
from airflow.hooks.filesystem import FSHook
43+
from airflow.providers.standard.hooks.filesystem import FSHook
4444

4545
hook = FSHook()
4646
args = {"owner": "airflow", "start_date": DEFAULT_DATE}

0 commit comments

Comments
 (0)