-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor code outside of endpoints for reusability
- Loading branch information
Showing
6 changed files
with
156 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ RUN pip install "." | |
|
||
ENTRYPOINT [ "python", "-m", "eidos" ] | ||
|
||
EXPOSE 6004 | ||
|
||
CMD [ "server" ] |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build" | |
|
||
[project] | ||
name = "eidos" | ||
version = "0.99.0" | ||
version = "0.99.1" | ||
authors = [ | ||
{ name="José F. Aldana Martín", email="[email protected]" }, | ||
] | ||
|
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import importlib | ||
|
||
from eidos.logs import get_logger | ||
|
||
logger = get_logger() | ||
|
||
|
||
def import_function(module: str) -> callable: | ||
"""Import a function from a module. | ||
Args: | ||
module (str): The module name, e.g., "pprint.pprint" | ||
Returns: | ||
callable: The function object | ||
""" | ||
|
||
if "." not in module: | ||
raise ValueError("You can't import built-in modules") | ||
|
||
try: | ||
module_name, function_name = module.rsplit(".", 1) | ||
module = importlib.import_module(module_name) | ||
try: | ||
function_ = getattr(module, function_name) | ||
return function_ | ||
except AttributeError as err: | ||
logger.error( | ||
f"Error: Function '{function_name}' " | ||
f"not found in module '{module_name}'." | ||
) | ||
raise err | ||
except (ValueError, ImportError) as err: | ||
logger.error( | ||
"Error: Unable to import module or " | ||
f"function from the provided name: '{module}'" | ||
) | ||
raise err |