|
| 1 | +--- |
| 2 | +layout: documentation |
| 3 | +title: Project Info — JSON Configuration Dump |
| 4 | +--- |
| 5 | + |
| 6 | +# Project Info — JSON Configuration Dump |
| 7 | + |
| 8 | +The `pyb -i` (or `pyb --project-info`) command outputs the complete project |
| 9 | +configuration as pretty-printed JSON to stdout, without running a build. |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```bash |
| 14 | +# Dump full project configuration |
| 15 | +pyb -i 2>/dev/null | python -m json.tool |
| 16 | + |
| 17 | +# Extract a single value |
| 18 | +pyb -i 2>/dev/null | jq -r .project.version |
| 19 | + |
| 20 | +# Apply environment and property overrides |
| 21 | +pyb -i -E ci -P coverage_break_build=false 2>/dev/null | jq .properties |
| 22 | +``` |
| 23 | + |
| 24 | +## Output Separation |
| 25 | + |
| 26 | +JSON is written to **stdout**. All log messages (plugin loading, initializer |
| 27 | +execution, debug output) are written to **stderr**. This separation ensures |
| 28 | +that the stdout stream is always valid JSON, regardless of verbosity level: |
| 29 | + |
| 30 | +```bash |
| 31 | +# JSON only |
| 32 | +pyb -i 2>/dev/null |
| 33 | + |
| 34 | +# JSON to file, logs visible |
| 35 | +pyb -i > project.json |
| 36 | + |
| 37 | +# JSON piped, debug logs to a file |
| 38 | +pyb -i -X 2>debug.log | jq . |
| 39 | + |
| 40 | +# Both visible (JSON to stdout, logs to stderr) |
| 41 | +pyb -i |
| 42 | +``` |
| 43 | + |
| 44 | +## What Runs |
| 45 | + |
| 46 | +When `pyb -i` is invoked: |
| 47 | + |
| 48 | +1. **`build.py` is loaded** — plugins are imported, project attributes are set. |
| 49 | +2. **Plugin initializers run** — these populate default property values (e.g. |
| 50 | + `dir_source_main_python`, `coverage_threshold_warn`). Initializers only call |
| 51 | + `set_property_if_unset()` and bind utility functions; they do not create |
| 52 | + directories, install packages, or modify the filesystem. |
| 53 | +3. **Property overrides are applied** — values from `-P` flags override |
| 54 | + plugin defaults. |
| 55 | + |
| 56 | +**What does NOT run:** No tasks execute. No build/test virtual environments are |
| 57 | +created. No dependencies are installed. No files are written to `target/`. |
| 58 | + |
| 59 | +## JSON Schema |
| 60 | + |
| 61 | +The output is a single JSON object with the following top-level keys: |
| 62 | + |
| 63 | +### `pybuilder_version` |
| 64 | + |
| 65 | +The PyBuilder version string. |
| 66 | + |
| 67 | +### `project` |
| 68 | + |
| 69 | +Project metadata: |
| 70 | + |
| 71 | +| Field | Type | Description | |
| 72 | +|-------|------|-------------| |
| 73 | +| `name` | string | Project name (from `build.py` or directory name) | |
| 74 | +| `version` | string | Declared version (e.g. `"1.0.dev"`) | |
| 75 | +| `dist_version` | string | Distribution version with timestamp (e.g. `"1.0.dev20260401120000"`) | |
| 76 | +| `basedir` | string | Absolute path to project root | |
| 77 | +| `summary` | string | One-line project summary | |
| 78 | +| `description` | string | Full project description | |
| 79 | +| `author` | string | Primary author (legacy field) | |
| 80 | +| `authors` | array | List of author objects with `name`, `email`, and optional `roles` | |
| 81 | +| `maintainer` | string | Primary maintainer (legacy field) | |
| 82 | +| `maintainers` | array | List of maintainer objects | |
| 83 | +| `license` | string | License identifier | |
| 84 | +| `url` | string | Primary project URL | |
| 85 | +| `urls` | object | Named URL map (e.g. `{"Source Code": "https://..."}`) | |
| 86 | +| `requires_python` | string | Python version specifier (e.g. `">=3.10"`) | |
| 87 | +| `default_task` | string or array | Default task(s) when `pyb` is run without arguments | |
| 88 | +| `obsoletes` | array | Obsoleted package names | |
| 89 | +| `explicit_namespaces` | array | Explicit namespace packages | |
| 90 | + |
| 91 | +### `environments` |
| 92 | + |
| 93 | +Array of active environment names (from `-E` flags). |
| 94 | + |
| 95 | +### `properties` |
| 96 | + |
| 97 | +Object mapping property names to their values. Includes all built-in and |
| 98 | +plugin-defined properties. Values that are not JSON-serializable (e.g. function |
| 99 | +objects) are converted to their string representation. |
| 100 | + |
| 101 | +### `plugins` |
| 102 | + |
| 103 | +Array of loaded plugin names in load order. |
| 104 | + |
| 105 | +### `dependencies` |
| 106 | + |
| 107 | +Object with four sub-keys: |
| 108 | + |
| 109 | +| Key | Contents | |
| 110 | +|-----|----------| |
| 111 | +| `runtime` | Dependencies from `depends_on()` | |
| 112 | +| `build` | Dependencies from `build_depends_on()` | |
| 113 | +| `plugin` | Dependencies from `plugin_depends_on()` | |
| 114 | +| `extras` | Object mapping extra name to dependency array | |
| 115 | + |
| 116 | +Each dependency is an object: |
| 117 | + |
| 118 | +```json |
| 119 | +{ |
| 120 | + "name": "requests", |
| 121 | + "version": ">=2.28", |
| 122 | + "url": null, |
| 123 | + "extras": null, |
| 124 | + "markers": "sys_platform == 'linux'", |
| 125 | + "declaration_only": false, |
| 126 | + "type": "dependency" |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +Requirements files have `"type": "requirements_file"` and only `name`, |
| 131 | +`version` (always null), and `declaration_only` fields. |
| 132 | + |
| 133 | +### `tasks` |
| 134 | + |
| 135 | +Array of task objects: |
| 136 | + |
| 137 | +```json |
| 138 | +{ |
| 139 | + "name": "run_unit_tests", |
| 140 | + "description": "Runs all unit tests", |
| 141 | + "dependencies": [ |
| 142 | + {"name": "compile_sources", "optional": false}, |
| 143 | + {"name": "coverage", "optional": true} |
| 144 | + ] |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +### `manifest_included_files` |
| 149 | + |
| 150 | +Array of glob patterns included in the distribution manifest. |
| 151 | + |
| 152 | +### `package_data` |
| 153 | + |
| 154 | +Object mapping package names to arrays of included file patterns. |
| 155 | + |
| 156 | +### `files_to_install` |
| 157 | + |
| 158 | +Array of `[destination, [filenames]]` pairs for files installed outside packages. |
| 159 | + |
| 160 | +## Integration Examples |
| 161 | + |
| 162 | +### CI/CD: Extract Version for Tagging |
| 163 | + |
| 164 | +```bash |
| 165 | +VERSION=$(pyb -i 2>/dev/null | jq -r .project.dist_version) |
| 166 | +docker build -t myapp:$VERSION . |
| 167 | +``` |
| 168 | + |
| 169 | +### Dependency Auditing |
| 170 | + |
| 171 | +```bash |
| 172 | +# List all runtime dependencies |
| 173 | +pyb -i 2>/dev/null | jq -r '.dependencies.runtime[].name' |
| 174 | + |
| 175 | +# Find dependencies without version constraints |
| 176 | +pyb -i 2>/dev/null | jq '.dependencies.runtime[] | select(.version == null) | .name' |
| 177 | +``` |
| 178 | + |
| 179 | +### Editor/IDE Integration |
| 180 | + |
| 181 | +```bash |
| 182 | +# Get source directory for language server configuration |
| 183 | +SRC=$(pyb -i 2>/dev/null | jq -r '.properties.dir_source_main_python') |
| 184 | + |
| 185 | +# Get test directory |
| 186 | +TEST=$(pyb -i 2>/dev/null | jq -r '.properties.dir_source_unittest_python') |
| 187 | +``` |
| 188 | + |
| 189 | +### Diffing Configuration Between Environments |
| 190 | + |
| 191 | +```bash |
| 192 | +diff <(pyb -i 2>/dev/null | jq -S .properties) \ |
| 193 | + <(pyb -i -E ci 2>/dev/null | jq -S .properties) |
| 194 | +``` |
| 195 | + |
| 196 | +## Command Line Options |
| 197 | + |
| 198 | +`pyb -i` is compatible with most project options: |
| 199 | + |
| 200 | +| Flag | Effect | |
| 201 | +|------|--------| |
| 202 | +| `-E <env>` | Activate environment (repeatable) | |
| 203 | +| `-P <key>=<value>` | Override property value | |
| 204 | +| `-D <dir>` | Set project directory | |
| 205 | +| `-O` | Offline mode | |
| 206 | +| `--no-venvs` | Disable venv creation | |
| 207 | +| `-X` | Debug log output (to stderr) | |
| 208 | +| `-v` | Verbose log output (to stderr) | |
| 209 | +| `-q` / `-Q` | Suppress log output (on stderr) | |
| 210 | + |
| 211 | +`pyb -i` is mutually exclusive with `-t`, `-T`, `--start-project`, and |
| 212 | +`--update-project`. |
0 commit comments