A CLI toolkit for TwinCAT/Beckhoff development workflows - format, lint, and convert Structured Text and TwinCAT XML files
Project description
TcTool
A CLI toolkit for TwinCAT/Beckhoff development workflows. Format, lint, and convert Structured Text (ST) and TwinCAT XML files.
Features
- ๐จ Format ST files - Consistent indentation and code style for Structured Text
- โ Lint ST files - Check for syntax issues and naming conventions
- ๐ Format XML files - Normalize TwinCAT .TcPOU XML files
- ๐ Convert ST โ XML - Bidirectional conversion between formats
Installation
pip install tctool
For development:
pip install tctool[dev]
Quick Start
Format Structured Text Files
# Check formatting (dry-run)
tctool fmt-st --check --format .
# Format files in-place
tctool fmt-st --format --inplace .
# Format a single file
tctool fmt-st --format --inplace ./src/FB_Controller.st
Lint Structured Text Files
# Check syntax and naming conventions
tctool fmt-st --check .
Format TwinCAT XML Files
# Check XML formatting
tctool fmt-xml --check ./TcPOU/src
# Format XML files
tctool fmt-xml ./TcPOU/src
Convert Between Formats
# Convert ST to TwinCAT XML
tctool st2xml ./src ./TcPOU/output
# Convert ST to XML, ignoring certain folders
tctool st2xml ./src ./TcPOU/output --ignore Tests Documentation
# Convert TwinCAT XML to ST
tctool xml2st ./TcPOU/src ./st_export
Commands
| Command | Description |
|---|---|
fmt-st |
Format and check Structured Text (.st) files |
fmt-xml |
Format TwinCAT XML (.TcPOU) files |
st2xml |
Convert Structured Text to TwinCAT XML |
xml2st |
Convert TwinCAT XML to Structured Text |
Command Options
fmt-st
tctool fmt-st [OPTIONS] [INPUT]
Arguments:
INPUT Input file or directory (default: .)
Options:
-c, --check Check syntax only
-f, --format Format code
-i, --inplace Modify files in-place
fmt-xml
tctool fmt-xml [OPTIONS] [INPUT]
Arguments:
INPUT Input file or directory (default: .)
Options:
-c, --check Check only, do not write
st2xml
tctool st2xml [OPTIONS] [INPUT] [OUTPUT]
Arguments:
INPUT Input file or directory (default: .)
OUTPUT Output directory (default: tcpou_export)
Options:
--ignore Folders to ignore
xml2st
tctool xml2st [OPTIONS] [INPUT] [OUTPUT]
Arguments:
INPUT Input file or directory (default: .)
OUTPUT Output directory (default: st_export)
Supported File Types
Input Formats
| Extension | Description |
|---|---|
.st |
Structured Text source files |
.TcPOU |
TwinCAT POU (Program Organization Unit) |
.TcDUT |
TwinCAT DUT (Data Unit Type) |
.TcGVL |
TwinCAT GVL (Global Variable List) |
.TcIO |
TwinCAT Interface |
Supported Constructs
PROGRAMFUNCTION_BLOCK(includingABSTRACT)FUNCTIONTYPE(STRUCT, ENUM)INTERFACEVAR_GLOBAL(GVL)- Methods and Properties with GET/SET accessors
Development
Setup
# Clone the repository
git clone https://github.com/bhanukiran/tctool.git
cd tctool
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # or `.venv\Scripts\activate` on Windows
# Install in development mode with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=tctool --cov-report=html
# Run specific test categories
pytest -m unit
pytest -m integration
pytest -m e2e
Code Quality
# Lint and format check
ruff check .
ruff format --check .
# Type checking
mypy src/tctool
# Auto-fix issues
ruff check --fix .
ruff format .
Project Structure
tctool/
โโโ src/tctool/
โ โโโ __init__.py
โ โโโ __main__.py
โ โโโ cli.py # CLI entry point
โ โโโ py.typed # PEP 561 marker
โ โโโ core/
โ โ โโโ __init__.py
โ โ โโโ common.py # Shared interfaces and utilities
โ โโโ converters/
โ โ โโโ __init__.py
โ โ โโโ st_to_xml.py # ST โ TwinCAT XML
โ โ โโโ xml_to_st.py # TwinCAT XML โ ST
โ โโโ formatters/
โ โโโ __init__.py
โ โโโ st_formatter.py # ST formatting and linting
โ โโโ xml_formatter.py # XML formatting
โโโ tests/
โ โโโ unit/
โ โโโ integration/
โ โโโ e2e/
โโโ pyproject.toml
โโโ README.md
โโโ LICENSE
โโโ CHANGELOG.md
โโโ CONTRIBUTING.md
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
Changelog
See CHANGELOG.md for a history of changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tc3tools-0.1.1.tar.gz.
File metadata
- Download URL: tc3tools-0.1.1.tar.gz
- Upload date:
- Size: 47.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c47bcc7c6ce912038eef5dffb2ff05fa3fb44fe9bf8f1c9ef725aa15c0d3e251
|
|
| MD5 |
081214b3b4e194345bf90d73f7707995
|
|
| BLAKE2b-256 |
3120f1d041897afe15be5ceff608993e9b4717846295ad812164e4903443de8f
|
Provenance
The following attestation bundles were made for tc3tools-0.1.1.tar.gz:
Publisher:
publish.yml on BhanuKiranChaluvadi/tctool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tc3tools-0.1.1.tar.gz -
Subject digest:
c47bcc7c6ce912038eef5dffb2ff05fa3fb44fe9bf8f1c9ef725aa15c0d3e251 - Sigstore transparency entry: 844786605
- Sigstore integration time:
-
Permalink:
BhanuKiranChaluvadi/tctool@8988c72cf87de6742c1438944c54c1c99b99d4a3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BhanuKiranChaluvadi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8988c72cf87de6742c1438944c54c1c99b99d4a3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tc3tools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tc3tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
825d6a161116cb64928c33b39dbc7f180dc6af611339d8f38cf56935995c37c7
|
|
| MD5 |
6add190d79d91401018f6bc8fa6edb50
|
|
| BLAKE2b-256 |
ec2dee31d21949833e4a5a7b70fd386ec50d3346b64e3f06cda84acaa8a5a3e3
|
Provenance
The following attestation bundles were made for tc3tools-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on BhanuKiranChaluvadi/tctool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tc3tools-0.1.1-py3-none-any.whl -
Subject digest:
825d6a161116cb64928c33b39dbc7f180dc6af611339d8f38cf56935995c37c7 - Sigstore transparency entry: 844786609
- Sigstore integration time:
-
Permalink:
BhanuKiranChaluvadi/tctool@8988c72cf87de6742c1438944c54c1c99b99d4a3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BhanuKiranChaluvadi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8988c72cf87de6742c1438944c54c1c99b99d4a3 -
Trigger Event:
workflow_dispatch
-
Statement type: