Skip to main content

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

Project description

TcTool

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 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

  • 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/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


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.2.tar.gz (47.8 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.2-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tc3tools-0.1.2.tar.gz
  • Upload date:
  • Size: 47.8 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.2.tar.gz
Algorithm Hash digest
SHA256 54f9f8a2e3ccc33cf9fafd9f0b1237bac16b9770e1d202e504e07bbf28d8a59e
MD5 260492ed063f1b9bba1bb2c9bd3c02a4
BLAKE2b-256 d5869515c011744c2e215834f60ad71d968f7bfb8817d9d35581553979590a91

See more details on using hashes here.

Provenance

The following attestation bundles were made for tc3tools-0.1.2.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.2-py3-none-any.whl.

File metadata

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

Hashes for tc3tools-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 789956899c2c6788adf2301aafd5a5ba4d0f8aa551820834c1b899a614e3ad70
MD5 cb9ea01f308f23770148dd1e57522ba0
BLAKE2b-256 dc13472d24c0793fb8d3d32385e6715747ebf956e0194384badcd41b5d602df7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tc3tools-0.1.2-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