Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/smoke_installed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Use the installed package the way a caller does: write a small schedule,
parse it, validate it and run the command line on it. Run from outside the
repository, so the package is the installed copy, not scripts/."""
import os
import subprocess
import sys
import tempfile

import cpp_xer_parser as p
import cpp_xer_parser.xer_parser as x

assert not os.path.isdir(os.path.join(os.getcwd(), "scripts")), "run from outside the repo"
assert x.__file__.startswith(sys.prefix), x.__file__
assert x._VALIDATION_AVAILABLE
assert x.get_profile.__module__ == "cpp_xer_parser.config_profiles"

T = "\t"
rows = [
["ERMHDR", "24.12", "2026-01-05", "Project", "admin", "Test", "db", "Project Management", "CAD"],
["%T", "PROJECT"], ["%F", "proj_id", "proj_short_name", "clndr_id", "plan_start_date"],
["%R", "P1", "SMOKE", "C1", "2026-01-05 08:00"],
["%T", "CALENDAR"], ["%F", "clndr_id", "clndr_name", "day_hr_cnt", "default_flag", "clndr_data"],
["%R", "C1", "5-Day", "8", "Y", ""],
["%T", "TASK"], ["%F", "task_id", "task_code", "task_name", "proj_id", "clndr_id",
"task_type", "status_code", "target_drtn_hr_cnt"],
["%R", "T1", "A1000", "Start", "P1", "C1", "TT_Task", "TK_NotStart", "40"],
["%E"],
]
path = os.path.join(tempfile.mkdtemp(), "smoke.xer")
with open(path, "w", encoding="utf-8", newline="") as f:
f.write("\r\n".join(T.join(r) for r in rows) + "\r\n")

data = p.parse_xer(path)
assert len(p.get_table(data, "TASK")) == 1
report = p.validate_schedule(data)
assert report is not None
out = subprocess.run([os.path.join(os.path.dirname(sys.executable), "cpp-xer-parser"),
"parse", path], capture_output=True, text=True, check=True).stdout
assert "TASK: 1 records" in out, out
print("cpp_xer_parser", p.__version__, "installed, parsed, validated")
79 changes: 79 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: publish

# Publishes to PyPI when a GitHub release is published. It uses PyPI trusted
# publishing (OpenID Connect): no API token is stored anywhere. Before the
# first release, the project's owner adds this repository and this workflow
# as a trusted publisher on pypi.org (environment "pypi").

on:
release:
types: [published]

permissions:
contents: read

jobs:
build:
name: Build the sdist and wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Test the commit being released
run: |
python -m pip install --upgrade pip pytest
pytest tests/ -q

- name: Build
run: |
python -m pip install --upgrade build twine
python -m build
python -m twine check --strict dist/*

- name: Install the wheel in a clean environment and parse a schedule
shell: bash
run: |
python -m venv /tmp/pkg
/tmp/pkg/bin/pip install dist/*.whl
cd /tmp && /tmp/pkg/bin/python "$GITHUB_WORKSPACE/.github/smoke_installed.py"

- name: The release tag names the version being built
shell: bash
run: |
python - <<'EOF'
import os, re, sys
version = re.search(r'(?m)^version = "([^"]+)"$', open('pyproject.toml').read()).group(1)
tag = os.environ['GITHUB_REF_NAME']
if tag != 'v' + version:
sys.exit('release tag %s is not v%s' % (tag, version))
# The changelog dates the release (not 'Unreleased').
heading = r'(?m)^## v%s \u2014 \d{4}-\d{2}-\d{2}$' % re.escape(version)
if not re.search(heading, open('CHANGELOG.md', encoding='utf-8').read()):
sys.exit('CHANGELOG.md has no dated heading for v%s' % version)
EOF

- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/cpp-xer-parser/
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- uses: pypa/gh-action-pypi-publish@release/v1
34 changes: 33 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ['3.10', '3.11', '3.12']
python: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.15']
steps:
- uses: actions/checkout@v4

Expand All @@ -38,3 +38,35 @@ jobs:
python tests/test_calendar_shift_hours_2026_10_10.py
python tests/test_p6_rules_2026_10_13.py
python tests/test_corrupt_calendar_record_2026_10_28.py

package:
name: Build, install and use the package (Python ${{ matrix.python }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# The oldest and the newest the classifiers name.
python: ['3.10', '3.15']
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Build and check
run: |
python -m pip install --upgrade pip build twine
python -m build
python -m twine check --strict dist/*

- name: Install the wheel in a clean environment and use it
shell: bash
run: |
python -m venv /tmp/pkg
/tmp/pkg/bin/pip install dist/*.whl
cd /tmp
/tmp/pkg/bin/python -c "import cpp_xer_parser as p, cpp_xer_parser.xer_parser as x; assert x._VALIDATION_AVAILABLE; assert x.get_profile.__module__ == 'cpp_xer_parser.config_profiles'; print('cpp_xer_parser', p.__version__)"
/tmp/pkg/bin/cpp-xer-parser > usage.txt || test $? -eq 1
grep -q "parse" usage.txt
/tmp/pkg/bin/python "$GITHUB_WORKSPACE/.github/smoke_installed.py"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Python
__pycache__/
# Packaging
dist/
build/
*.egg-info/
*.pyc
*.pyo
*.pyd
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to `cpp-xer-parser` are documented here. Versioning follows

---

## v0.6.1 — 2026-11-09

The parser installs from PyPI: `pip install cpp-xer-parser`. Nothing it computes changes.

### Added

- **Packaging** (`pyproject.toml`). Installed, `scripts/` is the package `cpp_xer_parser`, so `from cpp_xer_parser import parse_xer` works and the generic module names (`validation`, `config_profiles`) do not land at the top level of an environment. The command `cpp-xer-parser` runs the parser's command line. A clone with `scripts/` on `sys.path` works as before: `xer_parser.py` binds its two helpers from the package when installed, else as top-level modules.
- **Release workflow** (`.github/workflows/publish.yml`). Publishing a GitHub release builds the sdist and wheel, checks the release tag names the version in `pyproject.toml`, and uploads to PyPI by trusted publishing, so no API token is stored. CI also builds the wheel, installs it in a clean environment and runs the command on every push.

## v0.6.0 — 2026-11-08

The DCMA-14 profiles in `config_profiles.py` now carry the thresholds CPP's own tools use, as CPP's written DCMA-14 definition sets them ([criticalpathpartners.ca/dcma-14-definition.html](https://criticalpathpartners.ca/dcma-14-definition.html)). The file is identical to the copy [`cpp-critical-path-validator`](https://github.com/danafitkowski/cpp-critical-path-validator) bundles. The parser itself (`xer_parser.py`) is unchanged.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include CHANGELOG.md
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# cpp-xer-parser

[![license: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![license: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/danafitkowski/cpp-xer-parser/blob/main/LICENSE)
[![python: 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![tests](https://github.com/danafitkowski/cpp-xer-parser/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/danafitkowski/cpp-xer-parser/actions/workflows/test.yml)
[![version: 0.6.0](https://img.shields.io/badge/version-0.6.0-blue.svg)](CHANGELOG.md)
[![version: 0.6.1](https://img.shields.io/badge/version-0.6.1-blue.svg)](https://github.com/danafitkowski/cpp-xer-parser/blob/main/CHANGELOG.md)

A standalone parser and generator for Primavera P6 XER files. Pure Python 3.10+, MIT-licensed, no third-party runtime dependencies.

Expand Down Expand Up @@ -37,10 +37,17 @@ It comes out of forensic schedule analysis, where a silently mangled field becom

## Install

```bash
pip install cpp-xer-parser
```

Installed, the modules are the package `cpp_xer_parser`. The command `cpp-xer-parser` runs the same command line as `python scripts/xer_parser.py`.

Or use a clone with no install: no external dependencies, just put `scripts/` on your `sys.path`.

```bash
git clone https://github.com/danafitkowski/cpp-xer-parser
cd cpp-xer-parser
# No external dependencies. Just put scripts/ on your sys.path.
```

The parser is pure Python 3.10+ with no third-party runtime dependencies.
Expand All @@ -50,10 +57,9 @@ The parser is pure Python 3.10+ with no third-party runtime dependencies.
## Quick start

```python
import sys
sys.path.insert(0, 'scripts')

from xer_parser import parse_xer, print_summary, get_table, build_wbs_map
from cpp_xer_parser import parse_xer, print_summary, get_table, build_wbs_map
# From a clone instead: sys.path.insert(0, 'scripts'), then
# from xer_parser import parse_xer, print_summary, get_table, build_wbs_map

# Parse
data = parse_xer('path/to/your.xer')
Expand Down Expand Up @@ -117,8 +123,9 @@ for t in tasks[:3]:
A blank `TASK.clndr_id` means the project calendar, not "no calendar". MPXJ writes it blank for every task of a converted MS Project file that has no task-level calendar. Looked up as it stands, `cal_map.get(task['clndr_id'])` returns `None`, and whatever runs next falls to its last resort: 8 h/day in `duration_hours_to_days`, without a word, and in `cpp-cpm-engine` a continuous seven-day week, with an ALERT, unless the caller hands it the project calendar. Take the TASK rows through the resolver before looking a calendar up:

```python
from xer_parser import (get_table, get_calendar_map, duration_hours_to_days,
resolve_task_calendars, with_resolved_calendars)
from cpp_xer_parser.xer_parser import (
get_table, get_calendar_map, duration_hours_to_days,
resolve_task_calendars, with_resolved_calendars)

resolution = resolve_task_calendars(data)
tasks = with_resolved_calendars(get_table(data, 'TASK'), resolution)
Expand Down Expand Up @@ -147,7 +154,7 @@ The most analytically interesting feature in the repo. The `compute_half_step_xe
The forensic value: anything that moves in the half-step moved because work didn't happen as planned. Anything that moves between the half-step and the full update moved because the contractor revised logic or scope.

```python
from xer_parser import compute_half_step_xer
from cpp_xer_parser import compute_half_step_xer

result = compute_half_step_xer(
base_xer_path='period_start.xer',
Expand Down Expand Up @@ -225,15 +232,15 @@ Two consequences worth being explicit about:

## License

MIT — see [LICENSE](LICENSE).
MIT — see [LICENSE](https://github.com/danafitkowski/cpp-xer-parser/blob/main/LICENSE).

You may use this parser in commercial forensic consulting, in academic research, in your own scheduling product, in court-filed expert reports. Just keep the copyright notice.

---

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). Bug reports and pull requests are welcome.
See [CONTRIBUTING.md](https://github.com/danafitkowski/cpp-xer-parser/blob/main/CONTRIBUTING.md). Bug reports and pull requests are welcome.

---

Expand Down
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[build-system]
requires = ["setuptools>=77", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "cpp-xer-parser"
version = "0.6.1"
description = "Parse and write Primavera P6 XER files in pure Python: every table, calendars, cross-reference maps, half-step XERs and DCMA-14 profiles."
readme = "README.md"
license = "MIT"
license-files = ["LICENSE"]
requires-python = ">=3.10"
authors = [{ name = "Dana Fitkowski" }]
keywords = ["primavera", "p6", "xer", "schedule", "cpm", "construction", "forensic", "dcma"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Other Audience",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
"Topic :: Office/Business :: Scheduling",
"Topic :: File Formats",
]
dependencies = []

[project.urls]
Homepage = "https://github.com/danafitkowski/cpp-xer-parser"
Changelog = "https://github.com/danafitkowski/cpp-xer-parser/blob/main/CHANGELOG.md"
Issues = "https://github.com/danafitkowski/cpp-xer-parser/issues"

[project.scripts]
cpp-xer-parser = "cpp_xer_parser.xer_parser:main"

# The modules live in scripts/, where the tests and a plain clone find them as
# top-level modules. Installed, they are the package cpp_xer_parser, so the
# generic names (validation, config_profiles) do not land at the top level.
[tool.setuptools]
package-dir = { "cpp_xer_parser" = "scripts" }
packages = ["cpp_xer_parser"]
38 changes: 38 additions & 0 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""cpp-xer-parser, installed: ``pip install cpp-xer-parser``.

The package is the repository's scripts/ directory. Everything the parser
offers is in ``cpp_xer_parser.xer_parser``; the names below are the ones
most callers need::

from cpp_xer_parser import parse_xer, get_table, print_summary

A plain clone does not import this file: it puts scripts/ on sys.path and
imports ``xer_parser`` directly, as the README's quick start shows.
"""
from .xer_parser import ( # noqa: F401
build_activity_code_map,
build_predecessor_map,
build_resource_map,
build_udf_map,
build_wbs_map,
compute_half_step_xer,
generate_summary,
generate_xer,
get_calendar_map,
get_fields,
get_table,
get_work_days_between,
parse_xer,
print_summary,
validate_schedule,
)

__version__ = '0.6.1'

__all__ = [
'parse_xer', 'get_table', 'get_fields', 'get_calendar_map',
'get_work_days_between', 'build_wbs_map', 'build_resource_map',
'build_predecessor_map', 'build_activity_code_map', 'build_udf_map',
'generate_summary', 'print_summary', 'generate_xer',
'compute_half_step_xer', 'validate_schedule', '__version__',
]
17 changes: 14 additions & 3 deletions scripts/xer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
# ─────────────────────────────────────────────
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
_CPP_COMMON = os.path.normpath(os.path.join(_SCRIPT_DIR, '..', '..', '_cpp_common', 'scripts'))
if os.path.isdir(_CPP_COMMON) and _CPP_COMMON not in sys.path:
# The package this module was imported from: 'cpp_xer_parser' when installed,
# '' from a clone or run as a script. __spec__.parent, not __package__, which
# Python 3.15 schedules for removal.
_PKG = __spec__.parent if __spec__ is not None else ''
# Only from a clone: an installed copy has no sibling _cpp_common.
if not _PKG and os.path.isdir(_CPP_COMMON) and _CPP_COMMON not in sys.path:
sys.path.insert(0, _CPP_COMMON)

# Optional imports, guarded so xer_parser stays useful in callers that do not
Expand All @@ -64,8 +69,14 @@
# raised RuntimeError on a clean clone even though their dependencies were
# sitting next to them. Keep these blocks separate.
try:
from validation import Finding, ValidationReport, BLOCK, WARN, INFO, PASS
from config_profiles import get_profile
if _PKG:
# Installed with pip, the modules are the package cpp_xer_parser.
from .validation import Finding, ValidationReport, BLOCK, WARN, INFO, PASS
from .config_profiles import get_profile
else:
# A clone with scripts/ on sys.path: they are top-level modules.
from validation import Finding, ValidationReport, BLOCK, WARN, INFO, PASS
from config_profiles import get_profile
_VALIDATION_AVAILABLE = True
except ImportError:
_VALIDATION_AVAILABLE = False
Expand Down
Loading
Loading