Metadata-Version: 2.5
Name: usd-profiles
Version: 1.24.0rc10
Summary: USD Profiles
Project-URL: Repository, https://github.com/NVIDIA-Omniverse/usd-validate
Project-URL: Changelog, https://github.com/NVIDIA-Omniverse/usd-validate/blob/main/profiles/CHANGELOG.md
Project-URL: Homepage, https://nvidia-omniverse.github.io/usd-validate/specs/index.html
Project-URL: Documentation, https://nvidia-omniverse.github.io/usd-validate/specs/index.html
Author: NVIDIA
License: Apache-2.0 AND CC-BY-4.0
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
Requires-Python: >=3.10
Requires-Dist: docutils>=0.18.1
Requires-Dist: jinja2>=3.1.5
Requires-Dist: markdown-it-py>=3.0.0
Requires-Dist: tomli>=2.0.0; python_version < '3.11'
Description-Content-Type: text/markdown

# USD Profiles

A framework for defining and managing [OpenUSD](https://openusd.org) asset profiles, capabilities, and requirements.
This library provides tools for parsing profile specifications from Markdown, generating Python code,
and integrating with Sphinx documentation.

## Features

- **Profile definitions** — Define capabilities, features, and requirements in structured Markdown
- **Code generation** — Generate Python enums and dataclasses from profile specifications
- **Sphinx integration** — Custom directives and roles for rendering profile documentation
- **Validation support** — Generate validation rules from requirement specifications
- **Extensible** — Modular architecture for custom profile components

## AI Agent Guidance

AI coding agents should start with [AGENTS.md](AGENTS.md) for package context, expectations, and common workflows,
together with the repository root `AGENTS.md`. Repository-level agent skills live in the root `.agents/skills/`.

The runnable minimal code generation example is in [examples/python/minimal/](examples/python/minimal/).

## Installation

Install from PyPI:

```bash
pip install usd-profiles
```

## Basic Usage

### Loading Authored Specifications

Load a complete documentation tree into public API DTOs without resolving references against runtime registries:

```python
from pathlib import Path

from usd_profiles import SpecificationsLoader

specifications = SpecificationsLoader(
    root_dir=Path("specs"),
    reverse_domain="com.nvidia.simready",
).load()
```

The facade loads the configured `capabilities`, `features`, and `profiles` roots recursively and deterministically.
Document paths use the documentation root as their base for inputs inside that tree. External input roots
use their own directory as the base instead.
Use `capabilities_root`, `features_root`, or `profiles_root` to override a docs-tree directory, and
`features_roots` or `profiles_roots` for additional descriptor sources. Feature dependencies remain `FeatureRef`
objects, and additional JSON/TOML feature fields are available through `Feature.custom_data`. Profile entries retain
their `optional` flag and do not require referenced features to be registered while loading; runtime requirement
resolution skips unavailable optional features and reports an error for unavailable required features.

Markdown profiles contain resolved `Feature` objects in `Profile.features` and matching
`ProfileFeature(Feature(...))` entries in `Profile.profile_features`. JSON and TOML descriptor profiles expose
unresolved `FeatureRef` objects through both `Profile.features` and `Profile.profile_features` until runtime
resolution. When `reverse_domain` is configured, the loader qualifies local requirement codes, capability IDs,
profile IDs, and profile feature references as a separate enrichment step; parsing alone preserves identifiers as authored.

The resulting `LoadedSpecifications` contains public `Capability`, `Feature`, and `Profile` DTOs. Profile features,
feature dependencies, and externally referenced requirements stay as `FeatureRef` and `RequirementRef` values; the
loader does not resolve them against registries. `SpecificationsParser` remains available for compatibility, but new
consumers should use `SpecificationsLoader`.

Run local structural diagnostics without resolving lazy references or changing the loaded DTOs:

```python
for problem in specifications.validate():
    print(problem.severity.value, problem.message)
```

This reports typed problems for malformed versions, duplicate definitions in the load result, and invalid profile
feature optionality. It intentionally does not inspect live registries.

Register the loaded requirement definitions as metadata without binding them to validator rules, then remove the
same definitions by code and version when their content lifecycle ends:

```python
from usd_validate import register_requirements, unregister_requirements

register_requirements(*specifications.requirements)(None)
try:
    ...
finally:
    unregister_requirements(*specifications.requirements)
```

Rules may bind to `RequirementRef` values independently. Definition-only registration does not promote a
`RequirementRef` into requirement metadata. Definition-only registrations are reference-counted, so balance each
registration with one matching unregistration. They do not take ownership of definitions already held by another
registration source. Mixed definition/reference collections are accepted by both lifecycle calls; non-owning
references are ignored symmetrically.

### Code Generation

Generate Python code from profile specifications. Create a folder (e.g. `specs/`) with this structure and the
following files:

```
specs/
├── capabilities/
│   ├── capability-example.md
│   └── requirements/
│       └── single-root.md
├── features/
│   └── feature-example.md
└── profiles/
    └── profile-example.md
```

**specs/capabilities/requirements/single-root.md**

```markdown
# single-root

| Code          | REQ.001                   |
|---------------|---------------------------|
| Version       | 1.0.0                     |
| Compatibility | {compatibility}`OpenUSD`   |
| Validator     |                           |
| Tags          | {tag}`essential`          |

## Summary

USD stage must have a single root prim.

## Description

Every USD asset must contain one root prim from which all other prims descend.
```

**specs/capabilities/capability-example.md**

~~~markdown
# Example

## Overview

Minimal capability with one requirement.

## Requirements

```{requirements-table}
```
~~~

**specs/features/feature-example.md**

~~~markdown
# Example

| Property   | Value   |
|------------|---------|
| Version    | 1.0.0   |
| Dependency | OpenUSD |

## Description

Minimal feature with one requirement.

## Requirements

```{features-table}
REQ.001@1.0.0
```
~~~

**specs/profiles/profile-example.md**

```markdown
# Example

Minimal profile with one feature.

## Features

- [Example](../features/feature-example.md)
```

Then run:

```bash
python -m usd_profiles.codegen --docs-root specs --destination-dir output --namespace mypackage.profiles
```

Generated code will be under `output/mypackage/profiles/`.

If no capabilities, features, or profiles are loaded, `PythonGenerator.generate()` raises `ValueError`.
The CLI logs an error and exits with status 1. Check the configured input roots when this error appears.

### Other code generation parameters

`python -m usd_profiles.codegen` also supports:

- `--capabilities-root`: Capability directory; overrides the `capabilities/` subdirectory of `--docs-root`.
- `--features-root`: Feature directory; overrides the `features/` subdirectory of `--docs-root`.
- `--profiles-root`: Profile directory; overrides the `profiles/` subdirectory of `--docs-root`.
- `--package-name`: Python import path for generated modules; replaces the deprecated `--namespace` option.
- `--reverse-domain`: Prefix for specification identifiers, such as `com.example.factory`.
- `--header-from`: Existing UTF-8 Python source supplying an SPDX header for rendered modules only; copied API code
  keeps its original attribution. Omit this option to keep the default headers.

Supply at least one input root; `--docs-root` can be omitted when individual roots are provided.
See the [Quick Start](docs/quick-start.md#generate-python) for more.

### USD Validate integration

Use the generated requirements and features with
[USD Validate](https://pypi.org/project/usd-validate/).
Implement rule checkers and run validation as needed.

**Implement a rule** -- Register requirements and implement checks. For example, for the minimal example's single-root
requirement:

```python
import mypackage.profiles as cap
from usd_validate import BaseRule, register_requirements

@register_requirements(cap.Requirements.REQ_001_V1_0_0)
class SingleRootChecker(BaseRule):
    """USD stage must have a single root prim."""

    def CheckStage(self, usdStage):
        roots = [p for p in usdStage.GetPseudoRoot().GetChildren() if p.IsValid()]
        if len(roots) != 1:
            self._AddFailedCheck(
                "Stage must have exactly one root prim.",
                requirement=cap.Requirements.REQ_001_V1_0_0,
            )
```

**Validate with the generated feature** — Enable the feature you generated and run the engine:

```python
import mypackage.profiles
import usd_validate

engine = usd_validate.ValidationEngine(init_rules=False)
engine.enable_feature(mypackage.profiles.Features.EXAMPLE)
results = engine.validate("path/to/asset.usd")
```

### Sphinx Integration

The package includes Sphinx extensions for rendering profile documentation. Install Sphinx and MyST-Parser
separately in your documentation build environment.
Neither tool is required for specification parsing or code generation.

Add to your Sphinx `conf.py`:

```python
extensions = [
    "usd_profiles.sphinx.ext",
]
```

Use directives in your documentation:

````markdown
```{requirements-table}
geometry/mesh-valid
geometry/mesh-normals
```

```{features-table}
geometry/feature-mesh
```
````

Use roles for inline tags and compatibility badges:

```markdown
{tag}`performance` - Display a tag badge
{compatibility}`omniverse` - Display a compatibility badge
```

### Hatchling integration

The packaged `usd-profiles` Hatchling hook generates a package from authored specs for wheel,
source-distribution, and editable builds. For a project with `specs/` and `src/mypackage/`, configure:

```toml
[build-system]
requires = ["hatchling", "usd-profiles"]
build-backend = "hatchling.build"

[tool.hatch.build.hooks.usd-profiles]
docs-root = "specs"
destination-dir = "src"
package-name = "mypackage.profiles"
reverse-domain = "com.example"

[tool.hatch.build.targets.wheel]
packages = ["src/mypackage"]

[tool.hatch.build.targets.sdist]
artifacts = ["specs"]
```

`package-name` is required. `docs-root` defaults to `specs` when no individual input roots are set,
`destination-dir` to `src`, and
`reverse-domain` to an empty string. Paths are relative to the consuming project's root, and the
generated package must be inside that root. The hook includes generated files as build artifacts;
include the authored specs in the source distribution so they can be regenerated when building it.

Like the codegen CLI, the hook accepts `capabilities-root`, `features-root`, and `profiles-root`.
Each overrides the corresponding subdirectory of `docs-root`, and they can be used without a
common `docs-root`. For example, to generate a package from capabilities only:

```toml
[tool.hatch.build.hooks.usd-profiles]
package-name = "mypackage.profiles"
capabilities-root = "specs/capabilities"
destination-dir = "src"
reverse-domain = "com.example"
```

Use `header-from` to reuse an existing UTF-8 Python file's SPDX header in rendered modules;
copied API files keep their original headers. Include the header source and all input directories in the sdist.

Paths are relative to the project root and validated before generation. Inputs must exist;
the destination directory can be created, and the generated package must stay inside the project root.
Hatchling is needed only in the build environment; it is not a runtime dependency of `usd-profiles`.

## Documentation

- [Full Documentation](https://nvidia-omniverse.github.io/usd-validate/)
- [Validation Requirements](https://nvidia-omniverse.github.io/usd-validate/validation/docs/requirements.html)

## Requirements

Core package:

- Python 3.10 or later
- Jinja2 3.1.5 or later
- markdown-it-py 3.0.0 or later
- tomli 2.0.0 or later for Python versions earlier than 3.11

## License

Apache-2.0 AND CC-BY-4.0
