Repository: ansys/pyconverter-xml2py (language: python)

Issue:
Package name vs. installed name
Library is importable within Python with:

```py
import pydita
```

Whereas it's installed as:
```
pydita-ast                            0.1.dev0    /home/user/source/pydita-ast
```

Let's change the directory structure from:

```
pydita/ast
```

to

```
pydita_ast
```


Discussion / hints:
Yep, agreed. That way we call it with

```py
import pydita_ast
```
This issue will be handled once #28 is closed.

Fix patch:
diff --git a/.coveragerc b/.coveragerc
index 59d0997e4..0347b86f2 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,6 +1,6 @@
 [run]
 source =
-    pydita.ast
+    pydita_ast
 
 [report]
 show_missing = true
diff --git a/.github/workflows/autodoc_cicd.yml b/.github/workflows/autodoc_cicd.yml
index 2653fe114..586104048 100644
--- a/.github/workflows/autodoc_cicd.yml
+++ b/.github/workflows/autodoc_cicd.yml
@@ -48,8 +48,9 @@ jobs:
           token: ${{ secrets.MAPDL_CMD_DOC_TOKEN }}
           path: mapdl-cmd-doc
       
-      - name: "Install pydita-ast"
+      - name: "Install pydita_ast"
         run: |
+          pip install --upgrade pip
           pip install .[doc]
       
       - name: "Create pydita-autogenerated doc"
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index ed1aa787f..490103043 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -15,8 +15,8 @@ on:
 
 env:
   MAIN_PYTHON_VERSION: '3.10'
-  PACKAGE_NAME: 'pydita-ast'
-  PACKAGE_NAMESPACE: 'pydita.ast'
+  PACKAGE_NAME: 'pydita_ast'
+  PACKAGE_NAMESPACE: 'pydita_ast'
   DOCUMENTATION_CNAME: 'pydita-ast.docs.pyansys.com'
   RESET_PIP_CACHE: 0
   RESET_AUTOSUMMARY_CACHE: 0
@@ -133,7 +133,7 @@ jobs:
         run: |
           pytest -v --durations=10 --maxfail=10 \
             --reruns 7 --reruns-delay 3 --ghdir ${{ github.workspace }}\
-            --cov=pydita.ast --cov-report=xml:coverage.xml --cov-report=html\
+            --cov=pydita_ast --cov-report=xml:coverage.xml --cov-report=html\
             --cov-report term
 
       - name: "Upload coverage to Codecov"
@@ -166,18 +166,19 @@ jobs:
         uses: actions/cache@v3
         with:
           path: ~/.cache/pip
-          key: Python-pydita-ast-v${{ env.RESET_PIP_CACHE }}-${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
+          key: Python-pydita_ast-v${{ env.RESET_PIP_CACHE }}-${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
           restore-keys: |
-            Python-pydita-ast-v${{ env.RESET_PIP_CACHE }}-${{ env.MAIN_PYTHON_VERSION }}
+            Python-pydita_ast-v${{ env.RESET_PIP_CACHE }}-${{ env.MAIN_PYTHON_VERSION }}
       
-      - name: "Install pydita-ast"
+      - name: "Install pydita_ast"
         run: |
+          pip install --upgrade pip
           pip install .[doc]
       
-      - name: "Retrieve PyDita-AST version"
+      - name: "Retrieve pydita_ast version"
         run: |
-          echo "PYDITA_VERSION=$(python -c 'from pydita.ast import __version__; print(__version__)')" >> $GITHUB_ENV
-          echo "PyDita-AST version is: $(python -c 'from pydita.ast import __version__; print(__version__)')"
+          echo "PYDITA_VERSION=$(python -c 'from pydita_ast import __version__; print(__version__)')" >> $GITHUB_ENV
+          echo "pydita_ast version is: $(python -c 'from pydita_ast import __version__; print(__version__)')"
     
       - name: "Cache docs build directory"
         uses: actions/cache@v3
@@ -246,7 +247,7 @@ jobs:
     # - name: "Release to the public PyPI repository"
     #   uses: ansys/actions/release-pypi-public@v3
     #   with:
-    #     library-name: "pydita-ast"
+    #     library-name: "pydita_ast"
     #     twine-username: "__token__"
     #     twine-token: ${{ secrets.PYPI_TOKEN }}
 
diff --git a/README.rst b/README.rst
index ee27cd0eb..b2fb420d1 100644
--- a/README.rst
+++ b/README.rst
@@ -48,7 +48,7 @@ Install the ``pydita-ast`` package with:
 
 .. code:: bash
 
-   python -m pip install pydita-ast
+    python -m pip install pydita_ast
 
 
 It is recommended to organize the XML documentation as follow:
diff --git a/_package/pyproject.toml b/_package/pyproject.toml
index 897afad73..9283ef8b6 100644
--- a/_package/pyproject.toml
+++ b/_package/pyproject.toml
@@ -19,9 +19,12 @@ maintainers = [
 
 classifiers = [
     "Development Status :: 4 - Beta",
-    "Programming Language :: Python :: 3",
     "License :: OSI Approved :: MIT License",
     "Operating System :: OS Independent",
+    "Programming Language :: Python :: 3.8",
+    "Programming Language :: Python :: 3.9",
+    "Programming Language :: Python :: 3.10",
+    "Programming Language :: Python :: 3.11",
 ]
 
 dependencies = [
diff --git a/doc/source/api/ast_class.rst b/doc/source/api/ast_class.rst
index 5e98d7f25..3a5d19f29 100644
--- a/doc/source/api/ast_class.rst
+++ b/doc/source/api/ast_class.rst
@@ -1,7 +1,7 @@
 AST tree
 ========
 
-.. currentmodule:: pydita.ast.ast_tree
+.. currentmodule:: pydita_ast.ast_tree
 
 The following classes are used to create the adequate AST Tree:
 
diff --git a/doc/source/api/ast_functions.rst b/doc/source/api/ast_functions.rst
index 655304e2b..fdfa3bffb 100644
--- a/doc/source/api/ast_functions.rst
+++ b/doc/source/api/ast_functions.rst
@@ -1,7 +1,7 @@
 AST functions
 =============
 
-.. currentmodule:: pydita.ast.ast_tree
+.. currentmodule:: pydita_ast.ast_tree
 
 The following functions are used to create the adequate AST Tree:
 
diff --git a/doc/source/api/autogenerateddirectory.rst b/doc/source/api/autogenerateddirectory.rst
index 25a017f43..01b730ce8 100644
--- a/doc/source/api/autogenerateddirectory.rst
+++ b/doc/source/api/autogenerateddirectory.rst
@@ -1,7 +1,7 @@
 Autogenerated directory
 =======================
 
-.. currentmodule:: pydita.ast.version_variables
+.. currentmodule:: pydita_ast.version_variables
 
 The following class returns the variables related to the XML documentation:
 
diff --git a/doc/source/api/custom_functions.rst b/doc/source/api/custom_functions.rst
index a68c67600..e0303f7ae 100644
--- a/doc/source/api/custom_functions.rst
+++ b/doc/source/api/custom_functions.rst
@@ -1,7 +1,7 @@
 Customized functions
 ====================
 
-.. currentmodule:: pydita.ast.custom_functions
+.. currentmodule:: pydita_ast.custom_functions
 
 The following class and functions enable to handle customization of functions.
 
diff --git a/doc/source/api/directory_format.rst b/doc/source/api/directory_format.rst
index bddc13d46..335169fbb 100644
--- a/doc/source/api/directory_format.rst
+++ b/doc/source/api/directory_format.rst
@@ -1,7 +1,7 @@
 Directory format
 ================
 
-.. currentmodule:: pydita.ast.directory_format
+.. currentmodule:: pydita_ast.directory_format
 
 The following functions return the paths needed when the XML directory
 follows the pre-defined format.
diff --git a/doc/source/api/load_xml_doc.rst b/doc/source/api/load_xml_doc.rst
index 28627ce6e..b5cc35222 100644
--- a/doc/source/api/load_xml_doc.rst
+++ b/doc/source/api/load_xml_doc.rst
@@ -1,7 +1,7 @@
 Load XML documentation
 ======================
 
-.. currentmodule:: pydita.ast.load_xml_doc
+.. currentmodule:: pydita_ast.load_xml_doc
 
 The following functions load the XML documentation.
 
diff --git a/doc/source/api/oxygen_xml.rst b/doc/source/api/oxygen_xml.rst
index 5a58d2435..356c0cf86 100644
--- a/doc/source/api/oxygen_xml.rst
+++ b/doc/source/api/oxygen_xml.rst
@@ -1,7 +1,7 @@
 Oxygen XML tree
 ===============
 
-.. currentmodule:: pydita.ast.ast_tree
+.. currentmodule:: pydita_ast.ast_tree
 
 The following class enables to get an Oxygen XML Tree:
 
diff --git a/doc/source/api/writer.rst b/doc/source/api/writer.rst
index bb8d7566e..bc6381409 100644
--- a/doc/source/api/writer.rst
+++ b/doc/source/api/writer.rst
@@ -1,7 +1,7 @@
 Writer
 ======
 
-.. currentmodule:: pydita.ast.writer
+.. currentmodule:: pydita_ast.writer
 
 The following functions convert the AST tree into a Sphinx documentation.
 
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 763c38f47..f64cafd78 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -3,10 +3,10 @@
 import os
 
 from ansys_sphinx_theme import ansys_favicon, pyansys_logo_black
-from pydita.ast import __version__
+from pydita_ast import __version__
 
 # Project information
-project = "pydita-ast"
+project = "pydita_ast"
 copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
 author = "ANSYS, Inc."
 release = version = __version__
diff --git a/pyproject.toml b/pyproject.toml
index ea1ab35f4..804ac3bcb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
 
 [project]
 # Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
-name = "pydita-ast"
+name = "pydita_ast"
 version = "0.1.dev0"
 description = "PyDita AST converter."
 readme = "README.rst"
@@ -61,9 +61,6 @@ doc = [
     "sphinx-design==0.4.1",
 ]
 
-[tool.flit.module]
-name = "pydita.ast"
-
 [project.urls]
 Source = "https://github.com/ansys/pydita-ast/"
 Tracker = "https://github.com/ansys/pydita-ast/issues"
diff --git a/src/pydita/ast/__init__.py b/src/pydita_ast/__init__.py
similarity index 83%
rename from src/pydita/ast/__init__.py
rename to src/pydita_ast/__init__.py
index 619580cbd..2208e3e34 100644
--- a/src/pydita/ast/__init__.py
+++ b/src/pydita_ast/__init__.py
@@ -1,5 +1,5 @@
 """
-pydita.ast
+pydita_ast
 """
 
 try:
@@ -8,4 +8,4 @@
     import importlib_metadata
 
 __version__ = importlib_metadata.version(__name__.replace(".", "-"))
-"""PyDita-AST version."""
+"""pydita_ast version."""
diff --git a/src/pydita/ast/ast_tree.py b/src/pydita_ast/ast_tree.py
similarity index 99%
rename from src/pydita/ast/ast_tree.py
rename to src/pydita_ast/ast_tree.py
index 76cedd906..923d6fc4e 100644
--- a/src/pydita/ast/ast_tree.py
+++ b/src/pydita_ast/ast_tree.py
@@ -1968,14 +1968,14 @@ def py_docstring(self, custom_functions):
                 items += [""] + textwrap.wrap("Default: " + self.default.to_rst())
         if self.args is not None:
             items += [""] + self.py_parm
-        if (
+        if custom_functions is not None and (
             self.py_name in custom_functions.py_names
             and self.py_name in custom_functions.py_returns
         ):
             items += [""] + custom_functions.py_returns[self.py_name]
         if self.notes is not None:
             items += [""] + self.py_notes
-        if (
+        if custom_functions is not None and (
             self.py_name in custom_functions.py_names
             and self.py_name in custom_functions.py_examples
         ):
@@ -2274,10 +2274,10 @@ def __repr__(self):
 
         return "\n".join(lines)
 
-    def py_source(self, custom_functions):
+    def py_source(self, custom_functions=None):
         """Return the python source"""
 
-        if self.py_name not in custom_functions.py_names:
+        if custom_functions is None or self.py_name not in custom_functions.py_names:
 
             if len(self.py_args) > 0:
                 command = 'command = f"' + self.name + ",{" + "},{".join(self.py_args) + '}"\n'
@@ -2290,12 +2290,12 @@ def py_source(self, custom_functions):
             source = "".join(custom_functions.py_code[self.py_name])
         return source
 
-    def to_python(self, custom_functions, prefix=""):
+    def to_python(self, custom_functions=None, prefix=""):
         """Return the complete python definition of the command."""
         docstr = textwrap.indent(
             f'\nr"""{self.py_docstring(custom_functions)}\n"""', prefix=prefix + " " * 4
         )
-        if self.py_name in custom_functions.lib_import:
+        if custom_functions is not None and self.py_name in custom_functions.lib_import:
             out = f"{''.join(custom_functions.lib_import[self.py_name])}\n{self.py_signature}{docstr}\n{self.py_source(custom_functions)}"  # noqa : E501
         else:
             out = f"{self.py_signature}{docstr}\n{self.py_source(custom_functions)}"
diff --git a/src/pydita/ast/custom_functions.py b/src/pydita_ast/custom_functions.py
similarity index 100%
rename from src/pydita/ast/custom_functions.py
rename to src/pydita_ast/custom_functions.py
diff --git a/src/pydita/ast/directory_format.py b/src/pydita_ast/directory_format.py
similarity index 100%
rename from src/pydita/ast/directory_format.py
rename to src/pydita_ast/directory_format.py
diff --git a/src/pydita/ast/load_xml_doc.py b/src/pydita_ast/load_xml_doc.py
similarity index 99%
rename from src/pydita/ast/load_xml_doc.py
rename to src/pydita_ast/load_xml_doc.py
index 40f77bad9..e2d6bec7e 100644
--- a/src/pydita/ast/load_xml_doc.py
+++ b/src/pydita_ast/load_xml_doc.py
@@ -6,8 +6,8 @@
 
 from lxml.etree import ParserError
 from lxml.html import fromstring
-import pydita.ast.ast_tree as ast
-import pydita.ast.version_variables as var
+import pydita_ast.ast_tree as ast
+import pydita_ast.version_variables as var
 from tqdm import tqdm
 
 
diff --git a/src/pydita/ast/version_variables.py b/src/pydita_ast/version_variables.py
similarity index 100%
rename from src/pydita/ast/version_variables.py
rename to src/pydita_ast/version_variables.py
diff --git a/src/pydita/ast/writer.py b/src/pydita_ast/writer.py
similarity index 96%
rename from src/pydita/ast/writer.py
rename to src/pydita_ast/writer.py
index 16f22933e..532f9f210 100644
--- a/src/pydita/ast/writer.py
+++ b/src/pydita_ast/writer.py
@@ -2,10 +2,10 @@
 import os
 import shutil
 
-from pydita.ast import ast_tree as ast
-from pydita.ast import load_xml_doc as load
-from pydita.ast.custom_functions import CustomFunctions
-from pydita.ast.directory_format import get_paths
+from pydita_ast import ast_tree as ast
+from pydita_ast import load_xml_doc as load
+from pydita_ast.custom_functions import CustomFunctions
+from pydita_ast.directory_format import get_paths
 from tqdm import tqdm
 
 generated_src_code = os.path.join("src", "pydita", "generatedcommands")
@@ -245,7 +245,10 @@ def write_source(
 
     """
     _package_path = os.path.join(template_path, "_package")
-    custom_functions = CustomFunctions(path_custom_functions)
+    if path_custom_functions is not None:
+        custom_functions = CustomFunctions(path_custom_functions)
+    else:
+        custom_functions = None
 
     if not os.path.isdir(_package_path):
         raise FileNotFoundError(
diff --git a/tox.ini b/tox.ini
index 6521af445..0ea597c32 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,7 +17,7 @@ basepython =
     {style,reformat,doc}: python3
 setenv =
     PYTHONUNBUFFERED = yes
-    coverage: PYTEST_EXTRA_ARGS = --cov=pydita.ast --cov-report=term --cov-report=xml:.cov/xml --cov-report=html:.cov/html
+    coverage: PYTEST_EXTRA_ARGS = --cov=pydita_ast --cov-report=term --cov-report=xml:.cov/xml --cov-report=html:.cov/html
 extras = tests
 commands =
     pytest {env:PYTEST_MARKERS:} {env:PYTEST_EXTRA_ARGS:} {posargs:-vv}
diff --git a/xml2rst.py b/xml2rst.py
index 298b10a9c..4a8f9af37 100644
--- a/xml2rst.py
+++ b/xml2rst.py
@@ -1,4 +1,4 @@
-from pydita.ast import writer as wr
+from pydita_ast import writer as wr
 
 """
 Parse MAPDL command XML documentation.


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index a99608ce2..8417a9259 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,9 +1,9 @@
 import os
 
-from pydita.ast.custom_functions import CustomFunctions
-import pydita.ast.directory_format as ff
-import pydita.ast.load_xml_doc as lxd
-import pydita.ast.writer as wrt
+from pydita_ast.custom_functions import CustomFunctions
+import pydita_ast.directory_format as ff
+import pydita_ast.load_xml_doc as lxd
+import pydita_ast.writer as wrt
 import pytest
 
 pytest_plugins = ["pytester"]
diff --git a/tests/test_custom_functions.py b/tests/test_custom_functions.py
index bcb078098..bf27311d5 100644
--- a/tests/test_custom_functions.py
+++ b/tests/test_custom_functions.py
@@ -1,6 +1,6 @@
 import os
 
-import pydita.ast.custom_functions as cf
+import pydita_ast.custom_functions as cf
 
 
 def test_customfunctions(custom_functions):
diff --git a/tests/test_directory_format.py b/tests/test_directory_format.py
index 9a44439cc..5dd80706e 100644
--- a/tests/test_directory_format.py
+++ b/tests/test_directory_format.py
@@ -1,6 +1,6 @@
 import os
 
-import pydita.ast.directory_format as ff
+import pydita_ast.directory_format as ff
 import pytest
 
 
diff --git a/tests/test_load_xml_doc.py b/tests/test_load_xml_doc.py
index 50ff604a4..01ccd4796 100644
--- a/tests/test_load_xml_doc.py
+++ b/tests/test_load_xml_doc.py
@@ -1,4 +1,4 @@
-import pydita.ast.load_xml_doc as lxd
+import pydita_ast.load_xml_doc as lxd
 
 
 def test_load_links(link_path):
diff --git a/tests/test_writer.py b/tests/test_writer.py
index 8877234b3..997977098 100644
--- a/tests/test_writer.py
+++ b/tests/test_writer.py
@@ -1,7 +1,7 @@
 import os
 import shutil
 
-import pydita.ast.writer as wrt
+import pydita_ast.writer as wrt
 import pytest
 
 
@@ -51,7 +51,9 @@ def package_path(cwd):
     return os.path.join(cwd, "package")
 
 
-def test_write_source(commands, path_custom_functions, cwd, directory_path, package_path):
+def test_write_source_with_custom_functions(
+    commands, path_custom_functions, cwd, directory_path, package_path
+):
     cmd_path = wrt.write_source(commands, directory_path, cwd, path_custom_functions)
     assert cmd_path == os.path.join(package_path, wrt.generated_src_code)
     assert os.path.isfile(os.path.join(cmd_path, "acel.py"))
@@ -59,6 +61,14 @@ def test_write_source(commands, path_custom_functions, cwd, directory_path, pack
     assert os.path.isfile(os.path.join(package_path, "doc", "source", "images", "gcmdrsymm1.png"))
 
 
+def test_write_source_no_custom_function(commands, cwd, directory_path, package_path):
+    cmd_path = wrt.write_source(commands, directory_path, cwd)
+    assert cmd_path == os.path.join(package_path, wrt.generated_src_code)
+    assert os.path.isfile(os.path.join(cmd_path, "acel.py"))
+    assert os.path.isdir(os.path.join(package_path, "doc", "source", "images"))
+    assert os.path.isfile(os.path.join(package_path, "doc", "source", "images", "gcmdrsymm1.png"))
+
+
 def test_write_docs(commands, package_path):
     doc_src = wrt.write_docs(commands, package_path)
     file = open(doc_src, "r")
diff --git a/tests/test_xml_ast.py b/tests/test_xml_ast.py
index 1abe910b3..a540997bb 100644
--- a/tests/test_xml_ast.py
+++ b/tests/test_xml_ast.py
@@ -1,7 +1,7 @@
 # import os
 
 from lxml.html import fromstring
-import pydita.ast.ast_tree as ast
+import pydita_ast.ast_tree as ast
 import pytest