Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Complete pyi generation (#103)
Browse files Browse the repository at this point in the history
* Complete pyi generation

* Complete pyi generation

* Apply automatic changes

* Complete pyi generation

* Apply automatic changes

---------

Co-authored-by: jrobinAV <[email protected]>
  • Loading branch information
jrobinAV and jrobinAV authored Oct 18, 2023
1 parent caa269d commit 4abc197
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
62 changes: 61 additions & 1 deletion src/taipy/config/config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import json
from typing import Any, Callable, Dict, List, Optional, Union
from datetime import timedelta

from taipy.core.config import DataNodeConfig, JobConfig, ScenarioConfig, TaskConfig
from taipy.core.config import DataNodeConfig, JobConfig, ScenarioConfig, TaskConfig, MigrationConfig, CoreSection

from .checker.issue_collector import IssueCollector
from .common._classproperty import _Classproperty
Expand Down Expand Up @@ -699,6 +700,7 @@ class Config:
db_password: Optional[str] = None,
db_host: Optional[str] = None,
db_port: Optional[int] = None,
db_driver: Optional[str] = None,
db_extra_args: Optional[Dict[str, Any]] = None,
scope: Optional[Scope] = None,
validity_period: Optional[timedelta] = None,
Expand All @@ -721,6 +723,7 @@ class Config:
The default value is "localhost".
db_port (Optional[int]): The database port.<br/>
The default value is 27017.
db_driver (Optional[str]): The database driver.
db_extra_args (Optional[dict[str, any]]): A dictionary of additional arguments to be passed
into database connection string.
scope (Optional[Scope^]): The scope of the Mongo collection data node configuration.<br/>
Expand Down Expand Up @@ -817,3 +820,60 @@ class Config:
The new job execution configuration.
"""

@staticmethod
def add_migration_function(
target_version: str,
config: Union[Section, str],
migration_fct: Callable,
**properties,
):
"""Add a migration function for a Configuration to migrate entities to the target version.
Parameters:
target_version (str): The production version that entities are migrated to.
config (Union[Section, str]): The configuration or the `id` of the config that needs to migrate.
migration_fct (Callable): Migration function that takes an entity as input and returns a new entity
that is compatible with the target production version.
**properties (Dict[str, Any]): A keyworded variable length list of additional arguments.
Returns:
`MigrationConfig^`: The Migration configuration.
"""

@staticmethod
def configure_core(
root_folder: Optional[str] = None,
storage_folder: Optional[str] = None,
repository_type: Optional[str] = None,
repository_properties: Optional[Dict[str, Union[str, int]]] = None,
read_entity_retry: Optional[int] = None,
mode: Optional[str] = None,
version_number: Optional[str] = None,
force: Optional[bool] = None,
**properties,
) -> "CoreSection":
"""Configure the Core service.
Parameters:
root_folder (Optional[str]): Path of the base folder for the taipy application.
The default value is "./taipy/"
storage_folder (Optional[str]): Folder name used to store Taipy data. The default value is ".data/".
It is used in conjunction with the `root_folder` field. That means the storage path is
<root_folder><storage_folder> (The default path is "./taipy/.data/").
repository_type (Optional[str]): The type of the repository to be used to store Taipy data.
The default value is "filesystem".
repository_properties (Optional[Dict[str, Union[str, int]]]): A dictionary of additional properties
to be used by the repository.
read_entity_retry (Optional[int]): Number of retries to read an entity from the repository
before return failure. The default value is 3.
mode (Optional[str]): Indicates the mode of the version management system.
Possible values are *"development"*, *"experiment"*, or *"production"*.
version_number (Optional[str]): The string identifier of the version.
In development mode, the version number is ignored.
force (Optional[bool]): If True, Taipy will override a version even if the configuration
has changed and run the application.
**properties (Dict[str, Any]): A keyworded variable length list of additional arguments configure the
behavior of the `Core^` service.
Returns:
The Core configuration.
"""

6 changes: 6 additions & 0 deletions stubs/generate_pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def _build_entity_config_pyi(base_pyi, filename, entity_map):
functions[f.name] = f.lineno
elif "_set_default" in f.name and not f.name.startswith("__"):
functions[f.name] = f.lineno
elif "_add" in f.name and not f.name.startswith("__"):
functions[f.name] = f.lineno

for k, v in functions.items():
begin_line, end_line = _get_function_delimiters(v - 1, lines)
Expand Down Expand Up @@ -145,6 +147,8 @@ def _build_header(filename):
job_filename = "taipy-core/src/taipy/core/config/job_config.py"
scenario_filename = "taipy-core/src/taipy/core/config/scenario_config.py"
task_filename = "taipy-core/src/taipy/core/config/task_config.py"
migration_filename = "taipy-core/src/taipy/core/config/migration_config.py"
core_filename = "taipy-core/src/taipy/core/config/core_section.py"

entities_map, property_map = _generate_entity_and_property_maps(config_init)
pyi = _build_header(header_file)
Expand All @@ -154,6 +158,8 @@ def _build_header(filename):
pyi = _build_entity_config_pyi(pyi, dn_filename, entities_map["DataNodeConfig"])
pyi = _build_entity_config_pyi(pyi, task_filename, entities_map["TaskConfig"])
pyi = _build_entity_config_pyi(pyi, job_filename, entities_map["JobConfig"])
pyi = _build_entity_config_pyi(pyi, migration_filename, entities_map["MigrationConfig"])
pyi = _build_entity_config_pyi(pyi, core_filename, entities_map["CoreSection"])

with open("src/taipy/config/config.pyi", "w") as f:
f.writelines(pyi)
3 changes: 2 additions & 1 deletion stubs/pyi_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import json
from typing import Any, Callable, Dict, List, Optional, Union
from datetime import timedelta

from taipy.core.config import DataNodeConfig, JobConfig, ScenarioConfig, TaskConfig
from taipy.core.config import DataNodeConfig, JobConfig, ScenarioConfig, TaskConfig, MigrationConfig, CoreSection

from .checker.issue_collector import IssueCollector
from .common._classproperty import _Classproperty
Expand Down

0 comments on commit 4abc197

Please sign in to comment.