Skip to content

Commit

Permalink
Merge pull request #6 from ZLLentz/twincat
Browse files Browse the repository at this point in the history
ENH: Add Twincat Config and Hooks
  • Loading branch information
klauer authored Apr 22, 2020
2 parents 3158130 + d4ab870 commit 031b931
Show file tree
Hide file tree
Showing 15 changed files with 2,617 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre_commit_hooks/_version.py export-subst
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v2.5.0
hooks:
- id: no-commit-to-branch
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
exclude: '^(conda-recipe/meta.yaml)$'
- id: debug-statements

- repo: https://gitlab.com/pycqa/flake8.git
rev: 3.7.9
hooks:
- id: flake8

- repo: https://github.com/timothycrosley/isort.git
rev: 4.3.21-2
hooks:
- id: isort
29 changes: 29 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- id: twincat-lineids-remover
name: TwinCAT LineID Remover
description: Eliminate TwinCAT line ID lines
entry: twincat-lineids-remover
language: python
files: .*\.TcPOU$
- id: leading-tabs-remover
name: Leading Tabs Remover
description: Replace leading tabs with 4 spaces
entry: leading-tabs-remover
language: python
- id: twincat-leading-tabs-remover
name: TwinCAT Leading Tabs Remover
description: leading-tabs-remover configured for TwinCAT
entry: leading-tabs-remover
language: python
files: .*\.(TcPOU|TcDUT|TcGVL)$
- id: xml-format
name: XML Formatter
description: Use lxml to beautify xml files
entry: xml-format
language: python
types: [xml]
- id: twincat-xml-format
name: TwinCAT XML Formatter
description: xml-format configured for TwinCAT
entry: xml-format
language: python
files: .*\.(tmc|tpy|xml)$
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include versioneer.py
include pre_commit_hooks/_version.py
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Pre-commit hooks for PCDS projects (https://pre-commit.com/)


**To install pre-commit on your machine,** use `$ brew install pre-commit`
OR `$ pip install pre-commit`
### To install pre-commit on your machine:

**On Linux,** use `$ pip install pre-commit` or `conda install pre-commit -c conda-forge` from your favorite python environment.
**On Mac,** use `$ brew install pre-commit`, or follow the Linux instructions.
**On Windows,** set up python either your favorite way or by using https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html, and then follow the Linux instructions.

### To install pre-commit hooks to a local repository:

Expand All @@ -19,3 +21,27 @@ $ pre-commit run --all-files # run on everything
$ pre-commit run # run on staged
$ git commit -am "test" # run pre-commit and - if successful - commit
```

### Issues and client integration

If pre-commit is not an available command, you may need to look into platform-specific configuration. Generally, you'll need to be in a shell environment that has access to python and with pre-commit installed as directed in the above sections. Typical issues include a misconfigured PATH variable and not having python available. For specific help on integrating with various clients and on various operation systems, see the sections below. If you solve other client integration problems for your favorite workflow, please expand this section in a pull request.

#### Shell Integration on Windows

- Make sure git is set up for normal shell use (a git installation option) if you want to use cmd or powershell
- I have had success using the Anaconda Powershell Prompt and a conda environment with pre-commit installed

#### Git Bash Integration on Windows

- Add the following to your `~/.bash_profile`: `alias python='winpty python'`, to allow python to run without hanging.
- If using conda, run `$ conda init bash`, using the conda.exe in your `~/miniconda3/scripts` folder. You may also want to set up your `~/.bash_profile` to `conda activate` your `pre-commit` environment.
- Restart your shell after doing the above.

#### TwinCAT Integrated Git on Windows

- Someone needs to investigate this one. I don't have this running locally yet and am happy enough with the shells for now.

#### VSCode Integration on Windows

- Someone needs to figure out how to get the git extension to work here.
- If your shell integration works, you can connect to this in the integrated terminal by setting `terminal.integrated.shellArgs.windows` to the same arguments as used in the Anaconda Powershell prompt shortcut's properties.
16 changes: 16 additions & 0 deletions forTwinCatRepos/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v2.5.0
hooks:
- id: no-commit-to-branch
- id: trailing-whitespace
files: \.(TcPOU|TcDUT|TcGVL)$

- repo: https://github.com/pcdshub/pre-commit-hooks.git
rev: v1.0.0
hooks:
- id: twincat-leading-tabs-remover
- id: twincat-lineids-remover
- id: twincat-xml-format
5 changes: 5 additions & 0 deletions pre_commit_hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from ._version import get_versions

__version__ = get_versions()['version']
del get_versions
Loading

0 comments on commit 031b931

Please sign in to comment.