generated from jCloud/repository-template
style: format source code using Ruff
This commit is contained in:
41 files changed
+6061
-5670
No files matched your search
@@ -12,9 +12,9 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
'''
|
||||
"""
|
||||
The command line interface
|
||||
'''
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
@@ -31,80 +31,81 @@ __all__ = [
|
||||
_LANG_PYTHON = 'python'
|
||||
_PROGRAM_NAME = 'jcloud-docsgen'
|
||||
|
||||
|
||||
def existing_directory(path: str) -> pathlib.Path:
|
||||
_path = path
|
||||
path = pathlib.Path(_path)
|
||||
if not path.exists():
|
||||
raise argparse.ArgumentTypeError(
|
||||
f'{_path}: no such file or directory'
|
||||
)
|
||||
raise argparse.ArgumentTypeError(f'{_path}: no such file or directory')
|
||||
if not path.is_dir():
|
||||
raise argparse.ArgumentTypeError(f'{_path}: not a directory')
|
||||
return path
|
||||
|
||||
|
||||
def error(message: str, exit_code: int = 1):
|
||||
'''
|
||||
"""
|
||||
Shows an error message and returns the exit code.
|
||||
|
||||
:param message: The error message to show.
|
||||
:type message: str
|
||||
:param exit_code: The exit code.
|
||||
:type exit_code: int
|
||||
'''
|
||||
"""
|
||||
|
||||
print(f'{_PROGRAM_NAME}: error: {message}', file = sys.stderr)
|
||||
print(f'{_PROGRAM_NAME}: error: {message}', file=sys.stderr)
|
||||
return exit_code
|
||||
|
||||
|
||||
def create_argument_parser() -> argparse.ArgumentParser:
|
||||
'''
|
||||
"""
|
||||
Prepares a parser to parse the command-line arguments using
|
||||
argparse.
|
||||
|
||||
:return: The parser.
|
||||
:rtype: argparse.ArgumentParser
|
||||
'''
|
||||
"""
|
||||
|
||||
common_parser = argparse.ArgumentParser(add_help = False)
|
||||
common_parser = argparse.ArgumentParser(add_help=False)
|
||||
common_parser.add_argument(
|
||||
'project_directory',
|
||||
type = existing_directory,
|
||||
nargs = '?',
|
||||
default = pathlib.Path('.'),
|
||||
help = 'The directory of the project',
|
||||
type=existing_directory,
|
||||
nargs='?',
|
||||
default=pathlib.Path('.'),
|
||||
help='The directory of the project',
|
||||
)
|
||||
common_parser.add_argument(
|
||||
'-o',
|
||||
'--output-dir',
|
||||
type = pathlib.Path,
|
||||
help = 'the output directory the documentation will be written to',
|
||||
type=pathlib.Path,
|
||||
help='the output directory the documentation will be written to',
|
||||
)
|
||||
|
||||
argument_parser = argparse.ArgumentParser()
|
||||
|
||||
subparsers = argument_parser.add_subparsers(
|
||||
dest = 'language',
|
||||
required = True,
|
||||
dest='language',
|
||||
required=True,
|
||||
)
|
||||
|
||||
python_parser = subparsers.add_parser(
|
||||
_LANG_PYTHON,
|
||||
parents = [common_parser],
|
||||
help = 'generate documentation for Python project',
|
||||
parents=[common_parser],
|
||||
help='generate documentation for Python project',
|
||||
)
|
||||
python_parser.add_argument(
|
||||
'-s',
|
||||
'--sections',
|
||||
nargs = '+',
|
||||
choices = VALID_PYTHON_SECTIONS,
|
||||
help = 'the sections to be included in the documentation',
|
||||
nargs='+',
|
||||
choices=VALID_PYTHON_SECTIONS,
|
||||
help='the sections to be included in the documentation',
|
||||
)
|
||||
python_parser.add_argument(
|
||||
'-S',
|
||||
'--sections-exclude',
|
||||
nargs = '+',
|
||||
default = [],
|
||||
choices = VALID_PYTHON_SECTIONS,
|
||||
help = (
|
||||
nargs='+',
|
||||
default=[],
|
||||
choices=VALID_PYTHON_SECTIONS,
|
||||
help=(
|
||||
'the sections to be excluded in the documentation. '
|
||||
'If a section shall be included AND excluded, it is excluded.'
|
||||
),
|
||||
@@ -112,8 +113,8 @@ def create_argument_parser() -> argparse.ArgumentParser:
|
||||
python_parser.add_argument(
|
||||
'-H',
|
||||
'--allow-html',
|
||||
action = 'store_true',
|
||||
help = (
|
||||
action='store_true',
|
||||
help=(
|
||||
'indicates whether HTML is allowed in the documentation. '
|
||||
'By default, HTML is disabled.'
|
||||
),
|
||||
@@ -121,8 +122,8 @@ def create_argument_parser() -> argparse.ArgumentParser:
|
||||
python_parser.add_argument(
|
||||
'-T',
|
||||
'--allow-tables',
|
||||
action = 'store_true',
|
||||
help = (
|
||||
action='store_true',
|
||||
help=(
|
||||
'indicates whether Markdown tables are allowed in the '
|
||||
'documentation. By default, Markdown tables are disabled. '
|
||||
'Warning: Markdown tables are not CommonMark.'
|
||||
@@ -131,7 +132,8 @@ def create_argument_parser() -> argparse.ArgumentParser:
|
||||
|
||||
return argument_parser
|
||||
|
||||
def main(argv = None) -> int:
|
||||
|
||||
def main(argv=None) -> int:
|
||||
argument_parser = create_argument_parser()
|
||||
args = argument_parser.parse_args(argv)
|
||||
|
||||
@@ -141,13 +143,14 @@ def main(argv = None) -> int:
|
||||
try:
|
||||
if args.language == _LANG_PYTHON:
|
||||
from .languages.python import generate
|
||||
|
||||
generate(
|
||||
args.project_directory,
|
||||
args.output_dir,
|
||||
include_sections = args.sections,
|
||||
exclude_sections = args.sections_exclude,
|
||||
allow_html = args.allow_html,
|
||||
allow_tables = args.allow_tables,
|
||||
include_sections=args.sections,
|
||||
exclude_sections=args.sections_exclude,
|
||||
allow_html=args.allow_html,
|
||||
allow_tables=args.allow_tables,
|
||||
)
|
||||
except FileNotFoundError as exc:
|
||||
return error(f'{exc.filename}: no such file or directory')
|
||||
|
||||
Reference in new issue
Block a user