Project management#

This section contains the classes related to Scade One projects.

from ansys.scadeone.core import ScadeOne, ProjectFile

with ScadeOne() as app:
  project = app.load_project("project.sproj")
  ...

Project documentation#

This section gives the description of project class which is used to manage Scade One projects.

Projects are used by ScadeOne objects, and projects have a link to the application. To deal with the cross-links, we use the IProject interface.

class ansys.scadeone.core.project.IProject#

Bases: ABC

Interface class

class ansys.scadeone.core.project.Project(app: IScadeOne, project: ProjectStorage, is_new: bool = False)#

Bases: IProject, ProjectCreator

This class is the entry point of a project.

Parameters:
appScadeOne

Application object.

projectProjectStorage

Project storage object.

is_newbool, optional

True if the project is new, that is, it has not been loaded from a file.

add_test_module(name: str) TestModule#

Create a test module and add it to the model.

Parameters:
name: str

Module name.

Returns:
TestModule

TestModule object.

check_exists(parent_path: Path | str) bool#

Return true if any of the project modules or sproj already exists

Warning

Dependencies may not be checked.

dependencies(all=False) List[Project]#

Project dependencies as list of Projects.

If all is True, include recursively dependencies of dependencies.

A dependency occurs only once.

get_job(name: str) Job | None#

Get a job from its name.

load_jobs() List[Job]#

(Re)load and return all the jobs of a project.

save() None#

Save the following:

  • Project modules

  • Project dependencies

  • Project resources

  • sproj version

Two cases:

  • new project, saving to the .sproj location

  • loaded project, saving and replacing old files

set_modified() None#

Set the project as modified.

swan_sources(all=False) List[SwanFile]#

Return all Swan sources from project.

If all is True, include also sources from project dependencies.

Returns:
list[SwanFile]

List of all SwanFile objects.

property app: IScadeOne#

Access to current Scade One application.

property directory: Path | None#

Project directory: Path if storage is a file, else None.

property jobs: List[Job]#

Return job files of the project.

property model: Model#

Access to the project model.

property modules: List[Module]#

Loaded modules from the model

property resources: List[Resource]#

Project resources.

property storage: ProjectStorage#

Project storage.

Project items#

A project can manipulate different items saved using the storage module. The API handles projects and Swan sources (.swan and .swani files).

Project file#

class ansys.scadeone.core.common.storage.ProjectFile(file: str | Path)#

Bases: FileStorage, ProjectStorage

Project as a file.

content() str#

Content of file.

dump(**kw) JSONStorage#

Uses self.json to update storage content and returns self.

See json.dumps() for detailed interface.

exists() bool#

True when file exists.

load(**kw) JSONStorage#

Loads content of JSON data into json property and returns self.

See json.loads() for detailed interface.

set_content(data: str) None#

Sets content and write it to underlying file.

property json: dict#

JSON content. Any modification is propagated to the underlying JSON object.

property path: Path#

Saved path.

property source: str#

Source origin: file name, string, etc.

Swan code#

class ansys.scadeone.core.common.storage.SwanFile(file: str | Path)#

Bases: FileStorage, SwanStorage

Swan code within a file.

Parameters:
filePath

File containing the Swan source.

check_swan_version() bool#

Check Swan version information.

Raises:
ScadeOneException

When version information is missing or invalid.

check_swant_version() bool#

Check Swan test harness version information.

Raises:
ScadeOneException

When version information is missing or invalid.

content() str#

Content of file.

exists() bool#

True when file exists.

static extract_version(source: str) dict | None#

Extracts version information from a Swan source.

Parameters:
sourcestr

Version information as a string.

Returns:
Union[dict, None]

Either the version information as a dictionary, or None if no version found.

set_content(data: str) None#

Sets content and write it to underlying file.

property is_interface: bool#

True when file is an interface code.

property is_module: bool#

True when file is a module code.

property is_test: bool#

True when file is a test code.

property name: str#

Returns basename of source file (no suffix).

property path: Path#

Saved path.

property source: str#

Source origin: file name, string, etc.

property version: dict | None#

Swan version information.

Resources#

A project can also use Resource files. Resource are categorized in 3 different ResourceKind, each supports one file format:

  • Header: .h files

  • Source: .c files

  • Simulation data: .sd files

class ansys.scadeone.core.project.Resource(kind: ResourceKind, path: Path, key: str | None = None)#

Bases: object

Project resource.

Parameters:
kindResourceKind

Kind of the resource (header, source, simulation data).

pathPath

Path to the resource.

keystr, optional

Key of the resource (simulation data only).

property key: str | None#

Key of the resource (simulation data only).

property kind: ResourceKind#

Kind of the resource.

property path: Path#

Path to the resource.

class ansys.scadeone.core.project.ResourceKind(value)#

Bases: Enum

Project resource kind.

file_extension() str#

Returns expected file extension for the resource kind.

static str_to_kind(kind_str: str) ResourceKind#

Converts sproj kind string to a ResourceKind enum.

HEADER_FILE = 1#

Header file

SIMULATION_DATA = 3#

Simulation data file

SOURCE_FILE = 2#

Source file