Skip to main content

A CLI toolkit for TwinCAT/Beckhoff development workflows - format, lint, and convert Structured Text and TwinCAT XML files

Project description

tc3tools

PyPI - Version PyPI - Python Version CI codecov License: MIT

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 tc3tools

For development:

pip install tc3tools[dev]

Quick Start

Format Structured Text Files

# Check formatting (dry-run)
tc3tools fmt-st --check --format .

# Format files in-place
tc3tools fmt-st --format --inplace .

# Format a single file
tc3tools fmt-st --format --inplace ./src/FB_Controller.st

Lint Structured Text Files

# Check syntax and naming conventions
tc3tools fmt-st --check .

Format TwinCAT XML Files

# Check XML formatting
tc3tools fmt-xml --check ./TcPOU/src

# Format XML files
tc3tools fmt-xml ./TcPOU/src

Convert Between Formats

# Convert ST to TwinCAT XML
tc3tools st2xml ./src ./TcPOU/output

# Convert ST to XML, ignoring certain folders
tc3tools st2xml ./src ./TcPOU/output --ignore Tests Documentation

# Convert TwinCAT XML to ST
tc3tools 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

tc3tools 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

tc3tools fmt-xml [OPTIONS] [INPUT]

Arguments:
  INPUT           Input file or directory (default: .)

Options:
  -c, --check     Check only, do not write

st2xml

tc3tools st2xml [OPTIONS] [INPUT] [OUTPUT]

Arguments:
  INPUT           Input file or directory (default: .)
  OUTPUT          Output directory (default: tcpou_export)

Options:
  --ignore        Folders to ignore

xml2st

tc3tools 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

  • PROGRAM
  • FUNCTION_BLOCK (including ABSTRACT)
  • FUNCTION
  • TYPE (STRUCT, ENUM)
  • INTERFACE
  • VAR_GLOBAL (GVL)
  • Methods and Properties with GET/SET accessors

Development

Setup

# Clone the repository
git clone https://github.com/BhanuKiranChaluvadi/tctool.git
cd tc3tools

# 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=tc3tools --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/tc3tools

# Auto-fix issues
ruff check --fix .
ruff format .

Project Structure

tc3tools/
โ”œโ”€โ”€ src/tc3tools/
โ”‚   โ”œโ”€โ”€ __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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tc3tools-0.1.0.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tc3tools-0.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file tc3tools-0.1.0.tar.gz.

File metadata

  • Download URL: tc3tools-0.1.0.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

Hashes for tc3tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 24a9cc8a3400002d56a87d758166bc42f74b92ff2659f237f029ffdd40d6db53
MD5 fb6f1574751f059ad617aa3109a5457b
BLAKE2b-256 77d6d717ac7c136b50fbfd87d2149ec468e3322ce99f4b3f57fd516b2126490a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tc3tools-0.1.0.tar.gz:

Publisher: publish.yml on BhanuKiranChaluvadi/tctool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tc3tools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tc3tools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tc3tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb6aa62c2f135ea69fe046872d00ecbb2a4c8550bc0cbc00e296497114b9dbf
MD5 4fe10fdea41418f935ee53e84998a4c7
BLAKE2b-256 ba99a9e394339a31b203ff09b546fe6feb26b4b1450bd788b57b5866622c7bca

See more details on using hashes here.

Provenance

The following attestation bundles were made for tc3tools-0.1.0-py3-none-any.whl:

Publisher: publish.yml on BhanuKiranChaluvadi/tctool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page