Skip to content

Feature/SOF-7755 Add Python codebase#95

Merged
VsevolodX merged 35 commits intomainfrom
feature/SOF-7755
Dec 2, 2025
Merged

Feature/SOF-7755 Add Python codebase#95
VsevolodX merged 35 commits intomainfrom
feature/SOF-7755

Conversation

@VsevolodX
Copy link
Member

No description provided.

"""mat3ra namespace package."""
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this in every py pacakge we have so that we can install from local codebase when we run tests, and have installed packages resolved too. did this in Made, Mode


@property
def extra_data_key(self) -> str:
name_str = self.name.value if hasattr(self.name, 'value') else str(self.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a getter name_str

[ContextProviderNameEnum.QENEBInputDataManager]: mockConfig,
[ContextProviderNameEnum.VASPInputDataManager]: mockConfig,
[ContextProviderNameEnum.VASPNEBInputDataManager]: mockConfig,
[ContextProviderNameEnum.NWChemInputDataManager]: mockConfig,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this and above file changes

assert template.content == "&CONTROL\n/"
assert template.applicationName == "espresso"
assert template.executableName == "pw.x"
assert len(template.context_providers) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use assert deep almost equal

json_schema={"type": "object"},
)
assert provider.is_using_jinja_variables is True
assert provider.json_schema == {"type": "object"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this file is not needed

assert app_restored.name == app.name
assert exe_restored.name == executable.name
assert tmpl_restored.name == template.name
assert flv_restored.name == flavor.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Python implementation of the ADE (Application DEfinitions) codebase alongside the existing JavaScript/TypeScript implementation, enabling Python developers to work with application definitions, templates, executables, and flavors.

  • Implements Python versions of core ADE classes: Application, Executable, Flavor, Template, and ContextProvider
  • Adds comprehensive test coverage for all new Python classes using pytest
  • Updates project configuration to support both JavaScript and Python development workflows

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/py/mat3ra/ade/init.py Replaces sample function with proper module exports for ADE classes
src/py/mat3ra/init.py Configures mat3ra as a namespace package using pkgutil
src/py/mat3ra/ade/application.py Implements Application class with material usage detection and short name handling
src/py/mat3ra/ade/executable.py Implements Executable class for application executables
src/py/mat3ra/ade/flavor.py Implements Flavor and FlavorInput classes for executable flavors
src/py/mat3ra/ade/template.py Implements Template class with Jinja2 rendering and context provider support
src/py/mat3ra/ade/context/context_provider.py Implements ContextProvider base class for template context management
src/py/mat3ra/ade/context/jinja_context_provider.py Implements JinjaContextProvider extending ContextProvider
src/py/mat3ra/ade/context/json_schema_data_provider.py Implements JSONSchemaDataProvider with JSON schema support
tests/py/test_template.py Adds comprehensive tests for Template class functionality
tests/py/test_sample.py Removes obsolete sample test file
tests/py/test_flavor.py Adds tests for Flavor and FlavorInput classes
tests/py/test_executable.py Adds tests for Executable class
tests/py/test_context_provider.py Adds tests for ContextProvider functionality
tests/py/test_application.py Adds tests for Application class including material usage checks
pyproject.toml Adds Python dependencies (pydantic, jinja2, mat3ra packages) and test requirements
README.md Documents Python installation, development commands, and testing instructions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 89 to 91
print(f"Template is not compiled: {e}")
print(f"content: {self.content}")
print(f"_clean_rendering_context: {self._clean_rendering_context(rendering_context)}")
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using print() for error logging is not a best practice. Consider using Python's logging module instead for proper error handling and control over log levels. This would allow users to configure logging behavior and integrate with existing logging infrastructure. Example:

import logging
logger = logging.getLogger(__name__)

# Then in the except block:
logger.error(f"Template is not compiled: {e}")
logger.debug(f"content: {self.content}")
logger.debug(f"_clean_rendering_context: {self._clean_rendering_context(rendering_context)}")

Copilot uses AI. Check for mistakes.
def _get_rendering_context(
self, external_context: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
provider_context = external_context or {}
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provider_context parameter is defined but never used in this method. It's assigned at line 72 but not passed to _get_data_from_providers_for_rendering_context() at line 75. This suggests either the parameter should be removed, or it should be passed to the method call if it's meant to provide context to providers.

Copilot uses AI. Check for mistakes.


def test_template_to_dict():
config = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be used from top

pyproject.toml Outdated
"pydantic>=2.0",
"mat3ra-esse",
"mat3ra-code @ git+https://github.com/Exabyte-io/code.git@c2ddf37759be80a50415af2a68096ab82c9683e5",
"jinja2>=3.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be done through mat3ra-utils[extra]

cleaned_context = self._clean_rendering_context(rendering_context)
rendered = template.render(cleaned_context)
self.rendered = rendered or self.content
except TemplateError as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be render_jinja_with_error_handling in utils

def context_providers(self) -> List[ContextProvider]:
return self.contextProviders

@context_providers.setter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a separate task to deal with case conversion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned.pop("job", None)
return cleaned

def _get_data_from_providers_for_rendering_context(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it non-private and test

result: Dict[str, Any] = {}
for provider in self.context_providers:
context = provider.yield_data_for_rendering(provider_context)
for key, value in context.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's isolate to context provider itself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment

@github-actions
Copy link

github-actions bot commented Dec 2, 2025

Coverage after merging feature/SOF-7755 into main will be

89.26%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src/js
   ApplicationRegistry.ts92.12%88.14%100%92.77%137, 147–149, 152–154, 168, 168, 73–74, 78, 94
   application.ts100%100%100%100%
   applicationMixin.ts100%100%100%100%
   executable.ts100%100%100%100%
   executableMixin.ts100%100%100%100%
   flavor.ts100%100%100%100%
   flavorMixin.ts100%100%100%100%
   index.ts0%100%0%0%1, 10–11, 13, 16–19, 2, 20–29, 3–9
   template.ts100%100%100%100%
   templateMixin.ts98.13%90.91%100%100%103, 103
src/js/context
   ContextProvider.ts96.83%83.33%100%100%117, 81
   ContextProviderRegistryContainer.ts100%100%100%100%
   JSONSchemaDataProvider.ts100%100%100%100%
   JSONSchemaFormDataProvider.ts100%100%100%100%
   JinjaContextProvider.ts100%100%100%100%

@VsevolodX VsevolodX merged commit 6daccd9 into main Dec 2, 2025
10 checks passed
@VsevolodX VsevolodX deleted the feature/SOF-7755 branch December 2, 2025 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants