Skip to content

Commit dbfb238

Browse files
committed
[mkdocs.yml,docs] Prepare to generate doc site ; [cdd/shared/defaults_utils.py] Fix default handling for doc site ; [cdd/tests/test_compound/test_doctrans_utils.py] Test new default handling ; [*.py] Run with latest black
1 parent 3f0e13f commit dbfb238

39 files changed

+262
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,4 @@ dmypy.json
151151

152152
# Docs
153153
_docs
154+
reports

LICENSE-APACHE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2020–2023 Samuel Marks (for Offscale.io)
190+
Copyright 2020–2025 Samuel Marks (for Offscale.io)
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2020–2023 Samuel Marks (for Offscale.io)
1+
Copyright 2020–2025 Samuel Marks (for Offscale.io)
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

cdd/compound/exmod_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Exmod utils """
1+
"""Exmod utils"""
22

33
import sys
44
from ast import AST, Assign, Expr, ImportFrom, List, Load, Module, Name, Store, alias

cdd/shared/defaults_utils.py

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,24 @@ def extract_default(
175175

176176
default = default.strip(" \t`")
177177

178+
if default.count('"') & 1:
179+
default = default.strip('"')
180+
if default.count("'") & 1:
181+
default = default.strip("'")
182+
183+
# Correct for parsing errors where a quote is captured at the start or end, but not both
184+
if len(default) > 0:
185+
if default.count('"') == 1 and default.count("'") == 0:
186+
if default.startswith('"'):
187+
default = default + '"'
188+
elif default.endswith('"'):
189+
default = '"' + default
190+
elif default.count("'") == 1 and default.count('"') == 0:
191+
if default.startswith("'"):
192+
default = default + "'"
193+
elif default.endswith("'"):
194+
default = "'" + default
195+
178196
return _parse_out_default_and_doc(
179197
_start_idx,
180198
start_rest_offset,
@@ -228,28 +246,35 @@ def _parse_out_default_and_doc(
228246
:rtype: Tuple[str, Optional[str]]
229247
"""
230248
if typ is not None and typ in simple_types and default not in none_types:
231-
lit = (
232-
ast.AST()
233-
if typ != "str"
234-
and any(
235-
map(
236-
partial(contains, frozenset(("*", "^", "&", "|", "$", "@", "!"))),
237-
default,
249+
if typ == "str":
250+
from cdd.shared.pure_utils import unquote
251+
252+
default = unquote(default)
253+
else:
254+
lit = (
255+
ast.AST()
256+
if any(
257+
map(
258+
partial(
259+
contains, frozenset(("*", "^", "&", "|", "$", "@", "!"))
260+
),
261+
default,
262+
)
238263
)
264+
else literal_eval("({default})".format(default=default))
265+
)
266+
default = (
267+
"```{default}```".format(default=default)
268+
if isinstance(lit, ast.AST)
269+
else {
270+
"bool": bool,
271+
"int": int,
272+
"float": float,
273+
"complex": complex,
274+
}[
275+
typ
276+
](lit)
239277
)
240-
else literal_eval("({default})".format(default=default))
241-
)
242-
default = (
243-
"```{default}```".format(default=default)
244-
if isinstance(lit, ast.AST)
245-
else {
246-
"bool": bool,
247-
"int": int,
248-
"float": float,
249-
"complex": complex,
250-
"str": str,
251-
}[typ](lit)
252-
)
253278
elif default.isdecimal():
254279
default = int(default)
255280
elif default in frozenset(("True", "False")):
@@ -261,8 +286,15 @@ def _parse_out_default_and_doc(
261286
return line, default
262287
else:
263288
stop_tokens = frozenset((" ", "\t", "\n", "\n", "."))
264-
end = line[: _start_idx - 1]
265-
extra_offset = int(end[-1] in frozenset((" ", "\t", "\n", "\n")) if end else 0)
289+
if _start_idx == 0:
290+
fst = ""
291+
extra_offset = 0
292+
else:
293+
end = line[: _start_idx - 1]
294+
extra_offset = int(
295+
end[-1] in frozenset((" ", "\t", "\n", "\n")) if end else 0
296+
)
297+
fst = line[: _start_idx - 1 - extra_offset]
266298

267299
if rstrip_default:
268300
offset: int = count_iter_items(
@@ -273,7 +305,6 @@ def _parse_out_default_and_doc(
273305
)
274306
start_rest_offset += offset
275307

276-
fst = line[: _start_idx - 1 - extra_offset]
277308
rest = line[
278309
start_rest_offset : (
279310
(-extra_offset if extra_offset > 0 else None)

cdd/tests/mocks/eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" eval.py for testing with `sync_properties` """
1+
"""eval.py for testing with `sync_properties`"""
22

33
import sys
44

cdd/tests/mocks/exmod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Exmod mocks """
1+
"""Exmod mocks"""
22

33
from ast import Assign, ImportFrom, List, Load, Module, Name, Store, alias
44
from itertools import chain

cdd/tests/test_cli/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Tests for CLI (__main__.py) """
1+
"""Tests for CLI (__main__.py)"""
22

33
import os
44
from argparse import ArgumentParser

cdd/tests/test_cli/test_cli_doctrans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Tests for CLI doctrans subparser (__main__.py) """
1+
"""Tests for CLI doctrans subparser (__main__.py)"""
22

33
from os import path
44
from tempfile import TemporaryDirectory

cdd/tests/test_cli/test_cli_exmod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Tests for CLI exmod subparser (__main__.py) """
1+
"""Tests for CLI exmod subparser (__main__.py)"""
22

33
from unittest import TestCase
44
from unittest.mock import MagicMock, patch

0 commit comments

Comments
 (0)