主要内容

polyspace.project.Workspace Class

Namespace: polyspace.project

(Python) Create and manage Polyspace workspaces

Since R2024b

Description

Create or load a Polyspace® workspace and add or remove projects by using of this Python® class.

Creation

Description

wksp = polyspace.project.Workspace(workspaceName) loads the workspace from the file workspaceName.pswks into the object wksp if the file already exists or creates a workspace file in the current folder. If you create a new workspace, the workspace file myWorkspace.pswks is not saved to your file system until you explicitly run the wksp.save() command.

example

Input Arguments

expand all

Name of workspace, specified as a string. You do not need to specify the file extension (.pswks) when you create or load a workspace file.

Properties

expand all

Workspace author, specified as a string.

Example: wksp.Author

Example: wksp.Author="jsmith"

Project references in a workspace, specified as a polyspace.project.Workspace.Projects object.

To modify this property, use these methods:

  • add(projectRef) — Add project reference object projectRef to the workspace.

  • pop(projectRefIdx) — Remove project reference object with index projectRefIdx from the workspace. If you do not specify an index, the last project added to the workspace is removed.

  • clear() — Remove all project references.

Examples: In this table, wksp is a polyspace.project.Workspace object.

ActionDescription
Add project reference object

Add a project reference object to a workspace in one of these ways:

  • Specify the file path of project file. You can add by file path only if the file path is not already added to the workspace. Relative paths are resolved with respect to the workspace file location.

    wksp.Projects.add("/path/to/myProject")
    
  • Specify a project object.

    # Create project object
    proj = polyspace.project.Project("path/to/projectFile")
    # Add to workspace
    wksp.Projects.add(proj)
  • Specify a project reference object.

    # Create project reference object 
    projRef = otherWksp.Projects[1]
    # Add to workspace
    wksp.Projects.add(projRef)
    

Remove project reference object

Remove a project by specifying the index of the corresponding project reference object.

Remove project reference with index 1.

wksp.Projects.pop(1)

Remove the last project added to the workspace.

wksp.Projects.pop()    

Remove all the project reference objects from the workspace.

wksp.Projects.clear()
To view the indices of the project reference objects for a workspace wksp, run this code snippet:
for idx in range(len(wksp.Projects)):
    print("%d: %s" % (idx, wksp.Projects[idx].Path))    

Create project object from project reference object

Get a project reference by index and use the get() method to access the corresponding project.

projRef = wksp.Projects[3]
proj = projRef.get()

Read-Only Properties

Date and time the workspace was created, specified as a datetime.datetime type.

Example: datetime.datetime(2024, 6, 23, 13, 14, 32)

Date the workspace was last saved, specified as a datetime.datetime type.

Example: datetime.datetime(2024, 6, 23, 13, 30, 54)

Path of workspace file on your file system, specified as a string

Example: /usr/local/example/pstest/myWorkspace.wksp

Methods

expand all

Examples

collapse all

This example shows how to create and manage a Polyspace Platform workspace.

In general, you generate and manage Polyspace Test™ projects and workspaces by using classes from the polyspace.project module. Before starting, make sure you can import the module on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.

  1. Import the required modules:

    import polyspace.project
    import polyspace.test
    import os

  2. Create a workspace and add project reference objects by filepath and by project reference object.

    # Create workspace object
    myWksp = polyspace.project.Workspace("newWorkspace.pswks")
    # Add a project reference by filepath
    myWksp.Projects.add("/path/to/existingProject.psprjx")
    # Add a project reference by project object
    myProj =  polyspace.project.Project("/path/to/project.psprjx")
    myWksp.Projects.add(myProj)
  3. Save your changes to the file system.

    myWksp.save()

Version History

Introduced in R2024b