Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy-loading the required modules to avoid loading the global config #10

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/aiida_pythonjob/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from aiida import orm

from .data.serializer import serialize_to_aiida_nodes
from .utils import build_function_data, get_or_create_code


Expand All @@ -23,8 +22,8 @@ def prepare_pythonjob_inputs(
function_data: dict | None = None,
**kwargs: Any,
) -> Dict[str, Any]:
pass
"""Prepare the inputs for PythonJob"""
from .data.serializer import serialize_to_aiida_nodes

if function is None and function_data is None:
raise ValueError("Either function or function_data must be provided")
Expand Down
3 changes: 1 addition & 2 deletions src/aiida_pythonjob/parsers/pythonjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from aiida.engine import ExitCode
from aiida.parsers.parser import Parser

from aiida_pythonjob.data.serializer import general_serializer


class PythonJobParser(Parser):
"""Parser for an `PythonJob` job."""
Expand Down Expand Up @@ -95,6 +93,7 @@ def find_output(self, name):

def serialize_output(self, result, output):
"""Serialize outputs."""
from aiida_pythonjob.data.serializer import general_serializer

name = output["name"]
if output.get("identifier", "Any").upper() == "NAMESPACE":
Expand Down
5 changes: 3 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import aiida
from aiida_pythonjob.data import general_serializer
from aiida_pythonjob.utils import get_required_imports


def test_typing():
"""Test function with typing."""
from typing import List

from aiida_pythonjob.utils import get_required_imports
from numpy import array

def generate_structures(
Expand Down Expand Up @@ -57,6 +56,8 @@ def test_atoms_data():


def test_only_data_with_value():
from aiida_pythonjob.data import general_serializer

try:
general_serializer(aiida.orm.List([1]))
except ValueError as e:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from aiida import orm
from aiida.cmdline.utils.common import get_workchain_report
from aiida.common.links import LinkType
from aiida_pythonjob.parsers import PythonJobParser


def create_retrieved_folder(result: dict, output_filename="results.pickle"):
Expand All @@ -32,6 +31,8 @@ def create_process_node(result: dict, function_data: dict, output_filename: str


def create_parser(result, function_data, output_filename="results.pickle"):
from aiida_pythonjob.parsers import PythonJobParser

node = create_process_node(result, function_data, output_filename=output_filename)
parser = PythonJobParser(node=node)
return parser
Expand Down
Loading