Skip to content

Commit c14c88f

Browse files
authored
Implementing pre-commit.ci and blacken-docs hook (#228)
* Pre-commit autoupdate * Updating pipeline * Adding pre-commit blacken-docs hook * Typo in workflow * Blacken docs * Bugged snippet * Add disclaimer * Avoid concurrent workflows * Adding empty line (by @germa89)
1 parent 476298d commit c14c88f

15 files changed

+111
-101
lines changed

.github/workflows/ci-build.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,35 @@ env:
1212
MAIN_PYTHON_VERSION: '3.10'
1313
CNAME: 'dev.docs.pyansys.com'
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1519
permissions:
1620
contents: write
1721
pull-requests: write
1822

1923
jobs:
2024

21-
code-style:
22-
name: "Check code style"
23-
runs-on: ubuntu-latest
24-
steps:
25-
- name: "Check code style"
26-
uses: pyansys/actions/code-style@v1
27-
with:
28-
python-version: ${{ env.MAIN_PYTHON_VERSION }}
29-
use-python-cache: false
30-
3125
doc-style:
3226
name: "Check documentation style"
3327
runs-on: ubuntu-latest
3428
steps:
3529
- name: "Check documentation style"
36-
uses: pyansys/actions/doc-style@v1
30+
uses: pyansys/actions/doc-style@v2
3731
with:
3832
token: ${{ secrets.GITHUB_TOKEN }}
3933

4034
doc-build:
4135
name: "Build project documentation"
42-
needs: [code-style, doc-style]
36+
needs: doc-style
4337
runs-on: ubuntu-latest
4438
steps:
4539
- name: "Install mermaid-cli"
4640
run: npm install -g @mermaid-js/mermaid-cli
4741

4842
- name: "Build project documentation"
49-
uses: pyansys/actions/doc-build@v1
43+
uses: pyansys/actions/doc-build@v2
5044
with:
5145
python-version: ${{ env.MAIN_PYTHON_VERSION }}
5246
use-python-cache: false
@@ -61,7 +55,7 @@ jobs:
6155
needs: doc-build
6256
steps:
6357
- name: "Deploy development documentation"
64-
uses: pyansys/actions/doc-deploy-dev@v1
58+
uses: pyansys/actions/doc-deploy-dev@v2
6559
with:
6660
cname: ${{ env.CNAME }}
6761
token: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ repos:
22

33

44
- repo: https://github.com/psf/black
5-
rev: 22.3.0
5+
rev: 22.12.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
66
hooks:
77
- id: black
88
args: ["doc/source/conf.py"]
99

10+
- repo: https://github.com/adamchainz/blacken-docs
11+
rev: v1.12.1
12+
hooks:
13+
- id: blacken-docs
14+
additional_dependencies: [black==22.12.0]
15+
1016
- repo: https://github.com/pycqa/isort
11-
rev: 5.10.1
17+
rev: 5.11.4
1218
hooks:
1319
- id: isort
1420
args: [
@@ -18,24 +24,24 @@ repos:
1824
]
1925

2026
- repo: https://github.com/PyCQA/flake8
21-
rev: 5.0.4
27+
rev: 6.0.0
2228
hooks:
2329
- id: flake8
2430

2531
- repo: https://github.com/codespell-project/codespell
26-
rev: v2.1.0
32+
rev: v2.2.2
2733
hooks:
2834
- id: codespell
2935
args: [--ignore-words=ignore_words.txt, -S \*.pyc\,\*.xml\,\*.txt\,\*.gif\,\*.png\,\*.jpg\,\*.js\,\*.html\,\*.doctree\,\*.ttf\,\*.woff\,\*.woff2\,\*.eot\,\*.mp4\,\*.inv\,\*.pickle\,\*.ipynb\,flycheck\*\,./.git/\*\,./.hypothesis/\*\,\*.yml\,./doc/build/\*\,./doc/images/\*\,./dist/\*\,\*~\,.hypothesis\*\,./doc/source/examples/\*\,\*cover\,\*.dat\,\*.mac]
3036

3137
- repo: https://github.com/pre-commit/pre-commit-hooks
32-
rev: v4.1.0
38+
rev: v4.4.0
3339
hooks:
3440
- id: check-merge-conflict
3541
- id: debug-statements
3642

3743
- repo: https://github.com/python-jsonschema/check-jsonschema
38-
rev: 0.16.0
44+
rev: 0.19.2
3945
hooks:
4046
- id: check-github-workflows
4147
name: "Check GitHub workflows"

doc/source/abstractions/data-transfer.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ For example, consider a simple mesh in MAPDL:
1212

1313
.. code:: python
1414
15-
>>> mapdl.prep7()
16-
>>> mapdl.block(0, 1, 0, 1, 0, 1)
17-
>>> mapdl.et(1, 186)
18-
>>> mapdl.vmesh('ALL')
15+
mapdl.prep7()
16+
mapdl.block(0, 1, 0, 1, 0, 1)
17+
mapdl.et(1, 186)
18+
mapdl.vmesh("ALL")
1919
2020
At this point, there are only two ways within MAPDL to access the nodes and
2121
connectivity of the mesh, You can either print it using the ``NLIST``
@@ -29,13 +29,14 @@ methods are remarkably inefficient, requiring:
2929

3030
This example prints node coordinates using the ``NLIST`` command:
3131

32-
.. code:: python
32+
.. code:: pycon
3333
3434
>>> print(mapdl.nlist())
35-
NODE X Y Z
36-
1 0.0000 1.0000 0.0000
37-
2 0.0000 0.0000 0.0000
38-
3 0.0000 0.75000 0.0000
35+
36+
NODE X Y Z
37+
1 0.0000 1.0000 0.0000
38+
2 0.0000 0.0000 0.0000
39+
3 0.0000 0.75000 0.0000
3940
4041
It's more efficient to transfer the node array as either a
4142
series of repeated ``Node`` messages or, better yet, to serialize
@@ -54,7 +55,7 @@ the nodes of the mesh are accessible as the ``nodes`` attribute within
5455
the ``mesh`` attribute, which provides an encapsulation of the mesh
5556
within the MAPDL database.
5657

57-
.. code:: python
58+
.. code:: pycon
5859
5960
>>> mapdl.mesh.nodes
6061
array([[0. , 1. , 0. ],

doc/source/abstractions/service.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ way to do this is to include a function to launch the service.
6363
This example includes ``launch_mapdl``, which brokers a connection via the
6464
``Mapdl`` class:
6565

66-
.. code:: python
66+
.. code:: pycon
6767
6868
>>> from ansys.mapdl.core import Mapdl
69-
>>> mapdl = Mapdl(ip=<IP Address>, port=<Port>)
69+
>>> mapdl = Mapdl(ip=whatever_ip, port=whatever_port)
7070
>>> print(mapdl)
71+
7172
Product: Ansys Mechanical Enterprise
7273
MAPDL Version: 21.2
7374
ansys.mapdl Version: 0.59.dev0

doc/source/coding-style/deprecation.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ a minor release or two.
2424
2525
import warnings
2626
27-
class FieldAnalysis2D():
27+
28+
class FieldAnalysis2D:
2829
"""Class docstring"""
2930
3031
def assignmaterial(self, obj, mat):
@@ -37,12 +38,16 @@ a minor release or two.
3738
# one of the following:
3839
3940
# raise a DeprecationWarning. User won't have to change anything
40-
warnings.warn('`assignmaterial` is deprecated. Use `assign_material` instead.',
41-
DeprecationWarning)
41+
warnings.warn(
42+
"`assignmaterial` is deprecated. Use `assign_material` instead.",
43+
DeprecationWarning,
44+
)
4245
self.assign_material(obj, mat)
4346
4447
# or raise an AttributeError (could also make a custom DeprecationError)
45-
raise AttributeError('`assignmaterial` is deprecated. Use `assign_material` instead.')
48+
raise AttributeError(
49+
"`assignmaterial` is deprecated. Use `assign_material` instead."
50+
)
4651
4752
def assign_material(self, obj, mat):
4853
"""Assign a material to one or more objects.
@@ -62,17 +67,17 @@ method. Simply raise an ``AttributeError`` as part of the class or raise an ``Ex
6267
This function has been deprecated.
6368
6469
"""
65-
raise Exception('`my_function` has been deprecated')
70+
raise Exception("`my_function` has been deprecated")
6671
67-
Because there is no built-in depreciation error within Python, an alternate
72+
Because there is no built-in deprecation error within Python, an alternate
6873
approach is to create a custom ``DeprecationError``.
6974

7075
.. code:: python
7176
7277
class DeprecationError(RuntimeError):
73-
"""Used for depreciated methods and functions."""
78+
"""Used for deprecated methods and functions."""
7479
75-
def __init__(self, message='This feature has been depreciated.'):
80+
def __init__(self, message="This feature has been deprecated."):
7681
"""Empty init."""
7782
RuntimeError.__init__(self, message)
7883

doc/source/coding-style/pep8.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ more readable and reliable.
136136
.. tab-item:: Use
137137
138138
.. code-block:: python
139-
140139
from ansys.mapdl.core.plotting import general_plotter
141140

142141
.. tab-item:: Avoid
@@ -370,11 +369,11 @@ Instead of:
370369
else:
371370
372371
if x > y:
373-
372+
374373
...
375374
376375
else:
377-
376+
378377
...
379378
380379
if x > 0 and x < 10:
@@ -407,10 +406,14 @@ this line is difficult to follow:
407406
408407
.. tab-item:: Avoid
409408

410-
.. code:: python
409+
.. code-block:: python
410+
411+
# fmt: off
411412
412413
employee_hours = [schedule.earliest_hour for employee in self.public_employees for schedule in employee.schedules]
413414
415+
# fmt: on
416+
414417
Alternatively, instead of writing a list comprehension, you can use a
415418
classic loop.
416419

@@ -794,12 +797,13 @@ example, to extract all consonants in a sentence:
794797
"""Return ``True`` when a letter is a consonant."""
795798
vowels = 'aeiou'
796799
return letter.isalpha() and letter.lower() not in vowels
797-
800+
798801
.. code-block:: pycon
799-
802+
800803
>>> sentence = "This is a sample sentence."
801804
>>> consonants = [letter for letter in sentence if is_consonant(letter)]
802805
>>> print(f"{consonants = }")
806+
803807
consonants = ['T', 'h', 's', 's', 's', 'm', 'p', 'l', 's', 'n', 't', 'n', 'c']
804808
805809
.. tab-item:: Avoid
@@ -816,6 +820,7 @@ example, to extract all consonants in a sentence:
816820
.. code-block:: pycon
817821
818822
>>> print(f"{consonants = }")
823+
819824
consonants = ['T', 'h', 's', 's', 's', 'm', 'p', 'l', 's', 'n', 't', 'n', 'c']
820825
821826
The second approach is more readable and better documented. Additionally,

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"examples_dirs": ["../../examples"], # ["../../examples/"],
7272
# path where to save gallery generated examples
7373
"gallery_dirs": ["examples"],
74-
# Patter to search for example files
74+
# Pattern to search for example files
7575
"filename_pattern": r"\.py",
7676
# Remove the "Download all examples" button from the top level gallery
7777
"download_all_examples": False,

doc/source/doc-style/docstrings.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,16 @@ Instead, you should render type hints as part of each parameter's description. T
247247
accomplish this, you must combine the ``sphinx.ext.autodoc.typehints``, ``sphinx.ext.napoleon``,
248248
and ``numpydoc`` extensions in the ``conf.py`` file:
249249

250+
251+
250252
.. code:: python
251253
252254
extensions = [
253-
...
255+
...,
254256
"sphinx.ext.autodoc.typehints",
255257
"sphinx.ext.napoleon",
256258
"numpydoc",
257-
...
259+
...,
258260
]
259261
autodoc_typehints = "description"
260262

doc/source/how-to/compatibility.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ decorator is used in `ansys/mapdl/core/check_version.py`_ and
4949

5050
.. code:: python
5151
52-
class Client():
52+
class Client:
5353
def __init__(self):
5454
"""Connect to a fake server."""
5555
self._server = FakeServer()

doc/source/how-to/documenting.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ To describe 'why' and 'how' you use a class within :ref:`RST files`, use the
276276
.. code-block:: pycon
277277
278278
>>> from my_module import MyClass
279-
>>> my_obj = MyClass(parm1='apple', parm2='orange')
279+
>>> my_obj = MyClass(parm1="apple", parm2="orange")
280280
>>> my_obj.parm1
281281
'apple'
282282
@@ -288,7 +288,7 @@ To describe 'why' and 'how' you use a class within :ref:`RST files`, use the
288288
.. code-block:: pycon
289289
290290
>>> from my_module import MyClass
291-
>>> my_obj = MyClass(parm1='apple', parm2='orange')
291+
>>> my_obj = MyClass(parm1="apple", parm2="orange")
292292
>>> my_obj.parm1
293293
'apple'
294294

doc/source/how-to/grpc-api-packages.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To use this, include this tool in the ``pyproject.toml`` file as a build depende
6262
6363
Then generate a Python wheel containing the autogenerated Python source with:
6464

65-
.. code-block:: python
65+
.. code-block:: bash
6666
6767
pip install -U pip
6868
pip install build

0 commit comments

Comments
 (0)