-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-13824 Installed Python Processor Dependencies with one command
If a Python processor defines dependencies both inline and in a requirements.txt file, then we need to install the two groups of dependencies in a single `pip install` command, otherwise pip is not able to resolve the web of dependencies correctly. - Added setup-python step with Python 3.12 to ci-workflow for consistent version behavior This closes #9429 Signed-off-by: David Handermann <[email protected]>
- Loading branch information
1 parent
5be2cd7
commit 3b3e74d
Showing
8 changed files
with
180 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...-framework-bundle/nifi-python-framework/src/test/python/framework/TestExtensionManager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import tempfile | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from ExtensionManager import ExtensionManager | ||
from testutils import set_up_env, get_processor_details | ||
|
||
PROCESSOR_WITH_DEPENDENCIES_TEST_FILE = 'src/test/resources/python/framework/processor_with_dependencies/ProcessorWithDependencies.py' | ||
|
||
class ReturncodeMocker: | ||
def __init__(self, return_code): | ||
self.returncode = return_code | ||
|
||
class TestExtensionManager(unittest.TestCase): | ||
def setUp(self): | ||
set_up_env() | ||
self.extension_manager = ExtensionManager(None) | ||
|
||
@patch('subprocess.run') | ||
def test_import_external_dependencies(self, mock_subprocess_run): | ||
details = get_processor_details(self, 'ProcessorWithDependencies', PROCESSOR_WITH_DEPENDENCIES_TEST_FILE, '/extensions/processor_with_dependencies') | ||
self.assertIsNotNone(details) | ||
|
||
mock_subprocess_run.return_value = ReturncodeMocker(0) | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
packages_dir = os.path.join(temp_dir, 'packages') | ||
self.extension_manager.import_external_dependencies(details, packages_dir) | ||
|
||
mock_subprocess_run.assert_called_once() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...s/nifi-py4j-framework-bundle/nifi-python-framework/src/test/python/framework/testutils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import sys | ||
from nifiapi.__jvm__ import JvmHolder | ||
import ProcessorInspection | ||
|
||
class FakeJvm: | ||
def __init__(self): | ||
self.java = FakeJava() | ||
|
||
class FakeJava: | ||
def __init__(self): | ||
self.util = FakeJavaUtil() | ||
|
||
class FakeJavaUtil: | ||
def ArrayList(self): | ||
return FakeArrayList([]) | ||
|
||
class FakeArrayList: | ||
def __init__(self, my_list): | ||
self.my_list = my_list | ||
|
||
def __len__(self): | ||
return len(self.my_list) | ||
|
||
def __iter__(self): | ||
return iter(self.my_list) | ||
|
||
def add(self, element): | ||
self.my_list.append(element) | ||
|
||
def set_up_env(): | ||
python_command = sys.executable | ||
os.environ["PYTHON_CMD"] = python_command | ||
JvmHolder.jvm = FakeJvm() | ||
|
||
def get_processor_details(test_fixture, processor_name, processor_file, extension_home): | ||
class_nodes = ProcessorInspection.get_processor_class_nodes(processor_file) | ||
test_fixture.assertIsNotNone(class_nodes) | ||
test_fixture.assertEqual(len(class_nodes), 1) | ||
class_node = class_nodes[0] | ||
test_fixture.assertEqual(class_node.name, processor_name) | ||
|
||
return ProcessorInspection.get_processor_details(class_node, processor_file, extension_home, False) |
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
.../test/resources/python/framework/processor_with_dependencies/ProcessorWithDependencies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from nifiapi.flowfiletransform import FlowFileTransform, FlowFileTransformResult | ||
|
||
class ProcessorWithDependencies(FlowFileTransform): | ||
class Java: | ||
implements = ['org.apache.nifi.python.processor.FlowFileTransform'] | ||
|
||
class ProcessorDetails: | ||
description = "This processor depends on both google-cloud-vision and pymilvus" | ||
version = '0.0.1' | ||
tags = ['cloud', 'vision', 'milvus'] | ||
dependencies = ['pymilvus==2.4.4'] | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def transform(self, context, flow_file): | ||
self.logger.info("ProcessorWithDependencies is returning") | ||
return FlowFileTransformResult('success', contents='foobar') |
16 changes: 16 additions & 0 deletions
16
...ramework/src/test/resources/python/framework/processor_with_dependencies/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
google-cloud-vision==3.7.4 |