ansys-pre-commit-hooks 0.3.1__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ansys-pre-commit-hooks
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: A Python wrapper to create Ansys-tailored pre-commit hooks
5
5
  Author-email: "ANSYS, Inc." <pyansys.core@ansys.com>
6
6
  Maintainer-email: "ANSYS, Inc." <pyansys.core@ansys.com>
@@ -16,12 +16,12 @@ Classifier: Operating System :: OS Independent
16
16
  Requires-Dist: importlib-metadata==7.1.0
17
17
  Requires-Dist: reuse==3.0.2
18
18
  Requires-Dist: GitPython==3.1.43
19
- Requires-Dist: ansys-sphinx-theme[autoapi]==0.15.2 ; extra == "doc"
19
+ Requires-Dist: ansys-sphinx-theme[autoapi]==0.16.5 ; extra == "doc"
20
20
  Requires-Dist: numpydoc==1.7.0 ; extra == "doc"
21
21
  Requires-Dist: sphinx==7.3.7 ; extra == "doc"
22
- Requires-Dist: sphinx-autodoc-typehints==2.1.0 ; extra == "doc"
22
+ Requires-Dist: sphinx-autodoc-typehints==2.1.1 ; extra == "doc"
23
23
  Requires-Dist: sphinx-copybutton==0.5.1 ; extra == "doc"
24
- Requires-Dist: pytest==8.1.1 ; extra == "tests"
24
+ Requires-Dist: pytest==8.2.2 ; extra == "tests"
25
25
  Requires-Dist: pytest-cov==5.0.0 ; extra == "tests"
26
26
  Project-URL: Documentation, https://pre-commit-hooks.docs.ansys.com
27
27
  Project-URL: Homepage, https://github.com/ansys/pre-commit-hooks
@@ -116,7 +116,7 @@ Set custom arguments
116
116
  .. code:: yaml
117
117
 
118
118
  - repo: https://github.com/ansys/pre-commit-hooks
119
- rev: v0.3.1
119
+ rev: v0.3.2
120
120
  hooks:
121
121
  - id: add-license-headers
122
122
  args: ["--custom_copyright", "custom copyright phrase", "--custom_template", "template_name", "--custom_license", "license_name", "--ignore_license_check", "--start_year", "2023"]
@@ -161,7 +161,7 @@ the hook should run on, add the necessary regex to the ``files`` line in your
161
161
  .. code:: yaml
162
162
 
163
163
  - repo: https://github.com/ansys/pre-commit-hooks
164
- rev: v0.3.1
164
+ rev: v0.3.2
165
165
  hooks:
166
166
  - id: add-license-headers
167
167
  files: '(src|examples|tests|newFolder)/.*\.(py|newExtension)|\.(proto|newExtension)'
@@ -174,7 +174,7 @@ In .pre-commit-config.yaml:
174
174
  .. code:: yaml
175
175
 
176
176
  - repo: https://github.com/ansys/pre-commit-hooks
177
- rev: v0.3.1
177
+ rev: v0.3.2
178
178
  hooks:
179
179
  - id: add-license-headers
180
180
  exclude: |
@@ -84,7 +84,7 @@ Set custom arguments
84
84
  .. code:: yaml
85
85
 
86
86
  - repo: https://github.com/ansys/pre-commit-hooks
87
- rev: v0.3.1
87
+ rev: v0.3.2
88
88
  hooks:
89
89
  - id: add-license-headers
90
90
  args: ["--custom_copyright", "custom copyright phrase", "--custom_template", "template_name", "--custom_license", "license_name", "--ignore_license_check", "--start_year", "2023"]
@@ -129,7 +129,7 @@ the hook should run on, add the necessary regex to the ``files`` line in your
129
129
  .. code:: yaml
130
130
 
131
131
  - repo: https://github.com/ansys/pre-commit-hooks
132
- rev: v0.3.1
132
+ rev: v0.3.2
133
133
  hooks:
134
134
  - id: add-license-headers
135
135
  files: '(src|examples|tests|newFolder)/.*\.(py|newExtension)|\.(proto|newExtension)'
@@ -142,7 +142,7 @@ In .pre-commit-config.yaml:
142
142
  .. code:: yaml
143
143
 
144
144
  - repo: https://github.com/ansys/pre-commit-hooks
145
- rev: v0.3.1
145
+ rev: v0.3.2
146
146
  hooks:
147
147
  - id: add-license-headers
148
148
  exclude: |
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
5
5
  [project]
6
6
  # Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
7
7
  name = "ansys-pre-commit-hooks"
8
- version = "0.3.1"
8
+ version = "0.3.2"
9
9
  description = "A Python wrapper to create Ansys-tailored pre-commit hooks"
10
10
  readme = "README.rst"
11
11
  requires-python = ">=3.9,<4"
@@ -34,14 +34,14 @@ dependencies = [
34
34
 
35
35
  [project.optional-dependencies]
36
36
  tests = [
37
- "pytest==8.1.1",
37
+ "pytest==8.2.2",
38
38
  "pytest-cov==5.0.0",
39
39
  ]
40
40
  doc = [
41
- "ansys-sphinx-theme[autoapi]==0.15.2",
41
+ "ansys-sphinx-theme[autoapi]==0.16.5",
42
42
  "numpydoc==1.7.0",
43
43
  "sphinx==7.3.7",
44
- "sphinx-autodoc-typehints==2.1.0",
44
+ "sphinx-autodoc-typehints==2.1.1",
45
45
  "sphinx-copybutton==0.5.1",
46
46
  ]
47
47
 
@@ -66,7 +66,6 @@ line-length = 100
66
66
  profile = "black"
67
67
  force_sort_within_sections = true
68
68
  line_length = 100
69
- default_section = "THIRDPARTY"
70
69
  src_paths = ["doc", "src", "tests"]
71
70
 
72
71
  [tool.coverage.run]
@@ -115,4 +114,4 @@ showcontent = true
115
114
  [[tool.towncrier.type]]
116
115
  directory = "miscellaneous"
117
116
  name = "Miscellaneous"
118
- showcontent = true
117
+ showcontent = true
@@ -251,14 +251,7 @@ def set_header_args(
251
251
  return args
252
252
 
253
253
 
254
- def check_exists(
255
- changed_headers: int,
256
- parser: argparse.ArgumentParser,
257
- values: dict,
258
- proj: project.Project,
259
- missing_headers: list,
260
- i: int,
261
- ) -> int:
254
+ def non_recursive_file_check(changed_headers, parser, values, proj, missing_headers):
262
255
  """
263
256
  Check if the committed file is missing its header.
264
257
 
@@ -328,6 +321,89 @@ def check_exists(
328
321
  return changed_headers
329
322
 
330
323
 
324
+ def recursive_file_check(changed_headers, parser, values, proj, missing_headers, count):
325
+ """
326
+ Check if the committed file is missing its header.
327
+
328
+ Parameters
329
+ ----------
330
+ changed_headers: int
331
+ ``0`` if no headers were added or updated.
332
+ ``1`` if headers were added or updated.
333
+ parser: argparse.ArgumentParser
334
+ Parser containing default license header arguments.
335
+ values: dict
336
+ Dictionary containing the values of files, copyright,
337
+ template, license, changed_headers, year, and git_repo.
338
+ proj: project.Project
339
+ Project to run `REUSE <https://reuse.software/>`_ on.
340
+ missing_headers: list
341
+ Committed files that are missing copyright and/or
342
+ license information in their headers.
343
+ count: int
344
+ Integer of the location in the files array.
345
+
346
+ Returns
347
+ -------
348
+ int
349
+ ``0`` if all files contain headers and are up to date.
350
+ ``1`` if ``REUSE`` changed all noncompliant files.
351
+ """
352
+ files = values["files"]
353
+ start_year = values["start_year"]
354
+ current_year = values["current_year"]
355
+ copyright = values["copyright"]
356
+ template = values["template"]
357
+
358
+ if count < len(files):
359
+ # If the committed file is in missing_headers
360
+ file = files[count]
361
+
362
+ if (file in missing_headers) or (os.path.getsize(file) == 0):
363
+ changed_headers = 1
364
+ # Run REUSE on the file
365
+ args = set_header_args(parser, start_year, current_year, file, copyright, template)
366
+ if not args.ignore_license_check:
367
+ args.license = [values["license"]]
368
+ _annotate.run(args, proj)
369
+
370
+ # Check if the next file is in missing_headers
371
+ return recursive_file_check(
372
+ changed_headers, parser, values, proj, missing_headers, count + 1
373
+ )
374
+ else:
375
+ # Save current copy of file
376
+ before_hook = NamedTemporaryFile(mode="w", delete=False).name
377
+ shutil.copyfile(file, before_hook)
378
+
379
+ # Update the header
380
+ # tmp captures the stdout of the header.run() function
381
+ with NamedTemporaryFile(mode="w", delete=True) as tmp:
382
+ args = set_header_args(parser, start_year, current_year, file, copyright, template)
383
+ _annotate.run(args, proj, tmp)
384
+
385
+ # Check if the file before add-license-headers was run is the same as the one
386
+ # after add-license-headers was run. If not, apply the syntax changes
387
+ # from other hooks before add-license-headers was run to the file
388
+ if check_same_content(before_hook, file) == False:
389
+ add_hook_changes(before_hook, file)
390
+
391
+ # Check if the file content before add-license-headers was run has been changed
392
+ # Assuming the syntax was fixed in the above if statement, this check is
393
+ # solely for the file's content
394
+ if check_same_content(before_hook, file) == False:
395
+ changed_headers = 1
396
+ print(f"Successfully changed header of {file}")
397
+
398
+ os.remove(before_hook)
399
+
400
+ return recursive_file_check(
401
+ changed_headers, parser, values, proj, missing_headers, count + 1
402
+ )
403
+
404
+ return changed_headers
405
+
406
+
331
407
  def check_same_content(before_hook, after_hook):
332
408
  """
333
409
  Check if file before the hook ran is the same as after the hook ran.
@@ -635,7 +711,14 @@ def find_files_missing_header() -> int:
635
711
 
636
712
  # Add or update headers of required files.
637
713
  # Return 1 if files were added or updated, and return 0 if no files were altered.
638
- file_return_code = check_exists(changed_headers, parser, values, proj, missing_headers, 0)
714
+ if len(values["files"]) <= (sys.getrecursionlimit() - 2):
715
+ file_return_code = recursive_file_check(
716
+ changed_headers, parser, values, proj, missing_headers, 0
717
+ )
718
+ else:
719
+ file_return_code = non_recursive_file_check(
720
+ changed_headers, parser, values, proj, missing_headers
721
+ )
639
722
 
640
723
  # Unlink default files & remove .reuse and LICENSES folders if empty
641
724
  cleanup(assets, os_git_root)