[go: up one dir, main page]

Menu

[c0d108]: / main.py  Maximize  Restore  History

Download this file

103 lines (86 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
# main.py
# Summary: Create the documentation of a module, using ClammingPy library.
# Usage: python main.py --help
#
# This file is part of ClammingPy tool.
# (C) 2023-2024 Brigitte Bigi, Laboratoire Parole et Langage,
# Aix-en-Provence, France.
#
# Use of this software is governed by the GNU Public License, version 3.
#
# ClammingPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ClammingPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ClammingPy. If not, see <http://www.gnu.org/licenses/>.
#
# This banner notice must not be removed.
#
# ---------------------------------------------------------------------------
from __future__ import annotations
import os
import sys
import importlib
from argparse import ArgumentParser
import clamming
# ----------------------------------------------------------------------------
# Verify and extract args:
# ----------------------------------------------------------------------------
parser = ArgumentParser(usage="%s [options]" % os.path.basename(os.path.abspath(__file__)),
description="... create documentation of a python class or module.")
parser.add_argument("--md",
action='store_true',
help="Enable Markdown output instead of HTML")
parser.add_argument("-c",
metavar="str",
required=False,
help="Name of the class to be documented")
parser.add_argument("-m",
metavar="str",
required=True,
help="Name of the module")
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
# At least one argument is expected. If not, add help.
if len(sys.argv) <= 1:
sys.argv.append('-h')
args = parser.parse_args()
# ---------------------------------------------------------------------------
# Import the given module
try:
module = importlib.import_module(args.m)
except ModuleNotFoundError as e:
print("Invalid module name: {:s}".format(str(e)))
sys.exit(-1)
# ---------------------------------------------------------------------------
# Print the doc
if args.c:
# Create the documentation of a single class of the Python module
# ---------------------------------------------------------------
# Turn the given string into a class
c = clamming.ClamUtils.get_class(args.c, args.m)
# Create the documentation of the class
parser = clamming.ClammingClassParser(c)
clams_class = clamming.ClamsClass(parser)
# Print in the requested format
if args.md:
print(clams_class.markdown())
else:
print(clams_class.html())
else:
# Create the documentation of all classes of the Python module
# ------------------------------------------------------------
clams_pack = clamming.ClamsPack(module)
# Print in the requested format
if args.md:
print(clams_pack.markdown())
else:
print(clams_pack.html())