pcdshub / pre-commit-hooks

Pre-commit hooks for PCDS projects (https://pre-commit.com/)
Other
10 stars 7 forks source link

ENH: Add Twincat Config and Hooks #6

Closed ZLLentz closed 4 years ago

ZLLentz commented 4 years ago

This PR creates a reasonable forTwinCatRepos configuration, sets up this repo to be a source of hooks, and adds the following custom hooks:

For the tabs, I couldn't find an existing solution to do what I wanted (the existing hooks removed ALL tabs, not just leading tabs), so I rolled my own. I included a duplicate entry for twincat-leading-tabs-remover in addition to the generic entry to simplify the per-repo configuration.

For the lineids, this clearly needed to be custom. It's pretty simple though.

For the xml formatter, I did not find an existing pre-commit solution, so this was originally going to be Ken's https://gist.github.com/klauer/a1489e408042a95ed9e804e37e7832c2 adjusted to work with pre-commit. Unfortunately, bash isn't installed on most Windows machines, and these need to be run on Windows. xmllint, however, is available on windows, and so the next version was simply a python script that shelled out to xmllint. This worked great using a conda environment, where libxml2 gets installed with an xmllint binary even on windows. Unfortunately, this didn't work using the simple pip virtualenvs that pre-commit uses, which do not install an xmllint binary. Instead of fighting this, I conceded and switched to an uglier solution using lxml which seems to work correctly on Linux and Windows using pre-commit. I again include two hook ids here, one generic hook and one that has the TwinCAT-specific targeting.

The above also required the following changes to the repo:

Note that this PR assumes that we will tag this repo with v1.0.0 afterwards to be referenced in the TwinCAT pre-commit configs.

An example of these hooks running on my test branch: https://github.com/ZLLentz/lcls2-cc-lib/commit/4aa529495d4ea0c12b8606f2c32cb989e4972493

I've confirmed that the formatted xml files (tmc, NC export, CoE startup export) load properly when opened back up in TwinCAT.

closes #2

ZLLentz commented 4 years ago

Ok, I think this is ready to merge. I'm going to slide over and make an issue for configuring the built-in twincat git thing as soon as I figure out the right words to use.