Skip to content

Commit 8654568

Browse files
committed
[cdd/{emit,parse}.py -> cdd/{emit,parser}/*.py] Expand these two files into two modules ; [.github/workflows/main.yml] Upgrade versions of dependent actions ; [{README.md,.github/workflows/main.yml}] Reflect Python 3.11 release ; [cdd/__init__.py] Bump version ; [cdd/**.py] Use new parser and emitter locations throughout codebase (including use of import_module in cdd/gen.py)
1 parent 90b2402 commit 8654568

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2728
-2465
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ${{ matrix.os.runs-on }}
1616
strategy:
1717
matrix:
18-
python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.11.0-alpha - 3.11.0']
18+
python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.11']
1919
os:
2020
- name: Linux
2121
runs-on: ubuntu-latest
@@ -27,9 +27,9 @@ jobs:
2727
runs-on: macos-latest
2828
python_platform: darwin
2929
steps:
30-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v3
3131
- name: Set up Python ${{ matrix.python-version }}
32-
uses: actions/setup-python@v2
32+
uses: actions/setup-python@v4
3333
with:
3434
python-version: ${{ matrix.python-version }}
3535
architecture: x64

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cdd-python
22
==========
3-
![Python version range](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11.0rc2-blue.svg)
3+
![Python version range](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11-blue.svg)
44
![Python implementation](https://img.shields.io/badge/implementation-cpython-blue.svg)
55
[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)
66
[![Linting, testing, coverage, and release](https://github.com/offscale/cdd-python/workflows/Linting,%20testing,%20coverage,%20and%20release/badge.svg)](https://github.com/offscale/cdd-python/actions)

cdd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from logging import getLogger as get_logger
99

1010
__author__ = "Samuel Marks"
11-
__version__ = "0.0.84-beta"
11+
__version__ = "0.0.84"
1212
__description__ = (
1313
"Open API to/fro routes, models, and tests. "
1414
"Convert between docstrings, classes, methods, argparse, and SQLalchemy."

cdd/ast_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _generic_param2ast(param):
177177
"""
178178
name, _param = param
179179
del param
180-
from cdd.emitter_utils import ast_parse_fix
180+
from cdd.emit.emitter_utils import ast_parse_fix
181181

182182
annotation = ast_parse_fix(_param["typ"])
183183
value = set_value(None)
@@ -418,7 +418,7 @@ def _resolve_arg(action, choices, param, required, typ):
418418
elif _param["typ"] == "dict" or name.endswith("kwargs"):
419419
typ, required = "loads", not name.endswith("kwargs")
420420
elif _param["typ"]:
421-
from cdd.emitter_utils import ast_parse_fix
421+
from cdd.emit.emitter_utils import ast_parse_fix
422422

423423
parsed_type = ast_parse_fix(_param["typ"])
424424
for node in walk(parsed_type):

cdd/conformance.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
from operator import itemgetter
99
from os import path
1010

11-
from cdd import emit, parse
11+
import cdd.emit.argparse_function
12+
import cdd.emit.class_
13+
import cdd.emit.file
14+
import cdd.emit.function
1215
from cdd.ast_utils import RewriteAtQuery, cmp_ast, find_in_ast, get_function_type
1316
from cdd.pure_utils import pluralise, strip_split
1417
from cdd.source_transformer import ast_parse
@@ -83,9 +86,17 @@ def ground_truth(args, truth_file):
8386
:rtype: ```OrderedDict```
8487
"""
8588
arg2parse_emit_type = {
86-
"argparse_function": (parse.argparse_ast, emit.argparse_function, FunctionDef),
87-
"class": (parse.class_, emit.class_, ClassDef),
88-
"function": (parse.function, emit.function, FunctionDef),
89+
"argparse_function": (
90+
cdd.parse.argparse_function.argparse_ast,
91+
cdd.emit.argparse_function.argparse_function,
92+
FunctionDef,
93+
),
94+
"class": (cdd.parse.class_.class_, cdd.emit.class_.class_, ClassDef),
95+
"function": (
96+
cdd.parse.function.function,
97+
cdd.emit.function.function,
98+
FunctionDef,
99+
),
89100
}
90101

91102
parse_func, emit_func, type_wanted = arg2parse_emit_type[args.truth]
@@ -156,7 +167,7 @@ def _conform_filename(
156167
filename = path.realpath(path.expanduser(filename))
157168

158169
if not path.isfile(filename):
159-
emit.file(
170+
cdd.emit.file.file(
160171
emit_func(
161172
replacement_node_ir,
162173
emit_default_doc=False, # emit_func.__name__ == "class_"
@@ -177,7 +188,9 @@ def _conform_filename(
177188
**_default_options(node=original_node, search=search, type_wanted=type_wanted)()
178189
)
179190
if original_node is None:
180-
emit.file(replacement_node, filename=filename, mode="a", skip_black=False)
191+
cdd.emit.file.file(
192+
replacement_node, filename=filename, mode="a", skip_black=False
193+
)
181194
return filename, True
182195
assert len(search) > 0
183196

@@ -199,7 +212,7 @@ def _conform_filename(
199212
"modified" if rewrite_at_query.replaced else "unchanged", filename, sep="\t"
200213
)
201214
if rewrite_at_query.replaced:
202-
emit.file(parsed_ast, filename, mode="wt", skip_black=False)
215+
cdd.emit.file.file(parsed_ast, filename, mode="wt", skip_black=False)
203216

204217
replaced = rewrite_at_query.replaced
205218

cdd/docstring_parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Style,
2727
derive_docstring_format,
2828
)
29-
from cdd.emitter_utils import interpolate_defaults
29+
from cdd.emit.emitter_utils import interpolate_defaults
3030
from cdd.pure_utils import (
3131
code_quoted,
3232
count_iter_items,

cdd/doctrans_utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from copy import deepcopy
1818
from operator import attrgetter, eq
1919

20-
from cdd import emit, parse
20+
import cdd.emit.docstring
21+
import cdd.parse.docstring
22+
import cdd.parse.function
2123
from cdd.ast_cst_utils import (
2224
find_cst_at_ast,
2325
maybe_replace_doc_str_in_function_or_class,
@@ -36,7 +38,7 @@
3638
)
3739
from cdd.cst_utils import reindent_block_with_pass_body
3840
from cdd.docstring_parsers import parse_docstring
39-
from cdd.parser_utils import ir_merge
41+
from cdd.parse.parser_utils import ir_merge
4042
from cdd.pure_utils import PY_GTE_3_8, is_ir_empty, none_types, omit_whitespace
4143
from cdd.source_transformer import ast_parse
4244

@@ -223,7 +225,7 @@ def _get_ass_typ(self, node):
223225
(
224226
lambda doc_str: None
225227
if doc_str is None
226-
else parse.docstring(doc_str)
228+
else cdd.parse.docstring.docstring(doc_str)
227229
)(get_docstring(parent, clean=False))
228230
if isinstance(parent, (ClassDef, AsyncFunctionDef, FunctionDef))
229231
else {"params": OrderedDict()}
@@ -249,15 +251,15 @@ def _handle_function(self, node, original_doc_str):
249251
:rtype: ```Union[AsyncFunctionDef, FunctionDef]```
250252
"""
251253
ir = parse_docstring(original_doc_str)
252-
ir_merge(ir, parse.function(node))
254+
ir_merge(ir, cdd.parse.function.function(node))
253255
ir["name"] = node.name
254256
indent_level = max(
255257
len(node._location), 1
256258
) # function docstrings always have at least 1 indent level
257259
doc_str = (
258260
None
259261
if is_ir_empty(ir)
260-
else emit.docstring(
262+
else cdd.emit.docstring.docstring(
261263
ir,
262264
emit_types=not self.type_annotations,
263265
emit_default_doc=False,

0 commit comments

Comments
 (0)