Debian Codegraph @

tests/trb_syntax_english.py

raw symbols SCIP
1 """Creates a version of syntax_traceback_en.rst to insert in the documentation.
2 """
3
4 # When creating a new translation, you need to:
5 # 1. Make a copy of this file
6 # 2. Change the value of LANG as well as 'intro_text' so that they reflect the
7 # appropriate language
8 # 3. Change the first line of this file so that the name of the rst file
9 # is correct!
10
11
12 import os
13 import sys
14 import platform
15 this_dir = os.path.dirname(__file__)
16 sys.path.append(os.path.join(this_dir, ".."))
17 import friendly_traceback
18
19 # Make it possible to find docs and tests source
20 docs_root_dir = os.path.abspath(
21 os.path.join(this_dir, "..", "..", "friendly-docs")
22 )
23 assert os.path.isdir(docs_root_dir), "Separate docs repo need to exist"
24
25 LANG = "en"
26 friendly_traceback.install()
27 friendly_traceback.set_lang(LANG)
28 friendly_traceback.set_formatter("docs")
29
30 sys.path.insert(0, this_dir)
31 py_version = f"{sys.version_info.major}.{sys.version_info.minor}"
32
33 import trb_syntax_common
34
35 target = os.path.normpath(
36 os.path.join(
37 docs_root_dir, f"source/syntax_tracebacks_{LANG}_{py_version}.rst"
38 )
39 )
40
41 intro_text = """
42 Friendly SyntaxError tracebacks - in English
43 =============================================
44
45 Friendly aims to provide friendlier feedback when an exception
46 is raised than what is done by Python.
47 This file contains only examples of SyntaxError and its sub-classes.
48 Some tests may appear to be repetitive to a human reader
49 but they are may be included to ensure more complete test coverage.
50
51 .. note::
52
53 The content of this page is generated by running
54 `{name}` located in the ``tests/`` directory.
55 This needs to be done explicitly, independently of updating the
56 documentation using Sphinx.
57 On Windows, if Sphinx is installed on your computer, it is suggested
58 instead to run make_trb.bat in the root directory as it will create
59 similar files for all languages *and* update the documentation.
60
61 Friendly-traceback version: {friendly}
62 Python version: {python}
63
64 """.format(
65 friendly=friendly_traceback.__version__,
66 python=platform.python_version(),
67 name=sys.argv[0],
68 )
69
70 print(f"Python version: {platform.python_version()}; English")
71
72 trb_syntax_common.create_tracebacks(target, intro_text)