-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Path Resolver and Validator (#55)
The function "which" at aws_lambda_builders/utils.py was copied from https://github.com/python/cpython/blob/3.7/Lib/shutil.py SPDX-License-Identifier: Python-2.0 Copyright 2019 by the Python Software Foundation
- Loading branch information
Showing
32 changed files
with
493 additions
and
159 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
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
AWS Lambda Builders | ||
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
The function "which" at aws_lambda_builders/utils.py was copied from https://github.com/python/cpython/blob/3.7/Lib/shutil.py | ||
SPDX-License-Identifier: Python-2.0 | ||
Copyright 2019 by the Python Software Foundation |
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,21 @@ | ||
""" | ||
Class containing resolved path of binary given a validator and a resolver and the name of the binary. | ||
""" | ||
|
||
|
||
class BinaryPath(object): | ||
|
||
def __init__(self, resolver, validator, binary, binary_path=None): | ||
self.resolver = resolver | ||
self.validator = validator | ||
self.binary = binary | ||
self._binary_path = binary_path | ||
self.path_provided = True if self._binary_path else False | ||
|
||
@property | ||
def binary_path(self): | ||
return self._binary_path | ||
|
||
@binary_path.setter | ||
def binary_path(self, binary_path): | ||
self._binary_path = binary_path |
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,28 @@ | ||
""" | ||
Basic Path Resolver that looks for the executable by runtime first, before proceeding to 'language' in PATH. | ||
""" | ||
|
||
from aws_lambda_builders.utils import which | ||
|
||
|
||
class PathResolver(object): | ||
|
||
def __init__(self, binary, runtime): | ||
self.binary = binary | ||
self.runtime = runtime | ||
self.executables = [self.runtime, self.binary] | ||
|
||
def _which(self): | ||
exec_paths = [] | ||
for executable in [executable for executable in self.executables if executable is not None]: | ||
paths = which(executable) | ||
exec_paths.extend(paths) | ||
|
||
if not exec_paths: | ||
raise ValueError("Path resolution for runtime: {} of binary: " | ||
"{} was not successful".format(self.runtime, self.binary)) | ||
return exec_paths | ||
|
||
@property | ||
def exec_paths(self): | ||
return self._which() |
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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
""" | ||
No-op validator that does not validate the runtime_path for a specified language. | ||
""" | ||
|
||
import logging | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class RuntimeValidator(object): | ||
|
||
def __init__(self, runtime): | ||
self.runtime = runtime | ||
self._runtime_path = None | ||
|
||
def validate(self, runtime_path): | ||
self._runtime_path = runtime_path | ||
return runtime_path |
Oops, something went wrong.