Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/build_config/buildPyDoc.py
193867 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2011-2026 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file buildPyDoc.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2011-10-20
18
19
"""
20
Generates pydoc files for all python libraries.
21
"""
22
from __future__ import absolute_import
23
from __future__ import print_function
24
import os
25
import sys
26
import shutil
27
import pydoc
28
import types
29
from optparse import OptionParser
30
try:
31
# this can be removed once https://github.com/python/cpython/issues/127276 has been resolved
32
import importlib.resources
33
css_data = importlib.resources.files('pydoc_data').joinpath('_pydoc.css').read_text()
34
except Exception:
35
css_data = ""
36
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
37
import traci # noqa
38
import sumolib # noqa
39
from sumolib.miscutils import working_dir # noqa
40
41
42
def pydoc_recursive(module):
43
pydoc.writedoc(module)
44
if css_data:
45
with open(module.__name__ + ".html") as inp:
46
html = inp.read()
47
with open(module.__name__ + ".html", "w") as out:
48
out.write(html.replace("</head>", "<style>%s</style></head>" % css_data))
49
for submod in module.__dict__.values():
50
if isinstance(submod, types.ModuleType) and submod.__name__.startswith(module.__name__):
51
pydoc_recursive(submod)
52
53
54
optParser = OptionParser()
55
optParser.add_option("-p", "--pydoc-output", help="output folder for pydoc")
56
optParser.add_option("-c", "--clean", action="store_true", default=False, help="remove output dirs")
57
(options, args) = optParser.parse_args()
58
59
if options.pydoc_output:
60
if options.clean:
61
shutil.rmtree(options.pydoc_output, ignore_errors=True)
62
os.mkdir(options.pydoc_output)
63
with working_dir(options.pydoc_output):
64
for module in (traci, sumolib):
65
pydoc_recursive(module)
66
67