2 Commits
Author SHA1 Message Date
jakob.scheid b1213e1f24 docs(changelog): add namespace error fix entry
Added a changelog entry for the namespace name error of the Python
project documentation generator.
2026-09-28 22:28:36 +02:00
jakob.scheid d1c9839ec7 fix(python-generator): resolve directory path
The path to the directory is now completely resolved in
PythonDocumentationGenerator._namespace to prevent from empty path names
if the path is '.'. A fallback was also added for the case that the path
is '/'; the fallback value is irrelevant as the root namespace name does
not occur in the output and only the root package path can be '/'.
2026-09-28 22:26:32 +02:00
49 changed files with 463 additions and 250 deletions

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
Third-Party Notices
===================
This software uses the following third-party libraries. Full license texts are available in the 'licenses/' directory.
1. docstring-parser 0.17.0
Author: Marcin Kurczewski
License: MIT License
See licenses/docstring-parser.txt for full license text.
2. iniconfig 2.3.0
Author: Holger Krekel and others
License: MIT License
See licenses/iniconfig.txt for full license text.
3. packaging 26.0
Author: Donald Stufft and individual contributors
License: Apache License 2.0
URL: None
See licenses/packaging.txt for full license text.
4. pluggy 1.6.0
Author: Holger Krekel
License: MIT License
See licenses/pluggy.txt for full license text.
5. pygments 2.18.0
Author: Georg Brandl, Tim Hatch, Armin Ronacher, Others
License: BSD-2-Clause
See licenses/pygments.txt for full license text.
6. pytest 9.0.2
Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin, Others
License: MIT License
See licenses/pytest.txt for full license text.
7. pytest-expectdir 1.2.0
Author: Léo Falventin Hauchecorne
License: MIT
URL: https://github.com/hl037/pytest-expectdir
See licenses/pytest-expectdir.txt for full license text.
+1 -13
View File
@@ -1,22 +1,10 @@
# Changelog # Changelog
## [0.2.2] - 2026-10-14 ## [Unreleased]
### Fixed ### Fixed
- Import error in Python <3.13 which prevented the tool from running and made it unusuable in Python <3.13
## [0.2.1] - 2026-10-06
### Fixed
- Python namespace name conflict when package and module have the same name
- Internal namespace name error which occured when generating Python documentation with `.` as the project directory - Internal namespace name error which occured when generating Python documentation with `.` as the project directory
- Ignore Python namespaces with invalid names during documentation generation
### Changed
- Stricter Python namespace name validation
## [0.2.0] - 2026-09-28 ## [0.2.0] - 2026-09-28
@@ -1,45 +1,5 @@
# Module `jcloud_docsgen.core.python.namespaces` # Module `jcloud_docsgen.core.python.namespaces`
## Function `validate_namespace_name`
Checks whether a namespace name is valid. Namespace names are valid
if they contain no dots and are valid Python identifiers.
### Function signature
```python
validate_namespace_name(name: str) -> bool
```
### Returns
Whether the namespace name is valid.
Return type: `bool`
### Parameters
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `name` | `str` | normal | -- | The namespace name to validate. |
### Docstring
Checks whether a namespace name is valid. Namespace names are valid
if they contain no dots and are valid Python identifiers.
:param name: The namespace name to validate.
:type name: str
:returns: Whether the namespace name is valid.
:rtype: bool
## Class `PythonNamespace` ## Class `PythonNamespace`
The base class for all Python namespaces such as modules or packages. The base class for all Python namespaces such as modules or packages.
@@ -97,8 +57,6 @@ The base class for all Python namespaces such as modules or packages.
:param name: The name of the namespace. :param name: The name of the namespace.
:type name: str :type name: str
:raises InvalidNamespaceError: If the namespace name is invalid.
## Class `PythonPackageNamespace` ## Class `PythonPackageNamespace`
A subclass of ``PythonNamespace`` for Python package namespaces. A subclass of ``PythonNamespace`` for Python package namespaces.
@@ -423,8 +381,6 @@ A subclass of ``PythonNamespace`` for Python package namespaces.
:param sub_namespaces: The sub-namespaces. :param sub_namespaces: The sub-namespaces.
:type sub_namespaces: list[PythonNamespace] :type sub_namespaces: list[PythonNamespace]
:raises InvalidNamespaceError: If the namespace name is invalid.
## Class `PythonModuleNamespace` ## Class `PythonModuleNamespace`
A subclass of ``PythonNamespace`` for Python module namespaces. A subclass of ``PythonNamespace`` for Python module namespaces.
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 Marcin Kurczewski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2010 - 2023 Holger Krekel and others
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+177
View File
@@ -0,0 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 holger krekel (rather uses bitbucket/hpk42)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+25
View File
@@ -0,0 +1,25 @@
Copyright (c) 2006-2022 by the respective authors (see AUTHORS file).
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+19
View File
@@ -0,0 +1,19 @@
This is the MIT license: http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2015-2022 the pytest-datadir authors and contributors <see AUTHORS file>.
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2004 Holger Krekel and others
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Generated
+4 -4
View File
@@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 2.5.1 and should not be changed by hand. # This file is automatically @generated by Poetry 2.4.3 and should not be changed by hand.
[[package]] [[package]]
name = "colorama" name = "colorama"
@@ -235,14 +235,14 @@ version = "4.16.0"
description = "Backported and Experimental Type Hints for Python 3.9+" description = "Backported and Experimental Type Hints for Python 3.9+"
optional = false optional = false
python-versions = ">=3.9" python-versions = ">=3.9"
groups = ["main", "dev"] groups = ["dev"]
markers = "python_version == \"3.10\""
files = [ files = [
{file = "typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"}, {file = "typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"},
{file = "typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5"}, {file = "typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5"},
] ]
markers = {dev = "python_version == \"3.10\""}
[metadata] [metadata]
lock-version = "2.1" lock-version = "2.1"
python-versions = ">=3.10" python-versions = ">=3.10"
content-hash = "0fb3b53540e7a7fe173bf29a2031bd59f863a8dea94a29d51933de2375c3bfa2" content-hash = "24c9a2d464f6c737eeae0a66f792fa23824c3960b7cc72a22fff1408f21ec812"
+2 -2
View File
@@ -4,9 +4,9 @@ build-backend = "poetry.core.masonry.api"
[project] [project]
name = "jcloud-docsgen" name = "jcloud-docsgen"
version = "0.2.2" version = "0.2.0"
description = "A tool that generates Markdown documentation for software project source code" description = "A tool that generates Markdown documentation for software project source code"
dependencies = ["docstring-parser", "typing-extensions (>=4.16.0,<5.0.0)"] dependencies = ["docstring-parser"]
requires-python = ">=3.10" requires-python = ">=3.10"
license = "Apache-2.0" license = "Apache-2.0"
+5 -21
View File
@@ -37,11 +37,7 @@ from .definitions import (
PythonFunctionDefinition, PythonFunctionDefinition,
) )
from .docstrings import PythonDocstring from .docstrings import PythonDocstring
from .namespaces import ( from .namespaces import PythonModuleNamespace, PythonPackageNamespace
PythonModuleNamespace,
PythonPackageNamespace,
validate_namespace_name,
)
__all__ = [ __all__ = [
'PythonDefinitionDocumentationIncludeSections', 'PythonDefinitionDocumentationIncludeSections',
@@ -930,12 +926,9 @@ class PythonModuleDocumentationGenerator:
), ),
**kwargs, **kwargs,
) -> None: ) -> None:
if not ( if module_path.name.count('.') > 1:
module_path.suffix == '.py'
and validate_namespace_name(module_path.stem)
):
raise InvalidNamespaceError( raise InvalidNamespaceError(
'invalid module file name', 'namespace identifier cannot contain more than one dot',
namespace_identifier=module_path.name, namespace_identifier=module_path.name,
) )
@@ -1107,25 +1100,16 @@ class PythonDocumentationGenerator:
# fallback for the case that the path it '/'. In this case, the # fallback for the case that the path it '/'. In this case, the
# name would be ''. The fallback value is irrelevant; the name is # name would be ''. The fallback value is irrelevant; the name is
# only specified because PythonPackageNamespace requires # only specified because PythonPackageNamespace requires
# specifying it. The name will not be included in the generated # specifying it. The name will not occur in the generated output.
# output.
directory.resolve().name or 'project', directory.resolve().name or 'project',
[], [],
) )
for entry in directory.iterdir(): for entry in directory.iterdir():
try: if entry.is_dir():
if entry.is_dir() and (
entry.parent / (f'{entry.stem}.py')
).resolve() not in [
e.resolve() for e in entry.parent.iterdir()
]:
namespace.add(self._namespace(entry)) namespace.add(self._namespace(entry))
elif entry.suffix == '.py': elif entry.suffix == '.py':
namespace.add(PythonModuleNamespace(entry.stem)) namespace.add(PythonModuleNamespace(entry.stem))
except InvalidNamespaceError:
# the name of the directory or module is invalid; ignore.
pass
return namespace return namespace
+3 -26
View File
@@ -14,7 +14,6 @@
from __future__ import annotations from __future__ import annotations
import keyword
from typing import TypeAlias, Union from typing import TypeAlias, Union
from ...exceptions import ( from ...exceptions import (
@@ -25,47 +24,27 @@ from ...exceptions import (
from ...utils import assert_that_is_instance from ...utils import assert_that_is_instance
__all__ = [ __all__ = [
'validate_namespace_name',
'PythonNamespace', 'PythonNamespace',
'PythonPackageNamespace', 'PythonPackageNamespace',
'PythonModuleNamespace', 'PythonModuleNamespace',
] ]
def validate_namespace_name(name: str) -> bool:
"""
Checks whether a namespace name is valid. Namespace names are valid
if they contain no dots and are valid Python identifiers.
:param name: The namespace name to validate.
:type name: str
:returns: Whether the namespace name is valid.
:rtype: bool
"""
if not isinstance(name, str):
return False
return name.isidentifier() and not keyword.iskeyword(name)
class PythonNamespace: class PythonNamespace:
""" """
The base class for all Python namespaces such as modules or packages. The base class for all Python namespaces such as modules or packages.
:param name: The name of the namespace. :param name: The name of the namespace.
:type name: str :type name: str
:raises InvalidNamespaceError: If the namespace name is invalid.
""" """
def __init__(self, name: str) -> None: def __init__(self, name: str) -> None:
assert_that_is_instance(name, str) assert_that_is_instance(name, str)
if not validate_namespace_name(name): if not name.strip():
raise InvalidNamespaceError( raise InvalidNamespaceError(
'invalid namespace', namespace_identifier=name 'invalid namespace',
namespace_identifier=name,
) )
self.name = name self.name = name
@@ -91,8 +70,6 @@ class PythonPackageNamespace(PythonNamespace):
:type name: str :type name: str
:param sub_namespaces: The sub-namespaces. :param sub_namespaces: The sub-namespaces.
:type sub_namespaces: list[PythonNamespace] :type sub_namespaces: list[PythonNamespace]
:raises InvalidNamespaceError: If the namespace name is invalid.
""" """
def __init__( def __init__(
-14
View File
@@ -14,20 +14,6 @@
import errno import errno
__all__ = [
'NamespaceError',
'InvalidNamespaceError',
'NamespaceNotFoundError',
'NamespaceExistsError',
'PythonIdentifierError',
'InvalidPythonIdentifierError',
'PythonAnnotationError',
'InvalidPythonAnnotationError',
'PythonDefinitionError',
'PythonArgumentStructureError',
'DirectoryNotEmptyError',
]
class NamespaceError(ValueError): class NamespaceError(ValueError):
""" """
-10
View File
@@ -27,16 +27,6 @@ except ImportError:
from typing_extensions import deprecated from typing_extensions import deprecated
__all__ = [
'ExistingDirectory',
'ExistingFile',
'human_readable_list',
'assert_that_is_instance',
'non_empty_str',
'get_relative_path_segments',
]
@deprecated('Use pathlib.Path instead.') @deprecated('Use pathlib.Path instead.')
class ExistingDirectory(pathlib.Path): class ExistingDirectory(pathlib.Path):
""" """
@@ -1,9 +0,0 @@
# Module `pkg.a.b`
## Function `fn`
### Function signature
```python
fn()
```
@@ -25,134 +25,176 @@ from src.jcloud_docsgen.exceptions import InvalidNamespaceError
[ [
( (
pathlib.Path( pathlib.Path(
('tests/unit/core/python/_core/invalid_module_names/a.b.c'),
),
None,
InvalidNamespaceError,
'invalid module file name: a.b.c',
),
( (
pathlib.Path( 'tests/unit/core/python/_core/fil'
('tests/unit/core/python/_core/invalid_module_names/a.b.c.d'), 'es_with_more_than_one_dot/a.b.c'
),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d', 'namespace identifier cannot contain more than one dot: a.b.c',
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/i' 'tests/unit/core/python/_core/file'
'nvalid_module_names/a.b.c.d.e' 's_with_more_than_one_dot/a.b.c.d'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e', 'namespace identifier cannot contain more than one dot: a.b.c.d',
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/in' 'tests/unit/core/python/_core/files'
'valid_module_names/a.b.c.d.e.f' '_with_more_than_one_dot/a.b.c.d.e'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.f', (
'namespace identifier cannot cont'
'ain more than one dot: a.b.c.d.e'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/inv' 'tests/unit/core/python/_core/files_'
'alid_module_names/a.b.c.d.e.f.g' 'with_more_than_one_dot/a.b.c.d.e.f'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.f.g', (
'namespace identifier cannot conta'
'in more than one dot: a.b.c.d.e.f'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/inva' 'tests/unit/core/python/_core/files_w'
'lid_module_names/a.b.c.d.e.f.g.h' 'ith_more_than_one_dot/a.b.c.d.e.f.g'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.f.g.h', (
'namespace identifier cannot contai'
'n more than one dot: a.b.c.d.e.f.g'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/inval' 'tests/unit/core/python/_core/files_wi'
'id_module_names/a.b.c.d.e.f.g.h.py' 'th_more_than_one_dot/a.b.c.d.e.f.g.h'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.f.g.h.py', (
'namespace identifier cannot contain'
' more than one dot: a.b.c.d.e.f.g.h'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/inva' 'tests/unit/core/python/_core/files_wit'
'lid_module_names/a.b.c.d.e.f.g.py' 'h_more_than_one_dot/a.b.c.d.e.f.g.h.py'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.f.g.py', (
'namespace identifier cannot contain m'
'ore than one dot: a.b.c.d.e.f.g.h.py'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/in' 'tests/unit/core/python/_core/files_wi'
'lid_module_names/a.b.c.d.e.f.py' 'th_more_than_one_dot/a.b.c.d.e.f.g.py'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.f.py', (
'namespace identifier cannot contain '
'more than one dot: a.b.c.d.e.f.g.py'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/in' 'tests/unit/core/python/_core/files_w'
'valid_module_names/a.b.c.d.e.py' 'ith_more_than_one_dot/a.b.c.d.e.f.py'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.e.py', (
'namespace identifier cannot contain'
' more than one dot: a.b.c.d.e.f.py'
),
), ),
( (
pathlib.Path( pathlib.Path(
( (
'tests/unit/core/python/_core/i' 'tests/unit/core/python/_core/files_'
'nvalid_module_names/a.b.c.d.py' 'with_more_than_one_dot/a.b.c.d.e.py'
), ),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.d.py', (
'namespace identifier cannot contai'
'n more than one dot: a.b.c.d.e.py'
),
), ),
( (
pathlib.Path( pathlib.Path(
('tests/unit/core/python/_core/invalid_module_names/a.b.c.py'), (
'tests/unit/core/python/_core/files'
'_with_more_than_one_dot/a.b.c.d.py'
),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.c.py', (
'namespace identifier cannot conta'
'in more than one dot: a.b.c.d.py'
),
), ),
( (
pathlib.Path( pathlib.Path(
('tests/unit/core/python/_core/invalid_module_names/a.b.py'), (
'tests/unit/core/python/_core/file'
's_with_more_than_one_dot/a.b.c.py'
),
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.py', (
'namespace identifier cannot cont'
'ain more than one dot: a.b.c.py'
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/fil'
'es_with_more_than_one_dot/a.b.py'
),
),
None,
InvalidNamespaceError,
'namespace identifier cannot contain more than one dot: a.b.py',
), ),
( (
pathlib.Path( pathlib.Path(
@@ -163,7 +205,7 @@ from src.jcloud_docsgen.exceptions import InvalidNamespaceError
), ),
None, None,
InvalidNamespaceError, InvalidNamespaceError,
'invalid module file name: a.b.py', 'namespace identifier cannot contain more than one dot: a.b.py',
), ),
], ],
) )
@@ -28,6 +28,7 @@ class StrSubclass(str): ...
'namespace,expected_name', 'namespace,expected_name',
[ [
(PythonModuleNamespace('a'), 'a'), (PythonModuleNamespace('a'), 'a'),
(PythonModuleNamespace('1'), '1'),
(PythonModuleNamespace(StrSubclass('a')), StrSubclass('a')), (PythonModuleNamespace(StrSubclass('a')), StrSubclass('a')),
], ],
) )
@@ -40,7 +41,11 @@ def test_PythonModuleNamespace_name_attribute(namespace, expected_name):
[ [
(PythonModuleNamespace('a'), PythonModuleNamespace('a'), True), (PythonModuleNamespace('a'), PythonModuleNamespace('a'), True),
(PythonModuleNamespace('b'), PythonModuleNamespace('b'), True), (PythonModuleNamespace('b'), PythonModuleNamespace('b'), True),
(PythonModuleNamespace('1'), PythonModuleNamespace('1'), True),
(PythonModuleNamespace('42'), PythonModuleNamespace('42'), True),
(PythonModuleNamespace('a'), PythonModuleNamespace('b'), False), (PythonModuleNamespace('a'), PythonModuleNamespace('b'), False),
(PythonModuleNamespace('0'), PythonModuleNamespace('-0'), False),
(PythonModuleNamespace('1'), PythonModuleNamespace('a'), False),
(PythonModuleNamespace('a'), 'a', False), (PythonModuleNamespace('a'), 'a', False),
(PythonModuleNamespace('a'), 'b', False), (PythonModuleNamespace('a'), 'b', False),
(PythonModuleNamespace('a'), PythonPackageNamespace('a', []), False), (PythonModuleNamespace('a'), PythonPackageNamespace('a', []), False),
@@ -56,6 +61,7 @@ def test_PythonModuleNamespace___eq__(namespace1, namespace2, expected):
'namespace,expected', 'namespace,expected',
[ [
(PythonModuleNamespace('a'), "PythonModuleNamespace('a')"), (PythonModuleNamespace('a'), "PythonModuleNamespace('a')"),
(PythonModuleNamespace('1'), "PythonModuleNamespace('1')"),
( (
PythonModuleNamespace(StrSubclass('a')), PythonModuleNamespace(StrSubclass('a')),
"PythonModuleNamespace('a')", "PythonModuleNamespace('a')",
@@ -24,6 +24,7 @@ class StrSubclass(str): ...
'namespace,expected_name', 'namespace,expected_name',
[ [
(PythonNamespace('a'), 'a'), (PythonNamespace('a'), 'a'),
(PythonNamespace('1'), '1'),
(PythonNamespace(StrSubclass('a')), StrSubclass('a')), (PythonNamespace(StrSubclass('a')), StrSubclass('a')),
], ],
) )
@@ -35,6 +36,7 @@ def test_PythonNamespace_name_attribute(namespace, expected_name):
'namespace,expected', 'namespace,expected',
[ [
(PythonNamespace('a'), "PythonNamespace('a')"), (PythonNamespace('a'), "PythonNamespace('a')"),
(PythonNamespace('1'), "PythonNamespace('1')"),
(PythonNamespace(StrSubclass('a')), "PythonNamespace('a')"), (PythonNamespace(StrSubclass('a')), "PythonNamespace('a')"),
], ],
) )
@@ -38,6 +38,13 @@ class StrSubclass(str): ...
), ),
'a', 'a',
), ),
(
PythonPackageNamespace(
'1',
[],
),
'1',
),
( (
PythonPackageNamespace( PythonPackageNamespace(
StrSubclass('a'), StrSubclass('a'),
@@ -284,6 +291,10 @@ def test_PythonPackageNamespace___eq__(namespace1, namespace2, expected):
PythonPackageNamespace('a', []), PythonPackageNamespace('a', []),
"PythonPackageNamespace('a', [])", "PythonPackageNamespace('a', [])",
), ),
(
PythonPackageNamespace('1', []),
"PythonPackageNamespace('1', [])",
),
( (
PythonPackageNamespace(StrSubclass('a'), []), PythonPackageNamespace(StrSubclass('a'), []),
"PythonPackageNamespace('a', [])", "PythonPackageNamespace('a', [])",
@@ -1,52 +0,0 @@
# Copyright 2026 jCloud
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from src.jcloud_docsgen.core.python.namespaces import validate_namespace_name
@pytest.mark.parametrize(
'name,expected',
[
('a', True),
('namespace', True),
('match', True),
('case', True),
('type', True),
('_', True),
('__', True),
('___', True),
('_a', True),
('_a_', True),
('_a.', False),
('a.b', False),
('a-b', False),
('a.', False),
('a-', False),
('.a', False),
('-a', False),
('.a.', False),
('-a-', False),
('.', False),
('a-.b', False),
('"', False),
('""', False),
('def', False),
('class', False),
('import', False),
],
)
def test_validate_namespace_name(name, expected):
assert validate_namespace_name(name) == expected