@@ -31,189 +31,14 @@ Ansys pre-commit hooks
31
31
:alt: pre-commit.ci status
32
32
33
33
This Ansys repository contains `pre-commit `_ hooks for different purposes.
34
- Currently, these hooks are available:
34
+ The following hooks are currently available:
35
35
36
36
* ``add-license-headers ``: Add missing license headers to files by using
37
37
`REUSE <https://reuse.software/ >`_ . To use this hook, you must
38
38
have ``REUSE `` implemented in your repository.
39
39
* ``tech-review ``: Do a technical review of your repository according to
40
40
`Ansys repository requirements <https://dev.docs.pyansys.com/packaging/structure.html >`_
41
41
42
- ``add-license-headers `` setup
43
- -----------------------------
44
-
45
- Add required directories
46
- ^^^^^^^^^^^^^^^^^^^^^^^^
47
-
48
- If you are using the ansys.jinja2 template and MIT.txt license, skip this step. By default, the hook will make symbolic links
49
- from its "assets" directory containing LICENSES/MIT.txt and .reuse/templates/ansys.jinja2
50
- to your repository when the hook runs. The .reuse and LICENSES directories will be deleted once the hook is
51
- done running.
52
-
53
- If you are using a custom template, create a directory named ``.reuse ``, and if you are using a custom license, create a directory
54
- named ``LICENSES `` in the root of your repository. The custom template cannot be named ``ansys.jinja2 ``, otherwise it will be removed
55
- after the hook is done running. The custom license cannot be named ``MIT.txt `` for the same reason. The ``.reuse `` and/or ``LICENSES ``
56
- directories will have to be committed to your repository and will not be removed once the hook is done running as long as there
57
- are custom templates or licenses in those directories. Your project should have the following layout:
58
-
59
- ::
60
-
61
- project
62
- ├── LICENCES
63
- │ └── license_name.txt
64
- ├── .reuse
65
- │ └── templates
66
- │ └── template_name.jinja2
67
- ├── src
68
- ├── examples
69
- ├── tests
70
- ├── .pre-commit-config.yaml
71
- ├── pyproject.toml
72
-
73
- Where ``license_name `` is the name of the license that is being used, for example, MIT.txt, and
74
- ``template_name `` is the name of the custom template being used. The jinja2 file contains the
75
- template for the license headers that are added to the files.
76
-
77
- Licenses that are supported by ``REUSE `` can be found in the
78
- `spdx/license-list-data <https://github.com/spdx/license-list-data/tree/main/text >`_ repository.
79
- Please select a license text file from that repository, and copy it to the LICENSES directory.
80
-
81
- Set custom arguments
82
- ^^^^^^^^^^^^^^^^^^^^
83
-
84
- .. code :: yaml
85
-
86
- - repo : https://github.com/ansys/pre-commit-hooks
87
- rev : v0.5.1
88
- hooks :
89
- - id : add-license-headers
90
- args : ["--custom_copyright", "custom copyright phrase", "--custom_template", "template_name", "--custom_license", "license_name", "--ignore_license_check", "--start_year", "2023"]
91
-
92
- ``args `` can also be formatted as follows:
93
-
94
- .. code :: yaml
95
-
96
- args :
97
- - --custom_copyright=custom copyright phrase
98
- - --custom_template=template_name
99
- - --custom_license=license_name
100
- - --ignore_license_check
101
- - --start_year=2023
102
-
103
- * ``custom copyright phrase `` is the copyright line you want to include in the license
104
- header. By default, it uses ``"ANSYS, Inc. and/or its affiliates." ``.
105
- * ``template_name `` is the name of the .jinja2 file located in ``.reuse/templates/ ``.
106
- By default, it uses ``ansys ``.
107
- * ``license_name `` is the name of the license being used. For example, MIT, ECL-1.0, etc.
108
- To view a list of licenses that are supported by ``REUSE ``, see
109
- https://github.com/spdx/license-list-data/tree/main/text. By default it uses ``MIT ``.
110
- * ``ignore_license_check `` is whether or not to check for the license in the header. By default,
111
- it is ``False ``, meaning the files are checked for both the copyright and licensing information
112
- in the header. Add ``--ignore_license_check `` to ignore checking for licensing information
113
- in the files.
114
- * ``start_year `` is the start year of the copyright statement. By default, the ``start_year `` is
115
- the current year, making the copyright statement
116
- "Copyright (C) 2024 ANSYS, Inc. and/or its affiliates." If you are adding license headers
117
- to packages released before the current year, add the ``start_year `` argument with the year your
118
- package was released. For example, if ``start_year `` is 2023, the copyright statement would be
119
- "Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates." assuming the current year is 2024.
120
-
121
- Specify directories to run the hook on
122
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123
-
124
- By default, the hook will run on proto files in any directory, as well as python files within
125
- directories named ``src ``, ``examples ``, and ``tests ``. To specify additional files and/or directories
126
- the hook should run on, add the necessary regex to the ``files `` line in your
127
- .pre-commit-config.yaml file:
128
-
129
- .. code :: yaml
130
-
131
- - repo : https://github.com/ansys/pre-commit-hooks
132
- rev : v0.5.1
133
- hooks :
134
- - id : add-license-headers
135
- files : ' (src|examples|tests|newFolder)/.*\.(py|newExtension)|\.(proto|newExtension)'
136
-
137
- Ignore specific files or file types
138
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139
-
140
- In .pre-commit-config.yaml:
141
-
142
- .. code :: yaml
143
-
144
- - repo : https://github.com/ansys/pre-commit-hooks
145
- rev : v0.5.1
146
- hooks :
147
- - id : add-license-headers
148
- exclude : |
149
- (?x)^(
150
- path/to/file1.py |
151
- path/to/.*\.(ts|cpp) |
152
- (.folder1|folder2)/.* |
153
- .*\.js |
154
- \..* |
155
- )$
156
-
157
- * ``path/to/file1.py `` excludes the stated file.
158
- * ``path/to/.*\.(ts|cpp) `` excludes all .ts and .cpp files within the ``path/to `` directory.
159
- * ``(.folder1|folder2)/.* `` excludes directories named .folder1 and folder2.
160
- * ``.*\.js `` excludes all .js files in all directories.
161
- * ``\..* `` excludes all hidden files.
162
-
163
- ``tech-review `` setup
164
- ---------------------
165
-
166
- These are the default values for the arguments of the tech-review hook:
167
-
168
- * ``--author_maint_name=ANSYS, Inc. ``
169
-
170
- * ``--license=MIT ``
171
- * ``--url=https://github.com/ansys/{repo-name} ``, replacing ``repo-name `` with the name of the repository
172
-
173
- The ``--author_maint_name `` is the name of the author and maintainer in the ``pyproject.toml `` file.
174
- By default, it is "Ansys, Inc.".
175
-
176
- The ``--author_maint_email `` is the email of the author and maintainer in the ``pyproject.toml `` file.
177
- By default, it is "
[email protected] ".
178
-
179
- The ``--license `` argument is the license that is being used by your repository. By default, it is
180
- MIT.
181
-
182
- The ``--url `` argument is automatically rendered based on the repository name. If your repository
183
- is not in the Ansys organization, please add this argument to your configuration in
184
- .pre-commit-config.yaml.
185
-
186
- The ``--product `` argument is required if a ``README.rst `` or ``README.md `` file does not
187
- exist in your repository and you want the template to render correctly. The product
188
- for ``PyMechanical `` would be ``mechanical ``, for example.
189
-
190
- The ``--non_compliant_name `` flag can be used if your repository does not follow the typical
191
- naming convention of ``ansys-*-* ``.
192
-
193
- Technical review hook in ``ansys/pre-commit-hooks ``' .pre-commit-config.yaml file:
194
-
195
- .. code :: yaml
196
-
197
- - repo : https://github.com/ansys/pre-commit-hooks
198
- rev : v0.5.1
199
- hooks :
200
- - id : tech-review
201
- args :
202
- - --product=pre_commit_hooks
203
- - --non_compliant_name
204
-
205
- Technical review hook in ``PyMechanical ``'s .pre-commit-config.yaml file:
206
-
207
- .. code :: yaml
208
-
209
- - repo : https://github.com/ansys/pre-commit-hooks
210
- rev : v0.5.1
211
- hooks :
212
- - id : tech-review
213
- args :
214
- - --product=mechanical
215
-
216
-
217
42
How to install
218
43
--------------
219
44
0 commit comments