Main Content

polyspace.project.StaticAnalysisConfigurationRef Class

R2026b

Namespace: polyspace.project

(Python) Manage references from project to external static analysis configurations

Since R2026a

Description

This Python® class contains information about a static analysis configuration that is saved in a separate file, referenced by a Polyspace® Platform project. Polyspace supports two file formats for external configurations: the native JSON-based format (.pscfg) and the human-readable TOML format (.toml.pscfg). Saving your static analysis configurations in external files and referencing those files from one or more projects enables you to create a modular project structure that improves sharing and version control workflows. For more information about project structure, see Modularize Project by Using External Configurations, Test References, and External Stub Files.

To work with external static analysis configurations, use this class, which contains the name of the static analysis configuration and the path to the external configuration file, together with the polyspace.project.StaticAnalysisConfiguration class, which contains the static analysis configuration.

To work with static analysis configurations that are attached to a specific project, see polyspace.project.OwnedStaticAnalysisConfiguration.

Creation

Description

Import Configuration by Reference

staticAnalysisConfigRef = proj.StaticAnalysisConfigurationRefs.add(staticAnalysisConfig, staticAnalysisConfigRefName) adds a reference from the project to the static analysis configuration staticAnalysisConfig, which is an existing external configuration file (.pscfg or .toml.pscfg) or a polyspace.project.StaticAnalysisConfiguration object. The Name property of the resulting polyspace.project.StaticAnalysisConfigurationRef object is set to staticAnalysisConfigRefName.

staticAnalysisConfigRef = proj.StaticAnalysisConfigurationRefs.add(staticAnalysisConfigRefObj) adds a reference from the project to an existing polyspace.project.StaticAnalysisConfigurationRef object staticAnalysisConfigRefObj and inherits the configuration name.

staticAnalysisConfigRef = proj.StaticAnalysisConfigurationRefs.add(staticAnalysisConfigRefObj, staticAnalysisConfigRefName) adds a reference from the project to an existing polyspace.project.StaticAnalysisConfigurationRef object staticAnalysisConfigRefObj. Use the staticAnalysisConfigRefName argument to set the Name property of the resulting staticAnalysisConfigRef object.

Convert Configuration

staticAnalysisConfigRef = proj.StaticAnalysisConfigurationRefs.moveAsRef(ownedStaticAnalysisConfigObj,staticAnalysisConfigFile) converts the existing ownedStaticAnalysisConfigObj to a polyspace.project.StaticAnalysisConfigurationRef object in the same project. The conversion process saves ownedStaticAnalysisConfigObj in staticAnalysisConfigFile. You can specify staticAnalysisConfigFile as an absolute or relative path, where relative paths are considered relative to the location of the .psprjx project file. The resulting polyspace.project.StaticAnalysisConfigurationRef object has its path set to staticAnalysisConfigFile and its Name property is inherited from the owned static analysis configuration.

example

staticAnalysisConfigRef = proj.StaticAnalysisConfigurationRefs.moveAsRef(ownedStaticAnalysisConfigObj,staticAnalysisConfigFile, staticAnalysisConfigRefName) converts the existing ownedStaticAnalysisConfigObj to a polyspace.project.StaticAnalysisConfigurationRef object in the same project. The conversion process saves ownedStaticAnalysisConfigObj in staticAnalysisConfigFile. You can specify staticAnalysisConfigFile as an absolute or relative path, where relative paths are considered relative to the location of the .psprjx project file. The resulting polyspace.project.StaticAnalysisConfigurationRef object has its Path property set to staticAnalysisConfigFile and its Name property is set by the staticAnalysisConfigRefName argument you provide.

staticAnalysisConfigRef = proj.StaticAnalysisConfigurationRefs.moveAsRef(ownedStaticAnalysisConfigObj,staticAnalysisConfigFile, configFileFormat) converts the existing ownedStaticAnalysisConfigObj to a polyspace.project.StaticAnalysisConfigurationRef object in the same project and saves the external configuration in the format specified by configFileFormat.

Input Arguments

expand all

Static analysis configuration to add a reference to from the project, specified as a polyspace.project.StaticAnalysisConfiguration object or a path to an existing external configuration file (.pscfg or .toml.pscfg).

Name to assign the referenced static analysis configuration, specified as a string. This argument sets the Name property of the polyspace.project.StaticAnalysisConfigurationRef object.

The existing staticAnalysisConfigRefObj to add a reference to from the project, specified as a polyspace.project.StaticAnalysisConfigurationRef object.

Existing owned static analysis configuration to convert to an external configuration and reference from the project, specified as a polyspace.project.OwnedStaticAnalysisConfiguration object.

Static analysis configurations created from Polyspace for AUTOSAR workspaces cannot be converted to external configurations. To save a copy of these configurations to a file, use the export() method. See polyspace.project.OwnedStaticAnalysisConfiguration.

Relative or absolute path of the external configuration file to create when converting an existing owned static analysis configuration to an external configuration, referenced by the project. You can include a file extension as part of the staticAnalysisConfigFile argument to specify the file format to create: use .pscfg to create the file in native format, or .toml.pscfg to create the file in the full TOML format. Alternatively, do not include an extension in the staticAnalysisConfigFile argument, and use the configFileFormat argument to specify the file format. Relative paths are considered relative to the location of the .psprjx project file.

Format of the configuration file to create, specified as one of:

  • FileFormat.NATIVE — original, JSON-based file.

  • FileFormat.TOML_FULLTOML file containing all configuration values, including defaults.

  • FileFormat.TOML_CONCISE — TOML file containing only non-default values.

To use FileFormat as an argument, you must first import it from polyspace.project:

from polyspace.project import FileFormat
If you do not import it, use the full syntax when specifying the argument. For example,
polyspace.project.FileFormat.TOML_FULL

Properties

expand all

Name of the referenced external static analysis configuration, specified as a string. If you do not specify a Name argument, the name defaults to that of the existing static analysis configuration you are adding or converting.

Path to the .pscfg or .toml.pscfg file where the referenced external static analysis configuration is saved, specified as a string. All relative paths are considered relative to the location of the .psprjx project file.

Methods

expand all

Examples

collapse all

Modularize a Polyspace Platform project by converting an owned static analysis configuration to an external configuration, referenced by the project. An external configuration is a build, static analysis, or testing and profiling configuration that is saved in a .pscfg or .toml.pscfg file that is referenced by the project.

Create the project, add your source files, and parse the code.

## Import modules
import polyspace.project
import polyspace.test
import os

## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace", 
                            "examples", "doc_pstest", "python_api_test_authoring")
proj = polyspace.project.Project("externalConfigProject.psprjx")

## Add source files and include headers
proj.Code.Files.add(os.path.join(examples_path, "src", "algo.c"))
proj.Code.Files.add(os.path.join(examples_path, "src", "saturate.c"))
proj.IncludePaths.add(os.path.join(examples_path, "src"))

## Save project and parse code
proj.save()
codeInfo = polyspace.project.parseCode(proj)

Convert the existing static analysis configuration to an external configuration, referenced by the project using the moveAsRef method.

# Convert the configuration 
staticAnalysisConfig = proj.StaticAnalysisConfigurations[0]   
proj.StaticAnalysisConfigurationRefs.moveAsRef(staticAnalysisConfig, "externalStaticConfig.pscfg")

# Alternatively, convert to full TOML using: 
# proj.StaticAnalysisConfigurationRefs.moveAsRef(staticAnalysisConfig, "externalStaticConfig.toml.pscfg")

When you convert a configuration that is active in a project, Polyspace updates the active configuration accordingly. Check the active static analysis configuration for the project, then save and build the project.

proj.ActiveStaticAnalysisConfiguration
proj.save()
status = polyspace.test.build(proj)

Version History

Introduced in R2026a

expand all