Metadata-Version: 2.4
Name: carton-maya
Version: 0.6.0
Summary: Local-first package manager for Autodesk Maya tools
Author: cignoir
License: MIT
Project-URL: Homepage, https://github.com/cignoir/carton
Project-URL: Repository, https://github.com/cignoir/carton
Project-URL: Issues, https://github.com/cignoir/carton/issues
Keywords: maya,autodesk,package-manager,vfx,dcc
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: jsonschema>=4
Requires-Dist: questionary>=2
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-qt; extra == "dev"

# Carton

A local-first package manager for Autodesk Maya.

[日本語版はこちら](README_ja.md)

## What is Carton?

Carton installs, updates, and shares Maya tools. **Packages are first-class**:
you install a tool by its `namespace/name`, regardless of where its bytes come
from — a GitHub repo, a remote URL, a shared-drive index, or a local folder.
No cloud service required; everything runs on file paths, URLs, or shared
drives you already have.

```mermaid
flowchart LR
    subgraph Origins["Where the bytes live"]
        G["GitHub repo<br>package.json + Release"]
        U["Remote URL<br>package.json"]
        Z["Zip beside the catalogue"]
    end
    CAT["Catalogue<br>catalogue.json<br>one entry per package"]
    subgraph You["Your Maya"]
        LIB["Library<br>mystudio/rigger<br>thirdparty/qbloom<br>community/..."]
        MT["My Tools<br>your own dev scripts"]
    end
    G --> CAT
    U --> CAT
    Z --> CAT
    CAT -- Subscribe --> LIB
    MT -- Publish --> CAT
```

Every package belongs to a **catalogue** — a `catalogue.json` you can read,
diff, and keep in git. Each entry names one package and says where its bytes
come from. So there are three things you do with one:

1. **Subscribe** — add a `catalogue.json` by path or URL and every package in
   it appears in your Library.
2. **Curate** — create a local catalogue and add the tools you use to it
   (`owner/repo`, or a `package.json` URL). Commit the file and your team has
   the same list.
3. **Publish** — your own scripts go from My Tools into a catalogue.

## Concepts

```mermaid
flowchart TB
    subgraph Carton["Carton (in Maya)"]
        direction LR
        subgraph LIB["Library"]
            direction TB
            NS1["mystudio/*<br>(namespace group)"]
            NS2["thirdparty/*"]
        end
        subgraph MT["My Tools"]
            L["your local scripts<br>registered by reference"]
        end
    end
    subgraph ORG["Origins — where a package lives"]
        direction TB
        E["embedded<br>(catalogue hosts zip)"]
        GH["github<br>(Releases)"]
        UR["url<br>(remote package.json)"]
        LO["local<br>(filesystem path)"]
    end
    E -.lists in.-> NS1
    GH -.lists in.-> NS1
    UR -.lists in.-> NS2
    L -- Publish --> E
    L -- Publish --> GH
```

- **Package** — identified by `namespace/name` (npm-style, e.g.
  `mystudio/rigger`). Same package can be indexed in multiple catalogues; it
  still installs as one thing.
- **Origin** — *where* a package's bytes live. Four types:
  `embedded` (catalogue hosts the zip), `github` (GitHub Releases), `url`
  (arbitrary hosted `package.json`), `local` (filesystem path).
- **Catalogue** — an *optional* index (`catalogue.json`) that lists multiple
  packages and where each one's origin is. Useful for studios or communities
  distributing many tools at once. A package doesn't need to be in a catalogue
  — you can install it directly from a GitHub repo or URL.
- **My Tools** — your own local scripts, registered by reference (edits take
  effect immediately). Publishable to an origin (GitHub Release or embedded
  catalogue) when you're ready to share.

## Requirements

- Maya 2022 or newer, started in Python 3 mode
  (that is the default from Maya 2022 on)

  Carton needs a Python 3 interpreter and a PySide2 / PySide6
  binding — nothing tied to a particular Maya year, so the installer
  checks the interpreter rather than an allowlist of versions. The
  test suite runs on Python 3.9 (Maya 2023) upward in CI; Maya 2022's
  Python 3.7 is supported but not exercised there.

## Quick Start

### Install Carton

1. Download an installer from [Releases](https://github.com/cignoir/carton/releases)
2. Drag & drop the `.py` file onto Maya's viewport
3. Restart Maya
4. Menu: **Carton > Open Carton**

### Add a Catalogue

```
Settings (⚙) > + Add catalogue
```

One screen, three options:

- **Local catalogue file** — path to a `catalogue.json` on a shared drive or
  local filesystem.
- **Remote catalogue URL** — URL to a `catalogue.json`.
- **Create new local catalogue** — scaffold an empty one for you or your
  studio to publish into.

The Library view merges every catalogue by namespace, so you browse packages
without worrying which one they came from.

### Add a Package to a Catalogue

```
Settings (⚙) > pick a local catalogue > + Add package…
```

- **GitHub repository** — `owner/repo`. Carton reads the `package.json` at the
  repo root and records a `github` origin, so new Releases show up as updates.
- **package.json URL** — a direct URL, for packages that aren't on GitHub.

The entry is written into that catalogue's `catalogue.json`, so `git diff`
shows exactly what you added and your team gets it with a pull. Remote
catalogues are read-only mirrors and are never a target; when you have exactly
one local catalogue, Carton picks it without asking.

### Install a Tool

Open Carton, pick a namespace in the Library sidebar, click **Install**.

The detail panel has **Version History** for release notes and rollback.
Rolled-back packages are **pinned** and won't be updated automatically until
you unpin them.

### Register & Share Your Script

```
+ Import from shelf > pick a button you already use
                    > confirm the source, set namespace
                    > Register

+ Register Script   > select file or folder
                    > set namespace (required), name, icon, description
                    > Register

Card > Publish > pick target (GitHub repo or embedded catalogue)
              > write release notes > ship it
```

**+ Import from shelf** is usually the shortest route: the tool you run every
day is probably already a shelf button, and that button's command is a working
statement of how to launch it. Carton reads the command, works out where the
code lives (by module name, by a path in the command, or by searching
`MAYA_SCRIPT_PATH`), and warns you if the command carries an absolute path —
which works for you and for nobody else.

**+ Register Script** is the same thing starting from a file or folder. Both
sit in the toolbar above the card list, whichever sidebar row is selected. `namespace` is the one field that blocks: it is your
own prefix (`mystudio`, your handle) and becomes half of the package id — see
[Namespace and the Internal Name](#namespace-and-the-internal-name). Everything else Carton detects or you can leave
empty.

From a terminal the same thing is `uvx carton-maya package init --namespace
<you>` to scaffold, then `package lint` and `package pack`.

See [Registering tools to My Tools](#registering-tools-to-my-tools) below for
per-type details. Uninstalling a published tool from the Library view does
**not** delete its My Tools registration — Carton just demotes it back to a
local-only entry.

## Profiles

A **profile** is a saved set of runtime settings — catalogues, proxy,
language, auto-update. Switch profiles to flip your whole Carton between,
say, "studio work" and "personal" without re-adding catalogues by hand.

Profiles live as JSON files under `~/Documents/maya/carton/profiles/` (Windows)
or `~/maya/carton/profiles/` (macOS / Linux). The built-in `default` profile
always exists; create more from the **Profile Manager**, opened from
**📦 Manage profiles…** at the bottom of the sidebar.

From the Profile Manager you can:

- **New** — create a profile seeded from your current Carton settings
- **Edit** — change catalogues / proxy / language / name
- **Reorder** — drag profiles around in the dropdown order
- **Build Installer…** — generate a custom drag-and-drop installer that
  pre-seeds the profile on first install. The recipient gets a Carton
  pre-configured with that profile selected.

Switching profiles is instant (no Maya restart). Installed packages are
shared across all profiles — a profile only swaps Carton-wide settings like
the catalogue list, proxy, and language.

## Recovering from a damaged state file

Every file Carton writes — `config.json`, `installed.json`, catalogues,
profiles — is written to a temp file and swapped into place in one step,
so an interrupted write can never leave a half-written file behind.

If one turns up unreadable anyway (a failing disk, an external editor),
Carton renames it to `<name>.corrupt-<timestamp>` and starts from
defaults rather than refusing to launch. Nothing is deleted, and the
catalogue list is usually restored automatically from the active
profile, which carries its own copy.

## Catalogue Structure

An **embedded** catalogue (one that hosts its own package zips) looks like:

```
my-catalogue/
├── catalogue.json          # Package index (v5.0)
├── packages/
│   └── {namespace}/{name}/{version}/
│       └── {name}-{version}.zip
├── icons/
│   └── {name}.png          # Per-package icon
└── icons.zip               # Bundled icons for remote catalogues
```

`catalogue.json` shape (v5.0):

```json
{
  "schema_version": "5.0",
  "catalogue_id": "<UUID>",
  "display_name": "MyStudio Tools",
  "packages": {
    "mystudio/rigger": {
      "origin": {"type": "github", "repo": "mystudio/rigger"}
    },
    "mystudio/shader-studio": {
      "origin": {
        "type": "embedded",
        "latest_version": "1.0.0",
        "versions": {
          "1.0.0": {
            "download_url": "packages/mystudio/shader-studio/1.0.0/shader-studio-1.0.0.zip",
            "size_bytes": 12345,
            "maya_versions": ["2024", "2025", "2026"],
            "released_at": "2026-03-…"
          }
        }
      }
    },
    "thirdparty/qbloom": {
      "origin": {"type": "url", "url": "https://example.com/qbloom-package.json"}
    }
  }
}
```

Only `embedded` origins carry `versions` inline — `github` / `url` / `local`
resolve versions dynamically (GitHub Releases API, remote `package.json`,
local file). Manage your catalogue with Git, put it on a network drive, or
host it as static files — whatever works for your team.

## Registering tools to My Tools

"My Tools" is the local working area where you register tools by reference —
no copying. Edits to the original files take effect immediately. From My Tools
you can also Publish a tool to a catalogue (or a GitHub repo) to share it.

Carton supports several package types and auto-detects which one you're
adding. Below is what you can register and what to expect for each.

Because registration is by reference, moving or renaming the original
files breaks the link. Carton notices: the card shows a **Source missing**
badge and offers **Relink** in place of Launch. Relinking points the
registration at the new location and rewires Maya's paths for the current
session — the package keeps its identity, so anything already published
under it is unaffected.

### 1. Single-file Python script (`.py`)

```
tools/
└── quick_rename.py        # def show(): ...
```

**Add**: pick the file in `+ Add > File`. Carton inspects the file for
`def show / run / main / execute` and prefills the function name. You can pick
a different function from the dropdown.

**Run modes** — the two `entry_point` forms, one each:
- **Call function** (default for `.py` with detected functions): Carton imports
  the module by basename and calls the chosen function — e.g.
  `import quick_rename; quick_rename.show()`.
- **Run a command**: a command string, run exactly as a shelf button runs it.
  Carton fills the box in with one that locates the file by module name and
  re-reads its source on every Launch, so an edit shows up without restarting
  Maya and the package stays portable (no absolute path).

**The command is editable.** The box shows what will actually run before you
register, and you can replace it with anything a shelf button could hold —
that is the same string, and the same two `sourceType`s Maya has. Clear the box
to go back to Carton's generated one. Edit has the same field, so an imported
or hand-written command is never silently rewritten.

The file's parent directory is added to `sys.path` so either works.

### 2. Single-file MEL script (`.mel`)

```
tools/
└── quickRename.mel        # global proc quickRename() { ... }
```

**Add**: pick the file. Carton enables MEL mode and uses the filename (without
extension) as both the script and the procedure name by default.

At launch Carton runs `source "quickRename.mel"; quickRename();` via
`maya.mel.eval`. The file's directory is added to `MAYA_SCRIPT_PATH`.

### 3. Maya plug-in (`.mll`)

```
plug-ins/
└── exAttrEditor.mll
```

**Add**: pick the file. Carton detects the `.mll` extension, registers the
plug-in's directory on `MAYA_PLUG_IN_PATH`, and shows an extra **Launch
command** field where you can enter an optional Python expression to run after
the plug-in loads (typically the command that opens the tool's UI). For
example:

```python
import maya.cmds as mc; mc.exAttrEditor(ui=True)
```

Clicking Launch loads the plug-in (if not already loaded) and runs the
command.

### 4. Folder package — Python (`python_package`)

A folder you intend to `import` as a Python package:

```
my_tool/
├── __init__.py            # def show(): ...
├── ui.py
└── package.json           # optional metadata
```

**Add**: pick the folder in `+ Add > Folder`. Carton:

- Reads `package.json` if present (preferred — see below).
- Otherwise auto-detects: it scans `__init__.py` for a function and walks the
  tree to guess the type.
- Adds the **parent** of the folder to `sys.path` so `import my_tool` works.

At launch: `import my_tool; my_tool.show()` (or the function you picked).

If you bundle a `package.json` in the folder root, Carton skips the run-mode
UI entirely and just trusts the metadata. This is the recommended way to make
folder packages portable across teams. See the
[Carton Developer Guide](docs/developer-guide.md) for details.

### 5. Folder package — MEL (`mel_script`)

```
my_mel_tool/
├── scripts/
│   └── myTool.mel         # global proc myTool() { ... }
└── package.json           # optional, type: mel_script
```

**Add**: pick the folder. Carton finds the `scripts/` directory (or the folder
itself if there's no `scripts/`), adds it to `MAYA_SCRIPT_PATH`, and uses the
first `.mel` file as the script. At launch: `source "myTool.mel"; myTool();`.

### 6. Maya module (`maya_module`) — Autodesk Application Package / `.mod`

This is the format most third-party Maya tools ship in: a folder with
`PackageContents.xml` (or a `*.mod` file) plus `Contents/scripts`,
`Contents/plug-ins`, `Contents/icons`, and a `userSetup.py` that registers
menus or shelves.

```
SIWeightEditor/
├── PackageContents.xml
└── Contents/
    ├── scripts/
    │   ├── userSetup.py
    │   └── siweighteditor/
    │       └── __init__.py
    ├── plug-ins/
    │   └── win64/2024/
    │       └── bake_skin_weight.py
    └── icons/
```

**Add**: pick the folder. Carton detects the module layout and:

- Adds `Contents/scripts` to `sys.path` and `MAYA_SCRIPT_PATH`
- Walks `Contents/plug-ins` up to 3 levels deep (so nested layouts like
  `plug-ins/<plat>/<ver>/` are picked up) and adds every directory containing
  plug-in files to `MAYA_PLUG_IN_PATH`
- Adds `Contents/icons` to `XBMLANGPATH`, `Contents/presets` to
  `MAYA_PRESET_PATH`
- Executes `userSetup.py` deferred via `maya.utils.executeDeferred` so the
  module's own menu/shelf registration runs

The card shows an **Activate** button by default (no single window to
launch). Activation is idempotent within a session — clicking Activate twice
won't double-register menus.

#### Bind a Launch button to the module's main window

If you'd rather click **Launch** to open the module's UI directly, edit the
card and set the **Launch command** field to the Python expression that opens
the window. For SI Weight Editor:

```python
from siweighteditor import siweighteditor; siweighteditor.Option()
```

After saving, the card's button switches from Activate to Launch.

#### How to find the right launch command

Different tools name their entry function differently. In order of effort:

1. **Read the module's README / install guide** — easiest when it exists.
2. **Right-click an existing shelf button** for the tool → Edit → copy the
   command. Or in Maya: enable **Script Editor → History → Echo All
   Commands**, click the tool's menu item, and read the echoed command from
   the history.
3. **Grep `userSetup.py` and `startup.py`** for `runTimeCommand`, `menuItem
   -command`, or anything resembling `register*command`. The command string
   inside is the canonical entry point. (For SI Weight Editor that's how we
   found `siweighteditor.Option()`.)
4. **Search the source for top-level `def show / main / Go / open / run`** —
   common conventions for "open the main window" functions.
5. **Last resort**: find the main `QMainWindow` / `QDialog` subclass and
   instantiate it directly. Be aware some tools do important setup (loading
   resources, paths, plug-ins) in their entry function — instantiating the
   window class directly may give you a half-broken UI.

### 7. Folder package — `.mll` plugin bundle (`plugin`)

```
my_plugin/
├── plug-ins/
│   └── myPlugin.mll
├── scripts/
│   └── helper.py
└── package.json           # type: plugin
```

This is for plug-ins that ship alongside helper scripts as a unit. Carton
adds `plug-ins/` to `MAYA_PLUG_IN_PATH` and `scripts/` to both `sys.path` and
`MAYA_SCRIPT_PATH`. Auto-load can be enabled via `auto_load: true` in
`package.json`, next to `plugin_file`.

### Namespace and the Internal Name

Every package has an **internal name** (a slug like `quick_rename` or
`ari-mirror`), shown read-only in the Add and Edit dialogs. It's derived
from the file or folder name and is the package's stable identifier — it
cannot be changed after registration without orphaning the catalogue entry.

The **namespace** field is **required** — a package without one can never
be published, so Carton asks for it at registration rather than letting
you discover the problem later. If you type `MyStudio` it gets
auto-converted to `mystudio`; the canonical form is shown live below the
input.

Since almost everyone registers everything under the same namespace, set
**Settings → Default namespace** once and the field arrives prefilled. A
`package.json` or sidecar that declares its own namespace still wins.

## Developer documentation

Documentation for the **author** side — building Carton-compatible packages
— lives in [docs/developer-guide.md](docs/developer-guide.md). It covers:

- `package.json` full reference (the two `entry_point` forms,
  `platform` / `plugin_file` requirements, etc.)
- How to choose a package type (`plugin` vs `maya_module` decision matrix)
- Distributing as a Maya Module (`.mod`) with concrete steps
- Carton CLI (`uvx carton-maya`) usage
- Pre-publish checklist and common pitfalls

## Development

```bash
# Build installers
python scripts/build_installer.py

# Run tests (Qt smoke tests require pytest-qt; offscreen platform is auto-set)
pip install pytest-qt
python -m pytest tests/ -v

# Dev reload in Maya (Script Editor). compile() is required: it is how the
# script finds its own location, and therefore which source tree to deploy.
_p = r"path/to/carton/scripts/dev_reload.py"
exec(compile(open(_p, encoding="utf-8").read(), _p, "exec"))
```

See [docs/design-faq.md](docs/design-faq.md) for intentional non-decisions
("why isn't dependency resolution a thing?", "why no Cartonfile?", etc.) —
useful context before proposing new features.

## License

MIT
