-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow absolute path for the external script (#2565)
* add check not allow absolute path for the external script in job creation API. * Changed the job creation API to allow absolution path ext_scripts, but not copy the script. * Added absolute path ext_script support for job creation. * removed the no use import. * Added handle for the line continous support, added unit test. * Removed the requirement for absolute external script to have the package path. * enhance the handling of multi-lines import. added more cases of unit test. --------- Co-authored-by: Yuan-Ting Hsieh (謝沅廷) <yuantingh@nvidia.com>
- Loading branch information
1 parent
f8f121f
commit e37ff67
Showing
5 changed files
with
166 additions
and
9 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
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,51 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed 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 typing import Any, Dict, List | ||
|
||
from\ | ||
nvflare.fuel.f3.drivers.base_driver \ | ||
import \ | ||
BaseDriver | ||
|
||
from nvflare.fuel.f3.drivers.connector_info import ConnectorInfo \ | ||
|
||
from nvflare.fuel.f3.drivers.driver_params import DriverCap | ||
|
||
|
||
class WarpDriver(BaseDriver): | ||
"""A dummy driver to test custom driver loading""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
@staticmethod | ||
def supported_transports() -> List[str]: | ||
return ["warp"] | ||
|
||
@staticmethod | ||
def capabilities() -> Dict[str, Any]: | ||
return {DriverCap.SEND_HEARTBEAT.value: True, DriverCap.SUPPORT_SSL.value: False} | ||
|
||
def listen(self, connector: ConnectorInfo): | ||
self.connector = connector | ||
|
||
def connect(self, connector: ConnectorInfo): | ||
self.connector = connector | ||
|
||
def shutdown(self): | ||
self.close_all() | ||
|
||
@staticmethod | ||
def get_urls(scheme: str, resources: dict) -> (str, str): | ||
return "warp:enterprise" |
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,41 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed 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 pytest | ||
|
||
from nvflare.job_config.base_app_config import BaseAppConfig | ||
|
||
|
||
class TestBaseAppConfig: | ||
def setup_method(self, method): | ||
self.app_config = BaseAppConfig() | ||
|
||
def test_add_relative_script(self): | ||
cwd = os.getcwd() | ||
with tempfile.NamedTemporaryFile(dir=cwd, suffix=".py") as temp_file: | ||
script = os.path.basename(temp_file.name) | ||
self.app_config.add_ext_script(script) | ||
assert script in self.app_config.ext_scripts | ||
|
||
def test_add_ext_script(self): | ||
script = "/scripts/sample.py" | ||
self.app_config.add_ext_script(script) | ||
assert script in self.app_config.ext_scripts | ||
|
||
def test_add_ext_script_error(self): | ||
script = "scripts/sample.py" | ||
with pytest.raises(Exception): | ||
self.app_config.add_ext_script(script) |
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,34 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed 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 | ||
|
||
from nvflare.job_config.fed_job_config import FedJobConfig | ||
|
||
|
||
class TestFedJobConfig: | ||
def test_locate_imports(self): | ||
job_config = FedJobConfig(job_name="job_name", min_clients=1) | ||
cwd = os.path.dirname(__file__) | ||
source_file = os.path.join(cwd, "../data/job_config/sample_code.data") | ||
expected = [ | ||
"from typing import Any, Dict, List", | ||
"from nvflare.fuel.f3.drivers.base_driver import BaseDriver", | ||
"from nvflare.fuel.f3.drivers.connector_info import ConnectorInfo ", | ||
"from nvflare.fuel.f3.drivers.driver_params import DriverCap", | ||
] | ||
with open(source_file, "r") as sf: | ||
with tempfile.NamedTemporaryFile(dir=cwd, suffix=".py") as dest_file: | ||
imports = list(job_config.locate_imports(sf, dest_file=dest_file.name)) | ||
assert imports == expected |