This PR creates a reasonable forTwinCatRepos configuration, sets up this repo to be a source of hooks, and adds the following custom hooks:
leading-tabs-remover
twincat-lineids-remover
xml-format
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:
Created a pre_commit_hooks python module, complete with setup.py so that pre-commit could install it.
Installed versioneer to keep track of the version
Added a pre-commit configuration for this repo using the forPythonRepos configuration
Note that this PR assumes that we will tag this repo with v1.0.0 afterwards to be referenced in the TwinCATpre-commit configs.
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.
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 withpre-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 apython
script that shelled out toxmllint
. This worked great using a conda environment, wherelibxml2
gets installed with anxmllint
binary even on windows. Unfortunately, this didn't work using the simple pip virtualenvs thatpre-commit
uses, which do not install anxmllint
binary. Instead of fighting this, I conceded and switched to an uglier solution usinglxml
which seems to work correctly on Linux and Windows usingpre-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:
pre_commit_hooks
python module, complete withsetup.py
so thatpre-commit
could install it.versioneer
to keep track of the versionpre-commit
configuration for this repo using theforPythonRepos
configurationNote that this PR assumes that we will tag this repo with
v1.0.0
afterwards to be referenced in theTwinCAT
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