Skip to content

Commit 9d31cb4

Browse files
authored
Merge pull request #282 from ma10/yaml2sheet-20250127
YAMLファイルからGoogleスプレッドシートを生成するスクリプト
2 parents d674d6e + 4a84a71 commit 9d31cb4

24 files changed

+2595
-36
lines changed

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ pyyaml
66
jsonschema < 4.18.0
77
GitPython
88
sphinx-lint
9+
google-auth-oauthlib
10+
google-api-python-client
11+
pytz
12+
tools/yaml2x/get_yaml_data
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
YAML to JSON converter package for accessibility guidelines.
3+
4+
This package provides functionality to convert YAML-based accessibility
5+
guidelines into JSON format, handling RST markup and multilingual content.
6+
"""
7+
8+
from .process_yaml import get_yaml_data
9+
from .process_yaml import convert_yaml_to_json
10+
11+
__all__ = ['get_yaml_data', 'convert_yaml_to_json']
12+
13+
# Version information
14+
__version__ = '0.1.0'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# yaml2json/cli.py
2+
"""
3+
Command-line interface for YAML to JSON conversion tool.
4+
"""
5+
6+
import sys
7+
from pathlib import Path
8+
from get_yaml_data.config import setup_configuration
9+
from get_yaml_data.process_yaml import convert_yaml_to_json
10+
11+
def main() -> None:
12+
"""
13+
Main CLI function that processes YAML files and generates JSON output.
14+
"""
15+
try:
16+
# Get configuration
17+
settings = setup_configuration()
18+
19+
# Convert YAML to JSON
20+
convert_yaml_to_json(
21+
basedir=settings['basedir'],
22+
base_url=settings['base_url'],
23+
output_file=settings['output_file'],
24+
publish=settings['publish']
25+
)
26+
27+
except Exception as e:
28+
sys.exit(f"Error during conversion process: {str(e)}")
29+
30+
if __name__ == "__main__":
31+
main()
File renamed without changes.

tools/yaml2x/yaml2json/yaml2json.py renamed to tools/yaml2x/get_yaml_data/get_yaml_data/process_yaml.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
# get_yaml_data.py
12
"""
2-
Main module for YAML to JSON conversion.
3+
Main module for YAML processing and conversion to JSON.
34
4-
This module orchestrates the conversion process, handling configuration,
5-
data processing, and output generation for accessibility guidelines.
5+
This module provides the core functionality for converting YAML files to JSON format,
6+
focusing on accessibility guidelines processing.
67
"""
78

89
import sys
910
import json
1011
from pathlib import Path
11-
from typing import Dict, Any
12-
sys.path.append(str(Path(__file__).resolve().parent.parent))
12+
from typing import Dict, Any, Optional
13+
sys.path.append(str(Path(__file__).resolve().parent.parent.parent))
1314

1415
from a11y_guidelines import setup_instances, InfoRef, Check
15-
import config, utils, rst_processor
16+
from .config import setup_configuration
17+
from . import utils
18+
from . import rst_processor
1619

1720
def get_yaml_data(basedir: Path, base_url: str, publish: bool = False) -> Dict[str, Any]:
1821
"""
@@ -21,6 +24,7 @@ def get_yaml_data(basedir: Path, base_url: str, publish: bool = False) -> Dict[s
2124
Args:
2225
basedir (Path): Base directory containing YAML files
2326
base_url (str): Base URL for links
27+
publish (bool): Flag to indicate if this is a publication build
2428
2529
Returns:
2630
Dict[str, Any]: Processed data including version info, checks, and conditions
@@ -61,23 +65,31 @@ def get_yaml_data(basedir: Path, base_url: str, publish: bool = False) -> Dict[s
6165
'checks': checks
6266
}
6367

64-
def main() -> None:
68+
def convert_yaml_to_json(
69+
basedir: Path,
70+
base_url: str,
71+
output_file: Path,
72+
publish: bool = False
73+
) -> None:
6574
"""
66-
Main CLI function that processes YAML files and generates JSON output.
75+
Convert YAML files to JSON and write to specified output file.
76+
77+
Args:
78+
basedir (Path): Base directory containing YAML files
79+
base_url (str): Base URL for links
80+
output_file (Path): Path to output JSON file
81+
publish (bool): Flag to indicate if this is a publication build
82+
83+
Raises:
84+
Exception: If there's an error during the conversion process
6785
"""
6886
try:
69-
# Get configuration
70-
settings: Dict[str, Any] = config.setup_configuration()
71-
7287
# Process YAML data
73-
output_data = get_yaml_data(settings['basedir'], settings['base_url'], settings['publish'])
88+
output_data = get_yaml_data(basedir, base_url, publish)
7489

7590
# Write to JSON file
76-
with open(settings['output_file'], mode="w", encoding="utf-8", newline="\n") as f:
91+
with open(output_file, mode="w", encoding="utf-8", newline="\n") as f:
7792
json.dump(output_data, f, indent=2, ensure_ascii=False)
7893

7994
except Exception as e:
80-
sys.exit(f"Error during conversion process: {str(e)}")
81-
82-
if __name__ == "__main__":
83-
main()
95+
raise Exception(f"Error during conversion process: {str(e)}")
File renamed without changes.
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "get_yaml_data"
7+
version = "0.1.0"
8+
description = "A module to process YAML data"
9+
authors = [
10+
{name = "Masafumi NAKANE", email = "[email protected]"}
11+
]
12+
requires-python = ">=3.8"
13+
14+
[project.scripts]
15+
yaml2json = "get_yaml_data.cli:main"
16+
17+
[tool.setuptools]
18+
packages = { find = {} }

tools/yaml2x/yaml2json/__init__.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

tools/yaml2x/yaml2sheet/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config.*
2+
!config.*.sample

0 commit comments

Comments
 (0)