agi_env API

This is a module share between core/agi-core and gui/agilab to set all the path required by both

Usage Example

Instanciation

from agi_env import AgiEnv

app_env = AgiEnv(active_app=Path('/"your agilab homedir"/apps/mycode_project'), install_type=1, verbose=True)

Reference

Packages diagram for agi-env
class agi_env.agi_env.AgiEnv(active_app=None, install_type=None, verbose=None, debug=False, python_variante='')[source]

Bases: object

EXTRA_INDEX_URL = 'https://pypi.org/simple'
GUI_NROW = None
GUI_SAMPLING = None
INDEX_URL = 'https://test.pypi.org/simple'
__init__(active_app=None, install_type=None, verbose=None, debug=False, python_variante='')[source]
active(target, install_type)[source]
app = None
apps_dir = None
benchmark = None
change_active_app(app, install_type=1)[source]
check_args(target_args_class, target_args)[source]
static check_internet()[source]
clone_directory(source_dir, dest_dir, rename_map, spec, source_root)[source]

Recursively copy + rename directories, files, and contents, applying renaming only on exact path segments.

clone_project(target_project, dest_project)[source]

Clone a project by copying files and directories, applying renaming, then cleaning up any leftovers.

Parameters:
  • target_project – Path under self.apps_dir (e.g. Path(“flight_project”))

  • dest_project – Path under self.apps_dir (e.g. Path(“tata_project”))

copy_existing_projects(src_apps, dst_apps)[source]
copy_missing(src, dst, max_workers=8)[source]
create_junction_windows(dest)[source]

Create a directory junction on Windows.

Parameters:
  • source (Path) – The target directory path.

  • dest (Path) – The destination junction path.

create_rename_map(target_project, dest_project)[source]

Create a mapping of old → new names for cloning. Includes project names, top-level src folders, worker folders, in-file identifiers and class names.

Return type:

dict

Create a symbolic link on Windows, handling permissions and types.

Parameters:
  • source (Path) – Source directory path.

  • dest (Path) – Destination symlink path.

debug = False
extract_base_info(base, import_mapping)[source]
get_base_classes(module_path, class_name)[source]
get_base_worker_cls(module_path, class_name)[source]
get_full_attribute_name(node)[source]
get_import_mapping(source)[source]
get_modules(target=None)[source]
get_projects(path)[source]
handle_venv_directory(source_venv, dest_venv)[source]

Create a symbolic link for the .venv directory instead of copying it.

Parameters:
  • source_venv (Path) – Source .venv directory path.

  • dest_venv (Path) – Destination .venv symbolic link path.

has_admin_rights()[source]

Check if the current process has administrative rights on Windows.

Returns:

True if admin, False otherwise.

Return type:

bool

has_rapids_hw = None
humanize_validation_errors(error)[source]
init_done = False
init_envars_app(envars)[source]
install_type = None
static is_local(ip)[source]
Parameters:

ip

Returns:

is_valid_ip(ip)[source]
Return type:

bool

is_worker_env = False
static locate_agilab_installation(verbose=False)[source]
static log_info(line)[source]
log_remote_line(ip, line)[source]
logger = None
static mode2int(mode)[source]
mode2str(mode)[source]
pyvers_worker = None
static read_agilab_path(verbose=False)[source]
read_gitignore(gitignore_path)[source]
Return type:

PathSpec

replace_content(txt, rename_map)[source]
Return type:

str

async static run(cmd, venv, cwd=None, timeout=None, wait=True, log_callback=None)[source]

Run a shell command inside a virtual environment. Streams stdout/stderr live without blocking (Windows-safe). Returns the full stdout string.

async run_agi(code, log_callback=None, venv=None, type=None)[source]

Asynchronous version of run_agi for use within an async context.

async static run_async(cmd, venv=None, cwd=None, timeout=None, log_callback=None)[source]

Run a shell command asynchronously inside a virtual environment. Streams stdout/stderr live with sensible levels (packaging-aware). Returns the last non-empty line among stderr (preferred) then stdout. Raises on non-zero exit (logs stderr tail).

property scheduler_ip_address
set_apps_dir(apps_dir)[source]
set_cluster_credentials(credentials)[source]

Set the AGI_CREDENTIALS environment variable.

set_env_var(value)[source]
set_install_type()[source]
set_openai_api_key(api_key)[source]

Set the OPENAI_API_KEY environment variable.

snippet_tail = 'asyncio.get_event_loop().run_until_complete(main())'
target = None
unzip_data(archive_path, extract_to=None)[source]
update_pyproject()[source]
update_pyproject_enduser()[source]
uv = None
verbose = None
class agi_env.agi_env.ContentRenamer(rename_map)[source]

Bases: NodeTransformer

A class that renames identifiers in an abstract syntax tree (AST). .. attribute:: rename_map

A mapping of old identifiers to new identifiers.

type:

dict

__init__(rename_map)[source]

Initialize the ContentRenamer with the rename_map.

Parameters:

rename_map (dict) – Mapping of old names to new names.

generic_visit(node)

Called if no explicit visitor function exists for a node.

visit(node)

Visit a node.

visit_AnnAssign(node)[source]

Visit and process an AnnAssign node in an abstract syntax tree.

Parameters:
  • self – The AST visitor object.

  • node – The AnnAssign node to be visited.

Returns:

The visited AnnAssign node.

Return type:

AnnAssign

visit_Assign(node)[source]

Visit and process an assignment node.

Parameters:
  • self – The instance of the visitor class.

  • node – The assignment node to be visited.

Returns:

The visited assignment node.

Return type:

ast.Node

visit_Attribute(node)[source]

Visit and potentially rename an attribute in a node.

Parameters:

node – A node representing an attribute.

Returns:

The visited node with potential attribute renamed.

Return type:

node

Raises:

None.

visit_ClassDef(node)[source]

Visit and potentially rename a ClassDef node.

Parameters:

node (ast.ClassDef) – The ClassDef node to visit.

Returns:

The potentially modified ClassDef node.

Return type:

ast.ClassDef

visit_Constant(node)
visit_For(node)[source]

Visit and potentially rename the target variable in a For loop node.

Parameters:

node (ast.For) – The For loop node to visit.

Returns:

The modified For loop node.

Return type:

ast.For

Note

This function may modify the target variable in the For loop node if it exists in the rename map.

visit_FunctionDef(node)[source]

Rename a function node based on a provided mapping.

Parameters:

node (ast.FunctionDef) – The function node to be processed.

Returns:

The function node with potential name change.

Return type:

ast.FunctionDef

visit_Global(node)[source]

Visit and potentially rename global variables in the AST node.

Parameters:
  • self – The instance of the class that contains the renaming logic.

  • node – The AST node to visit and potentially rename global variables.

Returns:

The modified AST node with global variable names potentially renamed.

Return type:

AST node

visit_Import(node)[source]

Rename imported modules in ‘import module’ statements.

Parameters:

node (ast.Import) – The import node.

visit_ImportFrom(node)[source]

Rename modules and imported names in ‘from module import name’ statements.

Parameters:

node (ast.ImportFrom) – The import from node.

visit_Name(node)[source]

Visit and potentially rename a Name node in the abstract syntax tree.

Parameters:
  • self – The current object instance.

  • node – The Name node in the abstract syntax tree.

Returns:

The modified Name node after potential renaming.

Return type:

ast.Node

Note

This function modifies the Name node in place.

Raises:

None

visit_arg(node)[source]

Visit and potentially rename an argument node.

Parameters:
  • self – The instance of the class.

  • node – The argument node to visit and possibly rename.

Returns:

The modified argument node.

Return type:

ast.AST

Notes

Modifies the argument node in place if its name is found in the rename map.

Raises:

None.

visit_nonlocal(node)[source]

Visit and potentially rename nonlocal variables in the AST node.

Parameters:
  • self – An instance of the class containing the visit_nonlocal method.

  • node – The AST node to visit and potentially modify.

Returns:

The modified AST node after visiting and potentially renaming nonlocal variables.

Return type:

ast.AST

agi_env.agi_env.is_packaging_cmd(cmd)[source]
Return type:

bool

agi_env.agi_env.normalize_path(path)[source]
agi_env.agi_env.parse_level(line, default_level)[source]
agi_env.agi_env.strip_time_level_prefix(line)[source]
Return type:

str

Classes diagram for agi_env