Skip to content

Commit

Permalink
feat: using black for docstring length
Browse files Browse the repository at this point in the history
  • Loading branch information
clatapie committed Mar 15, 2024
1 parent 38a5c74 commit 16727a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/autodoc_cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: "Create pyconverter-autogenerated doc"
run: |
pyconverter-xml2py package -x ${{ github.workspace }}/mapdl-cmd-doc -f ${{ github.workspace }}/tests/customized_functions
pyconverter-xml2py package -x ${{ github.workspace }}/mapdl-cmd-doc -f ${{ github.workspace }}/tests/customized_functions -l 100
- name: Upload autogenerated doc artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ dependencies = [
"py-asciimath==0.3.0",
"pylatexenc==2.10",
"tqdm>=4.64.1",
"black>=24.2.0",
]

[project.optional-dependencies]
tests = [
"black>=24.2.0",
"click==8.1.7",
"pygithub==2.2.0",
"lxml==5.1.0",
Expand Down
25 changes: 16 additions & 9 deletions src/pyconverter/xml2py/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import os

import click
from pyconverter.xml2py import __version__, download
from pyconverter.xml2py import writer as wr
from pyconverter.xml2py import (__version__, download, writer, formatter)


def create_package(xml_path=None, functions_path=None, target_path=None, template_path=None):

def create_package(xml_path=None, functions_path=None, target_path=None, template_path=None, max_docstring_length=100):
"""Create Python package based on a XML documentation.
Parameters
Expand Down Expand Up @@ -88,11 +88,12 @@ def create_package(xml_path=None, functions_path=None, target_path=None, templat
if not os.path.isdir(os.path.join(os.getcwd(), "_package")):
download.download_template()

commands, cmd_map, *_ = wr.convert(xml_path)
wr.write_source(commands, cmd_map, xml_path, target_path, functions_path)
commands, cmd_map, *_ = writer.convert(xml_path)
writer.write_source(commands, cmd_map, xml_path, target_path, functions_path)
package_path = os.path.join(target_path, "package")
wr.write_docs(commands, cmd_map, package_path)

writer.write_docs(commands, cmd_map, package_path)
formatter.run_black(package_path, max_docstring_length)


@click.group()
def main():
Expand Down Expand Up @@ -126,6 +127,12 @@ def version():
type=click.Path(),
help="Path to the directory where you want the autogenerated package to be created.",
)
def package(xml_path, func_path, targ_path):
@click.option(
"-l",
"--max-docstring-length",
type=click.INT,
help="Maximum length of the generated docstrings.",
)
def package(xml_path, func_path, targ_path, max_docstring_length):
"""Create a Python package from your XML documentation."""
create_package(xml_path, func_path, targ_path)
create_package(xml_path, func_path, targ_path, max_docstring_length)
6 changes: 6 additions & 0 deletions src/pyconverter/xml2py/formatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""This module contains the functions to format the generated docstrings with black."""


def run_black(package_path, max_docstring_length):
"""Run black on the autogenerated package."""
exec(f"black {package_path}/src/pyconverter/generatedcommands -l {max_docstring_length}")

0 comments on commit 16727a5

Please sign in to comment.