Skip to content

Commit 3f9e19e

Browse files
authored
Back out all logic to support component lookup from other files (D75496839 and D82132556)
Differential Revision: D82492135 Pull Request resolved: #1117
1 parent dca99de commit 3f9e19e

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

torchx/specs/finder.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -278,25 +278,12 @@ def _get_validation_errors(
278278
linter_errors = validate(path, function_name, validators)
279279
return [linter_error.description for linter_error in linter_errors]
280280

281-
def _get_path_to_function_decl(
282-
self, function: Callable[..., Any] # pyre-ignore[2]
283-
) -> str:
284-
"""
285-
Attempts to return the path to the file where the function is implemented.
286-
This can be different from the path where the function is looked up, for example if we have:
287-
my_component defined in some_file.py, imported in other_file.py
288-
and the component is invoked as other_file.py:my_component
289-
"""
290-
# Unwrap decorated functions to get the original function
291-
unwrapped_function = inspect.unwrap(function)
292-
path_to_function_decl = inspect.getabsfile(unwrapped_function)
293-
if path_to_function_decl is None or not os.path.isfile(path_to_function_decl):
294-
return self._filepath
295-
return path_to_function_decl
296-
297281
def find(
298282
self, validators: Optional[List[ComponentFunctionValidator]]
299283
) -> List[_Component]:
284+
validation_errors = self._get_validation_errors(
285+
self._filepath, self._function_name, validators
286+
)
300287

301288
file_source = read_conf_file(self._filepath)
302289
namespace = copy.copy(globals())
@@ -309,12 +296,6 @@ def find(
309296
)
310297
app_fn = namespace[self._function_name]
311298
fn_desc, _ = get_fn_docstring(app_fn)
312-
313-
func_path = self._get_path_to_function_decl(app_fn)
314-
validation_errors = self._get_validation_errors(
315-
func_path, self._function_name, validators
316-
)
317-
318299
return [
319300
_Component(
320301
name=f"{self._filepath}:{self._function_name}",

torchx/specs/test/finder_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
get_components,
3030
ModuleComponentsFinder,
3131
)
32-
from torchx.specs.test.components.a import comp_a
3332
from torchx.util.test.entrypoints_test import EntryPoint_from_text
3433
from torchx.util.types import none_throws
3534

@@ -239,10 +238,6 @@ def test_get_component_invalid(self) -> None:
239238
with self.assertRaises(ComponentValidationException):
240239
get_component(f"{current_file_path()}:invalid_component")
241240

242-
def test_get_component_imported_from_other_file(self) -> None:
243-
component = get_component(f"{current_file_path()}:comp_a")
244-
self.assertListEqual([], component.validation_errors)
245-
246241

247242
class GetBuiltinSourceTest(unittest.TestCase):
248243
def setUp(self) -> None:

0 commit comments

Comments
 (0)