meta_package_manager.managers.mas module¶

class meta_package_manager.managers.mas.MAS[source]¶

Bases: PackageManager

mas drives the Mac App Store from the command line.

Packages are Mac App Store applications, keyed by the numeric adamID Apple assigns each title (the id in an App Store link). mpm reads and writes that ID; the display name rides along only as a label.

Every query reads --json output, the supported programmatic interface since the >=7.0.0 floor added --json to list, outdated and search. It sidesteps the column-alignment ambiguities of the tabular listing, where an app name carrying parentheses or padding whitespace would derail a positional parser.

Note

mas prints one JSON object per app, concatenated rather than wrapped in an array, and leaves control characters (embedded newlines, U+2028) unescaped inside name and description strings (mas-cli/mas#1248). mpm decodes the buffer one object at a time with strict=False so each object ends at its own closing brace instead of splitting on those bytes. The bug is fixed upstream for the (still unreleased) 7.1.0, so this workaround can be retired once the requirement floor rises to >=7.1.0.

Note

mas self-escalates: it asks for root itself when a store mutation needs it, so mpm never wraps install, upgrade or uninstall in its own sudo.

Initialize cli_errors list.

name: str = 'Mac App Store'¶

Return package manager’s common name.

Default value is based on class name.

homepage_url: str | None = 'https://github.com/mas-cli/mas'¶

Home page of the project, only used in documentation for reference.

Slug of the brand mark standing for this manager in the documentation.

Names an SVG vendored under docs/assets/managers/, whose provenance and license are recorded in docs/assets/managers/logos.yaml. Inlined at the top of the manager’s page by meta_package_manager._docs; a manager leaving it unset keeps the page’s default package glyph.

Several managers legitimately share one slug, either because they wrap the same upstream (brew and cask) or because the tool has no mark of its own and its ecosystem’s stands in (apt under Debian’s swirl, cargo under Rust’s gear). Documentation-only, like homepage_url: no CLI output reads it.

brewfile_entry_type: ClassVar[str | None] = 'mas'¶

Name of the Brewfile DSL entry type this manager maps to, or None if the manager has no Brewfile equivalent.

Set by the subset of managers Homebrew Bundle’s DSL covers, and consumed by meta_package_manager.brewfile when rendering the output of mpm dump --brewfile. Which manager maps to which entry is tabulated from these declarations in Snapshot and export, section “Brewfile”, where the export’s own quirks are documented too.

platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='macos', name='macOS')})¶

List of platforms supported by the manager.

Allows for a mishmash of platforms and groups of platforms. Will be normalized into a frozenset of Platform instances at instantiation.

requirement: str | None = '>=7.0.0'¶

7.0.0 introduces the --json flag on config, list, lookup/info, outdated & search. Parsing structured JSON output is the supported programmatic interface: it sidesteps the column-alignment ambiguities of the tabular output (app names containing parentheses or extra whitespace would break the previous regex-based parser).

version_cli_options: tuple[str, ...] = ('version',)¶
$ mas version
7.0.0
brewfile_entry(package)[source]¶

Emit the app’s display name, with its numeric adamID as the id: keyword brew bundle installs from.

Returns None (silently skip) for any package whose ID is not such a number: without it the entry cannot round-trip, and a half-broken mas "Name" line would error at install time. See Snapshot and export, section “mas entries”.

property installed: Iterator[Package]¶

Fetch installed packages.

$ mas list --json
{"adamID":1569813296,"bundleID":"com.1password.1password-safari","name":"1Password for Safari","version":"2.3.5"}
{"adamID":1295203466,"bundleID":"com.microsoft.rdc.macos","name":"Microsoft Remote Desktop","version":"10.7.6"}
{"adamID":409183694,"bundleID":"com.apple.iWork.Keynote","name":"Keynote","version":"12.0"}
property outdated: Iterator[Package]¶

Fetch outdated packages.

$ mas outdated --json
{"adamID":409183694,"name":"Keynote","newVersion":"12.0","version":"11.0"}
{"adamID":1176895641,"name":"Spark","newVersion":"2.11.21","version":"2.11.20"}
release_date(package_id)[source]¶

Publication timestamp of the latest release of an app, read from the App Store catalog.

mas lookup --json relays the App Store’s own catalog record, whose currentVersionReleaseDate is stamped by the store when the version goes live after review, not by the app’s author, which is what makes it a sound cooldown clock. App Review already delays every release on its own, so the window mostly buys time between a version going live and a takedown.

$ mas lookup 409183694 --json
{"adamID":409183694,"bundleID":"com.apple.iWork.Keynote","currentVersionReleaseDate":"2024-04-02T17:19:42Z","name":"Keynote","version":"14.0"}
Return type:

datetime | None

search(query, extended, exact)[source]¶

Fetch matching packages.

Caution

Search does not support extended or exact matching. So we return the best subset of results and let meta_package_manager.manager.PackageManager.refiltered_search() refine them.

$ mas search python --json
{"adamID":689176796,"name":"Python Runner","version":"1.3"}
{"adamID":630736088,"name":"Learning Python","version":"1.0"}
{"adamID":945397020,"name":"Run Python","version":"1.0"}
{"adamID":1164498373,"name":"PythonGames","version":"1.0"}
{"adamID":1400050251,"name":"Pythonic","version":"1.0.0"}
Return type:

Iterator[Package]

install(package_id, version=None)[source]¶

Install one package.

$ mas install 945397020
Return type:

str

upgrade_all_cli()[source]¶

Generates the CLI to upgrade all outdated packages.

$ mas upgrade
Return type:

tuple[str, ...]

cli_names: tuple[str, ...] = ('mas',)¶

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

id: str = 'mas'¶

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

upgrade_one_cli(package_id, version=None)[source]¶

Generates the CLI to upgrade the provided package.

$ mas upgrade 945397020
Return type:

tuple[str, ...]

virtual: bool = False¶

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

remove(package_id)[source]¶

Removes a package.

mas 4.1.0+ requests root privileges itself when not already running as root, so we don’t pre-wrap the call in sudo. This matches how install and upgrade are already invoked.

$ mas uninstall 1494051017
Password:
Uninstalled '/Applications/SimpleLogin.app' to '/Users/kde/.Trash/SimpleLogin.app'
Return type:

str