From da5b55d72e0201269dc6ea2256d2724f881e6af2 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Wed, 20 Mar 2024 13:07:26 +0000 Subject: [PATCH] #20 add black formatting --- .flake8 | 1 + cppwg/parsers/source_parser.py | 1 - doc/conf.py | 76 +++++++++--------- .../src/python/pyshapes/geometry/__init__.py | 2 +- .../python/pyshapes/math_funcs/__init__.py | 2 +- .../python/pyshapes/primitives/__init__.py | 2 +- .../shapes/src/python/test/test_classes.py | 16 ++-- .../shapes/src/python/test/test_functions.py | 6 +- examples/shapes/wrapper/generate.py | 79 ++++++++++++------- pyproject.toml | 8 +- 10 files changed, 113 insertions(+), 80 deletions(-) diff --git a/.flake8 b/.flake8 index 354dbab..0f89d48 100644 --- a/.flake8 +++ b/.flake8 @@ -6,3 +6,4 @@ exclude= build, doc, examples, +docstring-convention=numpy diff --git a/cppwg/parsers/source_parser.py b/cppwg/parsers/source_parser.py index 7e36ce9..1c9cbe9 100644 --- a/cppwg/parsers/source_parser.py +++ b/cppwg/parsers/source_parser.py @@ -20,7 +20,6 @@ # - variable_t (pygccxml.declarations.variable.variable_t) - class CppSourceParser: """ Parser for C++ source code diff --git a/doc/conf.py b/doc/conf.py index 6cbb8ba..49f71a1 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -30,37 +30,39 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.autodoc', - 'sphinx.ext.coverage', - 'sphinx.ext.mathjax', - 'sphinx.ext.viewcode', - 'sphinx.ext.githubpages'] +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.coverage", + "sphinx.ext.mathjax", + "sphinx.ext.viewcode", + "sphinx.ext.githubpages", +] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'cppwg' -copyright = u'2017, J. Grogan' -author = u'J. Grogan' +project = "cppwg" +copyright = "2017, J. Grogan" +author = "J. Grogan" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'0.1' +version = "0.1" # The full version, including alpha/beta/rc tags. -release = u'0.1.1' +release = "0.1.1" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -72,10 +74,10 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -86,7 +88,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -97,7 +99,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Custom sidebar templates, must be a dictionary that maps document names # to template names. @@ -105,12 +107,12 @@ # This is required for the alabaster theme # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars html_sidebars = { - '**': [ - 'about.html', - 'navigation.html', - 'relations.html', # needs 'show_related': True theme option to display - 'searchbox.html', - 'donate.html', + "**": [ + "about.html", + "navigation.html", + "relations.html", # needs 'show_related': True theme option to display + "searchbox.html", + "donate.html", ] } @@ -118,7 +120,7 @@ # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. -htmlhelp_basename = 'cppwgdoc' +htmlhelp_basename = "cppwgdoc" # -- Options for LaTeX output --------------------------------------------- @@ -127,15 +129,12 @@ # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -145,8 +144,7 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'cppwg.tex', u'cppwg Documentation', - u'J. Grogan', 'manual'), + (master_doc, "cppwg.tex", "cppwg Documentation", "J. Grogan", "manual"), ] @@ -154,10 +152,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'cppwg', u'cppwg Documentation', - [author], 1) -] +man_pages = [(master_doc, "cppwg", "cppwg Documentation", [author], 1)] # -- Options for Texinfo output ------------------------------------------- @@ -166,10 +161,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'cppwg', u'cppwg Documentation', - author, 'cppwg', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "cppwg", + "cppwg Documentation", + author, + "cppwg", + "One line description of project.", + "Miscellaneous", + ), ] - - - diff --git a/examples/shapes/src/python/pyshapes/geometry/__init__.py b/examples/shapes/src/python/pyshapes/geometry/__init__.py index bbfd373..87a4392 100644 --- a/examples/shapes/src/python/pyshapes/geometry/__init__.py +++ b/examples/shapes/src/python/pyshapes/geometry/__init__.py @@ -1,2 +1,2 @@ # Bring in everything from the shared module -from pyshapes.geometry._pyshapes_geometry import * \ No newline at end of file +from pyshapes.geometry._pyshapes_geometry import * diff --git a/examples/shapes/src/python/pyshapes/math_funcs/__init__.py b/examples/shapes/src/python/pyshapes/math_funcs/__init__.py index c5172d3..53f3fe0 100644 --- a/examples/shapes/src/python/pyshapes/math_funcs/__init__.py +++ b/examples/shapes/src/python/pyshapes/math_funcs/__init__.py @@ -1,2 +1,2 @@ # Bring in everything from the shared module -from pyshapes.math_funcs._pyshapes_math_funcs import * \ No newline at end of file +from pyshapes.math_funcs._pyshapes_math_funcs import * diff --git a/examples/shapes/src/python/pyshapes/primitives/__init__.py b/examples/shapes/src/python/pyshapes/primitives/__init__.py index 16f86bc..490a0f2 100644 --- a/examples/shapes/src/python/pyshapes/primitives/__init__.py +++ b/examples/shapes/src/python/pyshapes/primitives/__init__.py @@ -1,2 +1,2 @@ # Bring in everything from the shared module -from pyshapes.primitives._pyshapes_primitives import * \ No newline at end of file +from pyshapes.primitives._pyshapes_primitives import * diff --git a/examples/shapes/src/python/test/test_classes.py b/examples/shapes/src/python/test/test_classes.py index ac31d64..b0370f5 100644 --- a/examples/shapes/src/python/test/test_classes.py +++ b/examples/shapes/src/python/test/test_classes.py @@ -2,6 +2,7 @@ import pyshapes.geometry import pyshapes.primitives + class TestClasses(unittest.TestCase): def testGeometry(self): @@ -12,13 +13,14 @@ def testGeometry(self): points = [p1, p2, p3] triangle = pyshapes.primitives.Shape2() triangle.SetVertices(points) - self.assertTrue(len(triangle.rGetVertices())==3) - + self.assertTrue(len(triangle.rGetVertices()) == 3) + rectangle = pyshapes.primitives.Rectangle(5.0, 10.0) - self.assertTrue(len(rectangle.rGetVertices())==4) - + self.assertTrue(len(rectangle.rGetVertices()) == 4) + cuboid = pyshapes.primitives.Cuboid(5.0, 10.0, 20.0) - self.assertTrue(len(cuboid.rGetVertices())==8) + self.assertTrue(len(cuboid.rGetVertices()) == 8) + -if __name__ == '__main__': - unittest.main() \ No newline at end of file +if __name__ == "__main__": + unittest.main() diff --git a/examples/shapes/src/python/test/test_functions.py b/examples/shapes/src/python/test/test_functions.py index 28236a3..0440eb8 100644 --- a/examples/shapes/src/python/test/test_functions.py +++ b/examples/shapes/src/python/test/test_functions.py @@ -1,6 +1,7 @@ import unittest from pyshapes import math_funcs + class TestFunctions(unittest.TestCase): def testAdd(self): @@ -9,5 +10,6 @@ def testAdd(self): c = math_funcs.add(4, 5) self.assertTrue(c == a + b) -if __name__ == '__main__': - unittest.main() \ No newline at end of file + +if __name__ == "__main__": + unittest.main() diff --git a/examples/shapes/wrapper/generate.py b/examples/shapes/wrapper/generate.py index 88fabd6..92a8283 100644 --- a/examples/shapes/wrapper/generate.py +++ b/examples/shapes/wrapper/generate.py @@ -10,36 +10,61 @@ from cppwg import CppWrapperGenerator -def generate_wrapper_code(source_root, wrapper_root, castxml_binary, - package_info_path, includes): - - generator = CppWrapperGenerator(source_root, - includes, - wrapper_root, - castxml_binary, - package_info_path) +def generate_wrapper_code( + source_root, wrapper_root, castxml_binary, package_info_path, includes +): + + generator = CppWrapperGenerator( + source_root, includes, wrapper_root, castxml_binary, package_info_path + ) generator.generate_wrapper() + if __name__ == "__main__": - + parser = ArgumentParser() - parser.add_argument('--source_root', '-s', type=str, - help='Root of the source directory.', - default=os.getcwd()) - parser.add_argument('--wrapper_root', '-w', type=str, - help='Root of the wrapper directory.', - default=os.getcwd()) - parser.add_argument('--castxml_binary', '-c', type=str, - help='Path to the castxml binary.', - default='castxml') - parser.add_argument('--package_info', '-p', type=str, - help='Path to the package info file.', - default=os.getcwd() + "/package_info.yaml") - parser.add_argument('--includes', '-i', type=str, - help='Path to the includes directory.', - default=os.getcwd()) + parser.add_argument( + "--source_root", + "-s", + type=str, + help="Root of the source directory.", + default=os.getcwd(), + ) + parser.add_argument( + "--wrapper_root", + "-w", + type=str, + help="Root of the wrapper directory.", + default=os.getcwd(), + ) + parser.add_argument( + "--castxml_binary", + "-c", + type=str, + help="Path to the castxml binary.", + default="castxml", + ) + parser.add_argument( + "--package_info", + "-p", + type=str, + help="Path to the package info file.", + default=os.getcwd() + "/package_info.yaml", + ) + parser.add_argument( + "--includes", + "-i", + type=str, + help="Path to the includes directory.", + default=os.getcwd(), + ) args = parser.parse_args() - + all_includes = glob(args.includes + "/*/") - generate_wrapper_code(args.source_root, args.wrapper_root, args.castxml_binary, - args.package_info, all_includes) \ No newline at end of file + generate_wrapper_code( + args.source_root, + args.wrapper_root, + args.castxml_binary, + args.package_info, + all_includes, + ) diff --git a/pyproject.toml b/pyproject.toml index d9bd1c6..1c42cc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dependencies = ["pyyaml >=6.0", "pygccxml >=2.2", "castxml >=0.4"] requires-python = ">=3.8" [project.optional-dependencies] -dev = ["flake8", "flake8-bugbear", "isort"] +dev = ["black", "flake8", "flake8-bugbear", "flake8-docstrings", "isort"] docs = ["sphinx", "sphinx-rtd-theme", "numpydoc"] [project.scripts] @@ -42,3 +42,9 @@ cppwg = "cppwg.__main__:main" [project.urls] Repository = "https://github.com/Chaste/cppwg/" + +[tool.black] +target-version = ["py38", "py39", "py310", "py311", "py312"] + +[tool.isort] +profile = "black"