Skip to content

Commit

Permalink
SFA: Improve entrypoint specification parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 19, 2025
1 parent 982271b commit 774bc77
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pueblo/sfa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@


class InvalidTarget(Exception):
"""
Raised when the target specification format is invalid.
This exception is raised when the target string does not conform to the expected
format of either a module path (e.g., 'acme.app:foo') or a file path
(e.g., '/path/to/acme/app.py').
"""

pass


Expand All @@ -37,6 +45,7 @@ def from_spec(cls, spec: str, default_property=None):
:return:
"""
is_url = False
prop = None
if cls.is_valid_url(spec):
# Decode launch target location address from URL.
# URL: https://example.org/acme/app.py#foo
Expand All @@ -56,9 +65,10 @@ def from_spec(cls, spec: str, default_property=None):
prop = target_fragments[1]
else:
target = target_fragments[0]
if default_property is None:
raise ValueError("Property can not be discovered, and no default property was supplied")
prop = default_property

prop = prop or default_property
if not prop:
raise ValueError("Property can not be discovered, and no default property was supplied")

return cls(target=target, property=prop, is_url=is_url)

Expand Down Expand Up @@ -107,6 +117,10 @@ def path(self) -> Path:
raise ValueError("Path not defined")
return self._path

@property
def entrypoint(self) -> t.Union[t.Callable[..., t.Any], None]:
return self._entrypoint

def run(self, *args, **kwargs):
return t.cast(t.Callable, self._entrypoint)(*args, **kwargs)

Expand Down

0 comments on commit 774bc77

Please sign in to comment.