Main Content

mpmcreate

Create package

Since R2024b

    Description

    pkg = mpmcreate(name,location) creates a package named name from the folder specified by location and returns a matlab.mpm.Package object. A package is a collection of MATLAB® code, related files, and a package definition file that defines the package identity and dependencies.

    When you create a package using mpmcreate, the package is installed in place. In other words, the installed package files and folders are located in the folder specified by location, not in the default installation area.

    example

    pkg = mpmcreate(name,location,Name=Value) specifies options using one or more name-value arguments. For example, you can specify a package version, identifier, and description.

    Examples

    collapse all

    Create a new package named MyPackage from the folder PackageRootDir.

    pkg = mpmcreate("MyPackage","PackageRootDir")
    pkg = 
    
      Package with properties:
    
       Package Definition
                         Name: "MyPackage"
                  DisplayName: "MyPackage"
                      Version: 1.0.0 (1×1 Version)
                      Summary: ""
                  Description: ""
                     Provider: <missing>
                      Folders: [1×0 PackageFolder] (1×0 PackageFolder)
                 Dependencies: ""
         ReleaseCompatibility: "*"
                  FormerNames: ""
                           ID: "bb9abc84-5324-42fd-851c-b65e2887f3b5"
    
       Package Installation
                    Installed: 1
                     Editable: 1
        InstalledAsDependency: 0
                  PackageRoot: "C:\MyCode\New Folder\PackageRootDir"
        InstalledDependencies: ""
          MissingDependencies: ""
    
       Repository
                   Repository: [0×0 Repository]
    
      help MyPackage

    Input Arguments

    collapse all

    Package name, specified as a string scalar. A valid package name starts with a letter, followed by letters, digits, or underscores. The maximum length of a package name is the value that the namelengthmax command returns.

    Example: "MyPackage"

    Folder of MATLAB code and related files for the package, specified as a string scalar containing the path to the folder. If the root folder does not contain a resources folder, then the function creates one. The function adds the package definition file mpackage.json to the resources folder. Any other subfolders become member folders.

    If the folder specified by location does not exist, then the function creates a new folder and an empty package.

    Example: "Repository/PkgRootDir"

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: pkg = mpmcreate("myPackage",DisplayName="My MATLAB Package")

    Package display name, specified as a string scalar. The display name does not need to be a valid package name.

    Example: "Random Number Generator"

    Package version, specified as a string scalar containing a valid semantic version or a matlab.mpm.Version object. A valid semantic version consists of three dot-separated numbers in the format: <major version>.<minor version>.<patch version>.

    Example: "1.0.1"

    Package identifier, specified as a string scalar containing a universally unique identifier (UUID).

    Package provider, specified as a matlab.mpm.Provider object.

    Package summary, specified as a string scalar.

    Example: "Generate random numbers using various pseudorandom algorithms"

    Package description, specified as a string scalar.

    Example: "RandNumFunc(m,n,algo) creates an m-by-n matrix of random numbers"

    Compatible MATLAB versions, specified as a string scalar containing a valid version range. You can specify a single MATLAB version as the full name of a MATLAB release version (for example, "R2024b") or as a semantic version range.

    A MATLAB release name follows the format:

    • Ryyyy[a|b] — Where yyyy is the year of the release and a or b. For example R2024b.

    • R20yy[a|b]_[Prerelease] — Specifies the prerelease version. For example R2024b_Prerelease.

    • R20yy[a|b]_Update_# — Specifies a particular update. For example R2024b_Update_1.

    • R20yy[a|b]_[Prerelease]_Update_# — Specifies the prerelease version as well as a particular update. For example R2024b_Prerelease_Update1.

    For MATLAB releases valid semantic version consists of three dot-separated numbers in the format: <major version>.<minor version>.<patch version>. When you specify a MATLAB version using semantic version syntax, the major version is the last two digits of the release year. The minor version is 1 for "a" releases and 2 for "b" releases. The patch version corresponds to the update version. For example, R2024b has a semantic version of 24.2.0. The first update for R2025a has a semantic version of 25.1.1. Pre-release status is optional and is specified by adding -prerelease to the end of the version range, for example the prerelease version of R2025b is 25.2.0-prerelease.

    A version range can be specified using the <, <=, >, or >= operators in front of a version number. For example >24.2.0 would specify all versions later than R2024b. Multiple ranges separated by whitespace can be specified to further limit matches. For example, >24.2.0 <=24.2.2 would include versions between R2024b and R2024b update 2 but would not include R2025a or R2024b Update 3. Use the || operator to designate multiple acceptable version ranges. For example, <24.2.0 || >24.1.2 would include versions less than R2024b and greater than R2024b update 2 but would not include R2024b update 1.

    Example: "R2024b"

    Example: "R2024b_Prerelease"

    Example: "R2024b_Update1"

    Example: "R2024b_Prerelease_Update1"

    Example: "24.2.0"

    Example: "24.2.1"

    Example: "24.2.0-prerelease"

    Example: ">=R2024b"

    Example: >24.2.0

    Example: <24.2.0 || >24.1.2

    Add member folders and their subfolders, specified as a numeric or logical 1 (true) or 0 (false). If you specify IncludeSubfolders as true, then the function adds subfolders of location as member folders of the package.

    Package root folders, resources folders, private folders, namespace folders, class folders, and their subfolders are not added as member folders.

    Install package, specified as a numeric or logical 1 (true) or 0 (false). If you specify Install as true, then the function installs the newly created package.

    Tips

    • To undo the results of mpmcreate, follow these steps:

      1. Uninstall the package using mpmuninstall.

      2. Delete the file mpackage.json from the resources folder in the root folder of the package. If a resources folder did not previously exist, then delete that folder as well.

      3. Delete the folder specified by location if it did not previously exist.

    • If mpmcreate creates a package that would cause an error if installed, then a warning is issued.

    Version History

    Introduced in R2024b