Skip to content

Commit 6ed5c74

Browse files
committed
fix: code style
1 parent 70a1758 commit 6ed5c74

File tree

1 file changed

+84
-15
lines changed

1 file changed

+84
-15
lines changed

doc/source/conf.py

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import os
44
import pathlib
55

6+
import sphinx
67
from sphinx.util import logging
8+
79
from ansys_sphinx_theme import (
810
ansys_favicon,
911
get_version_match,
@@ -228,7 +230,18 @@ def get_images_directories_from_path(path):
228230

229231
# -- Sphinx configuration ----------------------------------------------------
230232

231-
def copy_directory_recursive(source_path, destination_path):
233+
def copy_directory_recursive(source_path: pathlib.Path, destination_path: pathlib.Path):
234+
"""
235+
Copy a directory from a source to a destination path.
236+
237+
Parameters
238+
----------
239+
source_path : pathlib.Path
240+
Source directory to be copied.
241+
destination_path : pathlib.Path
242+
Destination directory.
243+
244+
"""
232245
logger = logging.getLogger(__name__)
233246

234247
if source_path.is_dir():
@@ -244,10 +257,18 @@ def copy_directory_recursive(source_path, destination_path):
244257
destination_file.write_text(file.read_text())
245258

246259

247-
def remove_directory_recursive(directory_path):
260+
def remove_directory_recursive(directory_path: pathlib.Path):
261+
"""
262+
Revemo a directory given its path.
263+
264+
Parameters
265+
----------
266+
directory_path : pathlib.Path
267+
Path instance representing the path to the directory.
268+
269+
"""
248270
logger = logging.getLogger(__name__)
249271

250-
directory_path = pathlib.Path(directory_path)
251272
if not directory_path.exists():
252273
return
253274

@@ -262,35 +283,83 @@ def remove_directory_recursive(directory_path):
262283
directory_path.rmdir()
263284

264285

265-
def copy_directory(origin, destination):
286+
def copy_directory(origin: pathlib.Path, destination: pathlib.Path):
287+
"""
288+
Copy a directory from an origin to a desired destination.
289+
290+
Parameters
291+
----------
292+
origin : pathlib.Path
293+
Desired location of the directory to be copied.
294+
destination : pathlib.Path
295+
Destination directory path.
296+
297+
"""
266298
logger = logging.getLogger(__name__)
267299
logger.info(f"\nCopying {origin}/ to {destination}/...")
268300
copy_directory_recursive(origin, destination)
269301

270-
def copy_examples_to_source_dir(app):
271-
SOURCE_DIRECTORY = pathlib.Path(app.srcdir)
302+
def copy_examples_to_source_dir(app: sphinx.application.Sphinx):
303+
"""
304+
Copy the examples directory to the source directory of the documentation.
305+
306+
Parameters
307+
----------
308+
app : sphinx.application.Sphinx
309+
Sphinx application instance containing the all the doc build configuration.
310+
311+
"""
312+
SOURCE_EXAMPLES = pathlib.Path(app.srcdir) / "examples"
272313
EXAMPLES_DIRECTORY = pathlib.Path().parent.parent / "examples"
273-
copy_directory(EXAMPLES_DIRECTORY, SOURCE_DIRECTORY / "examples")
314+
copy_directory(EXAMPLES_DIRECTORY, SOURCE_EXAMPLES)
315+
316+
def copy_examples_to_output_dir(app: sphinx.application.Sphinx):
317+
"""
318+
Copy the examples directory to the output directory of the documentation.
274319
275-
def copy_examples_to_output_dir(app):
276-
OUTPUT_DIRECTORY = pathlib.Path(app.outdir)
320+
Parameters
321+
----------
322+
app : sphinx.application.Sphinx
323+
Sphinx application instance containing the all the doc build configuration.
324+
325+
"""
326+
OUTPUT_DIRECTORY = pathlib.Path(app.outdir) / "examples"
277327
EXAMPLES_DIRECTORY = pathlib.Path().parent.parent / "examples"
278-
copy_directory(EXAMPLES_DIRECTORY, OUTPUT_DIRECTORY / "examples")
328+
copy_directory(EXAMPLES_DIRECTORY, OUTPUT_DIRECTORY)
279329

280330
def remove_examples_from_source_dir(app, exception):
281-
SOURCE_DIRECTORY = pathlib.Path(app.srcdir)
331+
"""
332+
Remove the example files from the documentation source directory.
333+
334+
Parameters
335+
----------
336+
app : sphinx.application.Sphinx
337+
Sphinx application instance containing the all the doc build configuration.
338+
exception : Exception
339+
Exception encountered during the building of the documentation.
340+
341+
"""
342+
EXAMPLES_DIRECTORY = pathlib.Path(app.srcdir) / "examples"
282343
logger = logging.getLogger(__name__)
283-
logger.info(f"\nRemoving examples/ from {SOURCE_DIRECTORY} directory...")
284-
remove_directory_recursive(SOURCE_DIRECTORY / "examples")
344+
logger.info(f"\nRemoving {EXAMPLES_DIRECTORY} directory...")
345+
remove_directory_recursive(EXAMPLES_DIRECTORY)
346+
347+
def setup(app: sphinx.application.Sphinx):
348+
"""
349+
Setup different hook functions during the documentation build.
350+
351+
Parameters
352+
----------
353+
app : sphinx.application.Sphinx
354+
Sphinx application instance containing the all the doc build configuration.
285355
286-
def setup(app):
356+
"""
287357
# HACK: rST files are copied to the doc/source directory before the build.
288358
# Sphinx needs all source files to be in the source directory to build.
289359
# However, the examples are desired to be kept in the root directory. Once the
290360
# build has completed, no matter its success, the examples are removed from
291361
# the source directory.
292362
if BUILD_EXAMPLES:
293-
import os
294363
app.connect("builder-inited", copy_examples_to_source_dir)
295364
app.connect("build-finished", remove_examples_from_source_dir)
296365
app.connect("build-finished", copy_examples_to_output_dir)

0 commit comments

Comments
 (0)