Skip to content

Commit bb51dce

Browse files
PipKatRobPasMue
andauthored
Edits to RST and PY files (#28)
Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 1a48047 commit bb51dce

File tree

4 files changed

+92
-73
lines changed

4 files changed

+92
-73
lines changed

README.rst

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,31 @@ Ansys pre-commit hooks
2727
:alt: Black
2828

2929

30-
A repository containing a collection of `pre-commit`_ hooks for different purposes.
30+
This Ansys repository contains `pre-commit`_ hooks for different purposes.
31+
Currently, these hooks are available:
3132

32-
The available hooks are the following:
33-
34-
* ``add-license-headers``: Add missing license headers to files by using reuse lint and annotate.
35-
Requires repositories to have `REUSE <https://reuse.software/>`_ implemented.
33+
* ``add-license-headers``: Add missing license headers to files by using
34+
`REUSE <https://reuse.software/>`_ . To use this hook, you must
35+
have ``REUSE`` implemented in your repository.
3636

3737

3838
How to install
3939
--------------
4040

41-
At least two installation modes are provided: user and developer.
41+
The following sections provide instructions for installing the ``ansys-pre-commit-hooks``
42+
package in two installation modes: user and developer.
4243

4344
For users
4445
^^^^^^^^^
4546

46-
In order to install ansys-pre-commit-hooks library, make sure you
47-
have the latest version of `pip`_. To do so, run:
47+
Before installing the package, to ensure that you
48+
have the latest version of `pip`_, run this command:
4849

4950
.. code:: bash
5051
5152
python -m pip install -U pip
5253
53-
Then, you can simply execute:
54+
Then, to install the package, run this command:
5455

5556
.. code:: bash
5657
@@ -59,19 +60,21 @@ Then, you can simply execute:
5960
For developers
6061
^^^^^^^^^^^^^^
6162

62-
Installing ansys-pre-commit-hooks library in developer mode allows
63-
you to modify the source and enhance it.
63+
Installing the package in developer mode allows you to modify and
64+
enhance the source code.
65+
66+
Before contributing to the project, ensure that you are familiar with
67+
the `PyAnsys Developer's Guide`_.
6468

65-
Before contributing to the project, please refer to the `PyAnsys Developer's guide`_. You will
66-
need to follow these steps:
69+
For a developer installation, you must follow these steps:
6770

68-
#. Start by cloning this repository:
71+
#. Clone the repository with this command:
6972

7073
.. code:: bash
7174
7275
git clone https://github.com/ansys/pre-commit-hooks
7376
74-
#. Create a fresh-clean Python environment and activate it:
77+
#. Create a fresh-clean Python environment and activate it with these commands:
7578

7679
.. code:: bash
7780
@@ -87,14 +90,15 @@ need to follow these steps:
8790
# Activate it in Windows Powershell
8891
.venv\Scripts\Activate.ps1
8992
90-
#. Make sure you have the latest required build system tools:
93+
#. Ensure that you have the latest required build system tools by
94+
running this command:
9195

9296
.. code:: bash
9397
9498
python -m pip install -U pip flit tox twine
9599
96100
97-
#. Install the project in editable mode:
101+
#. Install the project in editable mode by running one of these commands:
98102

99103
.. code:: bash
100104
@@ -110,7 +114,7 @@ need to follow these steps:
110114
# Install all requirements
111115
python -m pip install -e .[tests,doc]
112116
113-
#. Finally, verify your development installation by running:
117+
#. Verify your development installation by running this command:
114118

115119
.. code:: bash
116120
@@ -120,37 +124,40 @@ need to follow these steps:
120124
How to test it
121125
--------------
122126

123-
This project takes advantage of `tox`_. This tool allows to automate common
124-
development tasks (similar to Makefile) but it is oriented towards Python
125-
development.
127+
This project takes advantage of `tox`_. This tool automates common
128+
development tasks (similar to Makefile), but it is oriented towards
129+
Python development.
126130

127-
Using tox
128-
^^^^^^^^^
131+
Using ``tox``
132+
^^^^^^^^^^^^^
133+
134+
While Makefile has rules, ``tox`` has environments. In fact, ``tox`` creates its
135+
own virtual environment so that anything being tested is isolated from the project
136+
to guarantee the project's integrity.
129137

130-
As Makefile has rules, `tox`_ has environments. In fact, the tool creates its
131-
own virtual environment so anything being tested is isolated from the project in
132-
order to guarantee project's integrity. The following environments commands are provided:
138+
These environment commands are provided:
133139

134-
- **tox -e style**: will check for coding style quality.
135-
- **tox -e py**: checks for unit tests.
136-
- **tox -e py-coverage**: checks for unit testing and code coverage.
137-
- **tox -e doc**: checs for documentation building process.
140+
- **tox -e style**: Checks for coding style quality.
141+
- **tox -e py**: Checks for unit tests.
142+
- **tox -e py-coverage**: Checks for unit testing and code coverage.
143+
- **tox -e doc**: Checks for successfully building the documentation.
138144

139145

140146
Raw testing
141147
^^^^^^^^^^^
142148

143-
If required, you can always call the style commands (`black`_, `isort`_,
144-
`flake8`_...) or unit testing ones (`pytest`_) from the command line. However,
145-
this does not guarantee that your project is being tested in an isolated
146-
environment, which is the reason why tools like `tox`_ exist.
149+
If required, you can always call style commands, such as `black`_, `isort`_,
150+
and `flake8`_, or unit testing commands, such as `pytest`_, from the command line.
151+
However, calling these commands does not guarantee that your project is
152+
being tested in an isolated environment, which is the reason why tools like
153+
``tox`` exist.
147154

148155

149156
A note on ``pre-commit``
150157
^^^^^^^^^^^^^^^^^^^^^^^^
151158

152159
The style checks take advantage of `pre-commit`_. Developers are not forced but
153-
encouraged to install this tool via:
160+
encouraged to install this tool by running this command:
154161

155162
.. code:: bash
156163
@@ -160,14 +167,15 @@ encouraged to install this tool via:
160167
Documentation
161168
-------------
162169

163-
For building documentation, you can either run the usual rules provided in the
164-
`Sphinx`_ Makefile, such us:
170+
For building documentation, you can run the usual rules provided in the
171+
`Sphinx`_ Makefile with a command that is formatted like this:
165172

166173
.. code:: bash
167174
168175
make -C doc/ html && your_browser_name doc/html/index.html
169176
170-
However, the recommended way of checking documentation integrity is using:
177+
However, the recommended way of checking documentation integrity is by
178+
running ``tox`` with a command that is formatted like this:
171179

172180
.. code:: bash
173181
@@ -177,8 +185,8 @@ However, the recommended way of checking documentation integrity is using:
177185
Distributing
178186
------------
179187

180-
If you would like to create either source or wheel files, start by installing
181-
the building requirements and then executing the build module:
188+
If you would like to create either source or wheel files, install
189+
the building requirements and then execute the build module with these commands:
182190

183191
.. code:: bash
184192
@@ -193,7 +201,7 @@ the building requirements and then executing the build module:
193201
.. _isort: https://github.com/PyCQA/isort
194202
.. _pip: https://pypi.org/project/pip/
195203
.. _pre-commit: https://pre-commit.com/
196-
.. _PyAnsys Developer's guide: https://dev.docs.pyansys.com/
204+
.. _PyAnsys Developer's Guide: https://dev.docs.pyansys.com/
197205
.. _pytest: https://docs.pytest.org/en/stable/
198206
.. _Sphinx: https://www.sphinx-doc.org/en/master/
199207
.. _tox: https://tox.wiki/

doc/source/_autoapi_templates/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
API reference
22
=============
33

4-
This page contains the ``ansys-pre-commit-hooks`` API reference.
4+
This section provides descriptions of all API members for Ansys pre-commit hooks.
55

66
.. toctree::
77
:titlesonly:

src/ansys/pre_commit_hooks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
"""Initialize package level imports."""
23+
"""Module for initializing package-level imports for Ansys pre-commit hooks."""
2424

2525
try:
2626
import importlib.metadata as importlib_metadata

src/ansys/pre_commit_hooks/add_license_headers.py

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
# SOFTWARE.
2323

24-
"""Run reuse for files missing license headers."""
24+
"""
25+
Module for running `REUSE <https://reuse.software/>`_ to add missing license headers to files.
26+
27+
A license header consists of the Ansys copyright statement and licensing information.
28+
"""
2529
import argparse
2630
from datetime import date as dt
2731
import json
@@ -34,17 +38,17 @@
3438

3539
def set_lint_args(parser):
3640
"""
37-
Add arguments to parser for reuse lint.
41+
Add lint arguments to the parser for `REUSE <https://reuse.software/>`_.
3842
3943
Parameters
4044
----------
4145
parser: argparse.ArgumentParser
42-
Parser without any arguments.
46+
Parser without any lint arguments.
4347
4448
Returns
4549
-------
4650
argparse.Namespace
47-
Parser Namespace containing lint arguments.
51+
Parser namespace containing lint arguments.
4852
"""
4953
parser.add_argument("--loc", type=str, help="Path to repository location", default="src")
5054
parser.add_argument("--parser")
@@ -56,19 +60,19 @@ def set_lint_args(parser):
5660

5761
def list_noncompliant_files(args, proj):
5862
"""
59-
Retrieve list of noncompliant files.
63+
Get a list of the files that are missing license headers.
6064
6165
Parameters
6266
----------
6367
args: argparse.Namespace
6468
Namespace of arguments with their values.
6569
proj: project.Project
66-
Project reuse runs on.
70+
Project to run `REUSE <https://reuse.software/>`_ on.
6771
6872
Returns
6973
-------
7074
list
71-
List of files without license headers.
75+
List of the files that are missing license headers.
7276
"""
7377
# Create a temporary file containing lint.run json output
7478
filename = None
@@ -77,7 +81,8 @@ def list_noncompliant_files(args, proj):
7781
lint.run(args, proj, tmp)
7882
filename = tmp.name
7983

80-
# Open the temporary file, load the json, and find files missing copyright & licensing info.
84+
# Open the temporary file, load the JSON file, and find files that
85+
# are missing license headers.
8186
lint_json = None
8287
with open(filename, "rb") as file:
8388
lint_json = json.load(file)
@@ -95,16 +100,18 @@ def list_noncompliant_files(args, proj):
95100

96101
def find_files_missing_header():
97102
"""
98-
Retrieve files without license header.
103+
Find files that are missing license headers and run `REUSE <https://reuse.software/>`_ on them.
99104
100105
Returns
101106
-------
102107
int
103-
Returns non-zero int if one or more files are noncompliant,
104-
or if the .reuse directory is missing.
108+
``1`` if ``REUSE`` changed all noncompliant files.
109+
110+
``2`` if the ``.reuse`` directory does not exist in the root path of the
111+
GitHub repository.
105112
"""
106113
# Set up argparse for location, parser, and lint
107-
# Lint contains 4 args: quiet, json, plain, and no_multiprocessing
114+
# Lint contains four arguments: quiet, json, plain, and no_multiprocessing
108115
parser = argparse.ArgumentParser()
109116
args = set_lint_args(parser)
110117
proj = project.Project(rf"{args.loc}")
@@ -114,62 +121,66 @@ def find_files_missing_header():
114121
# Get current year for license file
115122
year = dt.today().year
116123

117-
# If there are files missing headers, run reuse and return 1
124+
# If there are files missing headers, run REUSE and return 1
118125
if missing_headers:
119-
# Returns 1 if reuse changes all noncompliant files
120-
# Returns 2 if .reuse directory does not exist
126+
# Returns 1 if REUSE changes all noncompliant files
127+
# Returns 2 if .reuse directory does not exist in root of git repository
121128
return run_reuse(parser, year, args.loc, missing_headers)
122129

123130
return 0
124131

125132

126133
def check_reuse_dir():
127134
"""
128-
Check .reuse directory exists in root of git repository.
135+
Check if the ``.reuse`` directory exists in the root path of the git repository.
129136
130137
Returns
131138
-------
132139
str
133-
Root path of git repository.
140+
Root path of the git repository.
134141
int
135-
If .reuse directory does not exist at root path of git repository.
142+
``1`` if the ``.reuse`` directory does not exist in the root path
143+
of the git repository.
136144
"""
137145
# Get root directory of current git repository
138146
git_repo = git.Repo(os.getcwd(), search_parent_directories=True)
139147
git_root = git_repo.git.rev_parse("--show-toplevel")
140148

141-
# If .reuse folder does not exist in git repository root, return 1
149+
# If .reuse folder does not exist in root of git repository, return 1
142150
if not os.path.isdir(os.path.join(git_root, ".reuse")):
143-
print(f"Please ensure the .reuse directory is in {git_root}")
151+
print(f"Ensure that the .reuse directory is in {git_root}.")
144152
return 1
145153

146154
return git_root
147155

148156

149157
def run_reuse(parser, year, loc, missing_headers):
150158
"""
151-
Run reuse command on files without license headers.
159+
Run `REUSE <https://reuse.software/>`_ on files that are missing license headers.
152160
153161
Parameters
154162
----------
155163
parser: argparse.ArgumentParser
156-
Parser containing previously set arguments.
164+
Parser containing the previously set arguments.
157165
year: int
158-
Current year for license header.
166+
Current year for the license header.
159167
loc: str
160-
Location to search for files missing headers.
168+
Location to search for files that are missing license headers.
161169
missing_headers: list
162-
List of files that are missing headers.
170+
List of files that are missing license headers.
163171
164172
Returns
165173
-------
166174
int
167-
Fails pre-commit hook on return 1
175+
``1`` if the pre-commit hook fails.
176+
177+
``2`` if the ``.reuse`` directory does not exist in the root path
178+
of the GitHub repository.
168179
"""
169-
# Add header arguments to parser which include: copyright, license, contributor, year,
170-
# style, copyright-style, template, exclude-year, merge-copyrights, single-line,
180+
# Add header arguments to parser. Arguments are: copyright, license, contributor,
181+
# year, style, copyright-style, template, exclude-year, merge-copyrights, single-line,
171182
# multi-line, explicit-license, force-dot-license, recursive, no-replace,
172-
# skip-unrecognized, skip-existing
183+
# skip-unrecognized, and skip-existing.
173184
header.add_arguments(parser)
174185

175186
git_root = check_reuse_dir()
@@ -198,7 +209,7 @@ def run_reuse(parser, year, loc, missing_headers):
198209

199210

200211
def main():
201-
"""Find files missing license header & run reuse on them."""
212+
"""Find files missing license headers and run `REUSE <https://reuse.software/>`_ on them."""
202213
return find_files_missing_header()
203214

204215

0 commit comments

Comments
 (0)