|
1 | | -import os |
2 | | -import argparse |
3 | | -import pickle |
| 1 | +""" |
| 2 | +Legacy compatibility module for YAML to JSON conversion. |
4 | 3 |
|
5 | | -LANGUAGES = ['ja', 'en'] |
6 | | -PICKLE_PATH = 'build/doctrees/environment.pickle' |
| 4 | +This module provides backward compatibility by re-exporting functionality |
| 5 | +that has been moved to more specialized modules (config.py and utils.py). |
| 6 | +New code should use those modules directly instead. |
7 | 7 |
|
8 | | -def setup_parameters(): |
9 | | - args = parse_args() |
10 | | - return process_arguments(args) |
| 8 | +@deprecated: Use config.py and utils.py modules instead |
| 9 | +""" |
11 | 10 |
|
12 | | -def parse_args(): |
13 | | - parser = argparse.ArgumentParser(description="Process YAML files and generate a JSON file containing checklist items.") |
14 | | - parser.add_argument('--basedir', '-b', type=str, default='.', help='Base directory where the data directory is located.') |
15 | | - parser.add_argument('--output-file', '-o', type=str, default='data.json', help='Output file path.') |
16 | | - parser.add_argument('--base-url', '-u', type=str, default='', help='Base URL for the links to related information.') |
17 | | - parser.add_argument('--publish', '-p', action='store_true', help='Generate for publishing') |
18 | | - return parser.parse_args() |
| 11 | +from typing import Dict, Any |
19 | 12 |
|
20 | | -def process_arguments(args): |
21 | | - """ |
22 | | - Process the command-line arguments to determine the build mode, target files, and other options. |
| 13 | +from . import config, utils |
23 | 14 |
|
24 | | - Args: |
25 | | - args: The parsed command-line arguments. |
| 15 | +# Re-export constants for backward compatibility |
| 16 | +LANGUAGES = utils.LANGUAGES |
| 17 | +PICKLE_PATH = utils.PICKLE_PATH |
26 | 18 |
|
27 | | - Returns: |
28 | | - A dictionary containing settings derived from the command-line arguments. |
29 | | - """ |
30 | | - basedir = os.path.abspath(args.basedir) |
31 | | - if os.path.isabs(args.output_file): |
32 | | - output_file = args.output_file |
33 | | - elif not os.path.dirname(args.output_file): |
34 | | - output_file = os.path.join(basedir, args.output_file) |
35 | | - else: |
36 | | - output_file = os.path.abspath(args.output_file) |
37 | | - return { |
38 | | - 'basedir': basedir, |
39 | | - 'output_file': output_file, |
40 | | - 'base_url': args.base_url, |
41 | | - 'publish': args.publish |
42 | | - } |
| 19 | +# Re-export exception for backward compatibility |
| 20 | +InitializerError = config.ConfigError |
43 | 21 |
|
44 | | -def get_info_links(basedir, baseurl = ''): |
| 22 | +def setup_parameters() -> Dict[str, Any]: |
45 | 23 | """ |
46 | | - Extract the labels from the environment pickle file. |
47 | | -
|
48 | | - Args: |
49 | | - basedir: The project root directory where the data directory is located for each language. |
50 | | - baseurl: The base URL for the links to related information. |
51 | | -
|
52 | | - Returns: |
53 | | - A dictionary containing the labels extracted from the environment pickle file. |
| 24 | + @deprecated: Use config.setup_configuration() instead |
54 | 25 | """ |
55 | | - info = {} |
56 | | - path_prefix = { |
57 | | - 'ja': '', |
58 | | - 'en': 'en/' |
59 | | - } |
60 | | - for lang in LANGUAGES: |
61 | | - pickle_file = os.path.abspath(os.path.join(basedir, lang, PICKLE_PATH)) |
62 | | - try: |
63 | | - with open(pickle_file, 'rb') as f: |
64 | | - doctree = pickle.load(f) |
65 | | - except Exception as e: |
66 | | - raise Exception(f'Error loading environment pickle file: {pickle_file}') from e |
67 | | - labels = doctree.domaindata['std']['labels'] |
68 | | - for label in labels: |
69 | | - if labels[label][0] == '' or labels[label][1] == '' or labels[label][2] == '': |
70 | | - continue |
71 | | - if label not in info: |
72 | | - info[label] = { |
73 | | - 'text': {}, |
74 | | - 'url': {} |
75 | | - } |
76 | | - info[label]['text'][lang] = labels[label][2] |
77 | | - info[label]['url'][lang] = f'{baseurl}/{path_prefix[lang]}{labels[label][0]}.html#{labels[label][1]}' |
| 26 | + return config.setup_configuration() |
78 | 27 |
|
79 | | - return info |
| 28 | +def get_info_links(basedir: str, baseurl: str = '') -> Dict[str, Any]: |
| 29 | + """ |
| 30 | + @deprecated: Use utils.get_info_links() instead |
| 31 | + """ |
| 32 | + return utils.get_info_links(basedir, baseurl) |
80 | 33 |
|
81 | | -def version_info(basedir): |
82 | | - version_info = {} |
83 | | - with open(os.path.join(basedir, 'version.py'), encoding='utf-8') as f: |
84 | | - exec(f.read(), version_info) |
85 | | - return version_info |
| 34 | +def version_info(basedir: str) -> Dict[str, str]: |
| 35 | + """ |
| 36 | + @deprecated: Use utils.get_version_info() instead |
| 37 | + """ |
| 38 | + return utils.get_version_info(basedir) |
0 commit comments