Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

rez-package-pitfalls

БесплатноБез исполняемых скриптовНе проверен

The package.py execution model and the errors it produces — why a top-level `from x import SomeClass` makes the installed package.py unparseable, why…

loonghaoот loonghao359 установок в других каталогах

Об этом скилле

Rez package.py pitfalls

One-sentence summary: rez execs package.py once at build time and writes every surviving module-level name back out as Python source, so anything at module scope that is not a plain value, a function or a module lands in the installed package.py as text that no longer parses.

Skill scope: what rez does to package.py and when. For the attribute reference and the @early/@late mechanics see rez-package-definition; for the commands() body and the rex API see rez-package-commands; for the version/variant/range decisions and the rest of the anti-pattern list see rez-package-authoring.

Every pitfall below was reproduced against Rez 3.4.0, and the error text is copied from a real run with only the host, user and timestamp replaced by placeholders.

The three phases

Phase When it runs What it does to package.py
Load every time rez reads a package, including during rez-build execs the file; every module-level name is collected as a candidate attribute
Serialize on rez-build / rez-release writes the surviving attributes back out as a new package.py into the install
Interpret on rez-env and every other resolve runs commands() through rex and emits shell code; does not run the module body

Two consequences drive every pitfall here: the module body is Python evaluated on the build machine, and commands() is not Python at resolve time.

Pitfall 1 — a top-level from x import SomeClass breaks the installed package

Symptom

rez-build --install fails while resolving the build environment, before your build command ever runs. The named file is a temporary copy, not your source.

Trigger

Any module-level name bound to something that is not a plain value, a function, a module or a __-leading name. The most common shape is importing a class at the top of the file:

from pathlib import Path          # Path is a class, so it survives serialization

documents_path = Path.home().as_posix() + "/Documents/.p4config"

name = "foo"
version = "1.0.0"

Actual error

Resolving build environment:
resolved by builder@BUILD-HOST, on Fri Oct 02 01:05:17 2026, using Rez v3.4.0

requested packages:
~platform==windows           (implicit)
~arch==AMD64                 (implicit)
~os==windows-10.0.26100.SP0  (implicit)

resolved packages:
01:05:17 ERROR    ResourceError: Problem loading C:\Users\<user>\AppData\Local\Temp\rez_write__epzwl2x\package.py: invalid syntax (package.py, line 12)

Invoking custom build system...

The rez_write_<random> directory is rez's own temp copy of the definition (rez/serialise.py, prefix="rez_write_"), so the path in the message never points at the file you edited. The offending line is what rez wrote, not what you wrote — here line 12 of the generated file is:

Path = <class 'pathlib.Path'>

package.py attributes are dumped with pformat(), and the repr of a class object is not valid Python source.

Correct form

Import inside commands(), and keep the value out of the module scope entirely:

name = "foo"
version = "1.0.0"


def commands():
    # Import inside commands() so the module is not captured as a package
    # attribute: rez serializes module-level names into the installed
    # package.py, and a class object renders as invalid syntax.
    from pathlib import Path

    documents_path = Path.home().as_posix() + "/Documents/.p4config"
    env.P4CONFIG.set(documents_path)

The installed package.py then carries name, version, commands, timestamp and format_version — and nothing else. The last two are rez's, not yours: timestamp defaults to the install time and format_version is always written by the filesystem package repository (rezplugins/package_repository/filesystem.py), so expect both after every rez-build --install.

Pitfall 2 — module-scope values are frozen on the build machine

Symptom

A package works on the machine that released it and is wrong everywhere else: a per-user path, a hostname, a sys.prefix or a os.getcwd() result points at the builder's machine.

Trigger

Computing anything environment-dependent at module scope:

import sys
from pathlib import Path

sys_path = sys.prefix                                    # frozen at build time
documents_path = Path.home().as_posix() + "/Documents/.p4config"

Why

The module body runs once, during rez-build, and its results are written into the install. This is what lands in the installed package.py:

sys_path = 'C:\\Users\\<user>\\AppData\\Local\\Programs\\Python\\Python312'

documents_path = 'C:/Users/<user>/Documents/.p4config'

Note that sys_path survived even though sys itself did not — the module was stripped, the string it produced was not.

Correct form

Move anything that depends on who or where the reso

Полный SKILL.md на ClawHub

Установить rez-package-pitfalls в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл rez-package-pitfalls?

The package.py execution model and the errors it produces — why a top-level `from x import SomeClass` makes the installed package.py unparseable, why module-scope values are frozen on the build machine, why `env`/`this`/`root` look undefined to linters, and why a failed rez-build can leave a broken install behind. Use when a package resolves or builds with a confusing error, when reviewing a package.py for module-scope mistakes, or before releasing one. Covers Rez 3.4.0.

Как установить скилл rez-package-pitfalls?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл rez-package-pitfalls запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить rez-package-pitfalls с