Skip to content

Implementing blacken docs #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ defaults:

jobs:

code-style:
name: "Code style"
runs-on: ubuntu-latest
steps:
- name: "PyAnsys code style checks"
uses: pyansys/actions/code-style@v2
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

doc-style:
name: "Documentation style check"
runs-on: ubuntu-latest
Expand All @@ -66,7 +57,6 @@ jobs:
smoke-tests:
name: "Build and smoke tests"
runs-on: ${{ matrix.os }}
needs: code-style
strategy:
fail-fast: false
matrix:
Expand Down
10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fail_fast: True

repos:

- repo: https://github.com/pycqa/isort
Expand All @@ -6,12 +8,18 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 22.12.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
hooks:
- id: black
args:
- --line-length=88

- repo: https://github.com/adamchainz/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==22.12.0]

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
Expand Down
26 changes: 15 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PyMAPDL
=======
|pyansys| |pypi| |PyPIact| |GH-CI| |codecov| |zenodo| |MIT| |black|
|pyansys| |pypi| |PyPIact| |GH-CI| |codecov| |zenodo| |MIT| |black| |pre-commit|

.. |pyansys| image:: https://img.shields.io/badge/Py-Ansys-ffc107.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABDklEQVQ4jWNgoDfg5mD8vE7q/3bpVyskbW0sMRUwofHD7Dh5OBkZGBgW7/3W2tZpa2tLQEOyOzeEsfumlK2tbVpaGj4N6jIs1lpsDAwMJ278sveMY2BgCA0NFRISwqkhyQ1q/Nyd3zg4OBgYGNjZ2ePi4rB5loGBhZnhxTLJ/9ulv26Q4uVk1NXV/f///////69du4Zdg78lx//t0v+3S88rFISInD59GqIH2esIJ8G9O2/XVwhjzpw5EAam1xkkBJn/bJX+v1365hxxuCAfH9+3b9/+////48cPuNehNsS7cDEzMTAwMMzb+Q2u4dOnT2vWrMHu9ZtzxP9vl/69RVpCkBlZ3N7enoDXBwEAAA+YYitOilMVAAAAAElFTkSuQmCC
:target: https://docs.pyansys.com/
Expand Down Expand Up @@ -28,6 +28,9 @@ PyMAPDL
:target: https://github.com/psf/black
:alt: black

.. |pre-commit| image:: https://results.pre-commit.ci/badge/github/pyansys/pymapdl/main.svg
:target: https://results.pre-commit.ci/latest/github/pyansys/pymapdl/main
:alt: pre-commit.ci status

Overview
--------
Expand Down Expand Up @@ -93,21 +96,21 @@ Python 3.10 on Windows, Mac OS, and Linux.
Install the latest release from `PyPi
<https://pypi.org/project/ansys-mapdl-core/>`_ with:

.. code::
.. code:: console

pip install ansys-mapdl-core

Alternatively, install the latest from `PyMAPDL GitHub
<https://github.com/pyansys/pymapdl/issues>`_ via:

.. code::
.. code:: console

pip install git+https://github.com/pyansys/pymapdl.git


For a local "development" version, install with (requires pip >= 22.0):

.. code::
.. code:: console

git clone https://github.com/pyansys/pymapdl.git
cd pymapdl
Expand All @@ -127,7 +130,7 @@ this on an isolated system with a fresh python or on a virtual environment.

For example, on Linux with Python 3.7, unzip it and install it with the following:

.. code::
.. code:: console

unzip PyMAPDL-v0.62.dev1-wheelhouse-Linux-3.7.zip wheelhouse
pip install ansys-mapdl-core -f wheelhouse --no-index --upgrade --ignore-installed
Expand Down Expand Up @@ -156,6 +159,7 @@ You can launch MAPDL locally directly from Python using ``launch_mapdl``:
.. code:: python

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()

This automatically searches for the latest local version of MAPDL,
Expand All @@ -174,23 +178,23 @@ adapted to run from Linux, or the LAN provided the necessary ports are
open. This example specifies the port with ``-port 50052``, but this
option can be left out if you plan on using the default port 50052.

.. code::
.. code:: pwsh

start "MAPDL" "%ANSYS211_DIR%\bin\winx64\ANSYS211.exe" -port 50052 -grpc

Next, connect to the instance of MAPDL from python with:

.. code:: python
.. code:: pycon

>>> from ansys.mapdl.core import Mapdl
>>> ip = '127.0.0.1'
>>> ip = "127.0.0.1"
>>> mapdl = Mapdl(ip=ip, port=50052, start_instance=False)
>>> print(mapdl)


A successful connection returns:

.. code::
.. code:: output

Product: ANSYS Mechanical Enterprise
MAPDL Version: RELEASE 2020 R2 BUILD 20.2TEST UPDATE 20200601
Expand All @@ -210,7 +214,7 @@ You run MAPDL commands via:

.. code:: python

mapdl.run('/PREP7')
mapdl.run("/PREP7")


Nearly all the built-in MAPDL commands have an associated pythonic
Expand Down Expand Up @@ -244,7 +248,7 @@ and source, you can visit `pyansys Zenodo
<https://zenodo.org/badge/latestdoi/70696039>`_ and generate the
correct citation. For example, the BibTex citation is:

.. code::
.. code:: bibtex

@software{alexander_kaszynski_2020_4009467,
author = {Alexander Kaszynski},
Expand Down
4 changes: 2 additions & 2 deletions doc/source/api/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ logging architecture with global and local logging instances.

For these two types of loggers, the default log message format is:

.. code:: python
.. code:: pycon

>>> from ansys.mapdl.core import launch_mapdl
>>> mapdl = launch_mapdl()
>>> mapdl._log.info('This is an useful message')
>>> mapdl._log.info("This is an useful message")
LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE
INFO - GRPC_127.0.0.1:50052 - test - <module> - This is an useful message

Expand Down
29 changes: 17 additions & 12 deletions doc/source/api/unit_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ this library:

def get_report_colors(theme):

if theme == 'weather':
if theme == "weather":
colors = ["blue", "lightblue", "grey"]
elif theme == 'traffic':
elif theme == "traffic":
colors = ["red", "orange", "yellow"]
else:
colors = ["red", "blue", "green"]

return colors


Expand All @@ -59,9 +59,9 @@ You can opt to run the tests with this configuration:

def test_get_report_colors():

assert get_report_colors('weather') == ["blue", "lightblue", "grey"]
assert get_report_colors('traffic') == ["red", "orange", "yellow"]
assert get_report_colors('other') == ["red", "blue", "green"]
assert get_report_colors("weather") == ["blue", "lightblue", "grey"]
assert get_report_colors("traffic") == ["red", "orange", "yellow"]
assert get_report_colors("other") == ["red", "blue", "green"]


Or, if a method is a bit more complex, you can split the case in different tests:
Expand All @@ -70,15 +70,17 @@ Or, if a method is a bit more complex, you can split the case in different tests

def test_get_report_colors_weather():

assert get_report_colors('weather') == ["blue", "lightblue", "grey"]
assert get_report_colors("weather") == ["blue", "lightblue", "grey"]


def test_get_report_colors_traffic():

assert get_report_colors('traffic') == ["red", "orange", "yellow"]
assert get_report_colors("traffic") == ["red", "orange", "yellow"]


def test_get_report_colors_other():

assert get_report_colors('other') == ["red", "blue", "green"]
assert get_report_colors("other") == ["red", "blue", "green"]


While the code coverage in either case is 100% for the function, the second case is
Expand Down Expand Up @@ -131,7 +133,7 @@ It will be executed upstream of each test and not within all tests.
mapdl.prep7()
# .... more code

return True # if everything goes ok until here
return True # if everything goes ok until here


Example
Expand All @@ -147,22 +149,25 @@ Here are some examples of how you use ``pytest``:
import numpy as np
import ansys.mapdl.core.math as apdl_math


@pytest.fixture(scope="module")
def mm(mapdl): # pass the 'mapdl' fixture as an argument.

return mapdl.math


def test_rand(mm): # pass the 'mm' fixture as an argument.

w = mm.rand(10)
assert w.size == 10 # if it is False, AssertionError is raised


def test_matrix_addition(mm):

m1 = mm.rand(10, 10)
m2 = mm.rand(10, 10)
m3 = m1 + m2
assert np.allclose(m1.asarray() + m2.asarray(), m3.asarray())
# if it is False, AssertionError is raised
assert np.allclose(m1.asarray() + m2.asarray(), m3.asarray())
# if it is False, AssertionError is raised

For further explanations, see the `pytest documentation <pytest_>`_.
12 changes: 12 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,15 @@

# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]

# Adding apdl syntax highlighting
def setup(app):
from pygments.lexers.apdlexer import apdlexer
from pygments.lexers.julia import JuliaLexer

# ANSYS lexer
app.add_lexer("apdl", apdlexer)
app.add_lexer("ansys", apdlexer)

# Julia lexer
app.add_lexer("julia", JuliaLexer)
26 changes: 13 additions & 13 deletions doc/source/examples/extended_examples/Krylov/krylov_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,41 +388,41 @@ This code plots the frequency response function for a node along 0.2 in the X di
Get the response of the system for the selected node
over a range of frequencies, such as 0 to 1000 Hz.

.. code:: python3
.. code:: python

start_freq = 0
end_freq = 1000
num_steps = 100
step_val = (end_freq - start_freq) / num_steps
dic = {}

for freq in range (0,num_steps):
pressure = get_pressure_at(node_number, freq)['x']
for freq in range(0, num_steps):
pressure = get_pressure_at(node_number, freq)["x"]
abs_pressure = abs(pressure)

dic[start_freq] = abs_pressure
start_freq += step_val

Sort the results.

.. code:: python3
.. code:: python

frf_List = dic.items()
frf_List = sorted(frf_List)
frf_x, frf_y = zip(*frf_List)


frf_x, frf_y = zip(*frf_List)

Plot the frequency response function for the selected node.

.. code:: python3
plt.plot(frf_x, frf_y, linewidth= 3.0, color='b')
.. code:: python

plt.plot(frf_x, frf_y, linewidth=3.0, color="b")

# Plot the natural frequency as vertical lines on the FRF graph
for itr in range(0,6):
plt.axvline(x=eigenvalues[itr], ymin=0,ymax=2, color='r', linestyle='dotted', linewidth=1)

for itr in range(0, 6):
plt.axvline(
x=eigenvalues[itr], ymin=0, ymax=2, color="r", linestyle="dotted", linewidth=1
)

# Name the graph and the x-axis and y-axis
plt.title("Frequency Response Function")
plt.xlabel("Frequency (HZ)")
Expand Down
Loading