Skip to content

Commit

Permalink
[setup.py,cdd/{class_/emit.py,compound/doctrans_utils.py,function/uti…
Browse files Browse the repository at this point in the history
…ls/emit_utils.py,function/utils/parse_utils.py,shared/ast_utils.py,shared/defaults_utils.py,shared/docstring_parsers.py,sqlalchemy/utils/parse_utils.py,tests/test_docstring/test_parse_docstring_utils.py,tests/test_shared/test_ast_utils.py}] Increase test coverage ; [cdd/__init__.py] Bump version
  • Loading branch information
SamuelMarks committed Mar 15, 2024
1 parent 8720f1b commit 8d83ccb
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 54 deletions.
2 changes: 1 addition & 1 deletion cdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from logging import getLogger as get_logger

__author__ = "Samuel Marks" # type: str
__version__ = "0.0.99rc34" # type: str
__version__ = "0.0.99rc35" # type: str
__description__ = (
"Open API to/fro routes, models, and tests. "
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."
Expand Down
4 changes: 2 additions & 2 deletions cdd/class_/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import cdd.shared.ast_utils
from cdd.class_.utils.emit_utils import RewriteName
from cdd.docstring.emit import docstring
from cdd.function.utils.emit_utils import _make_call_meth
from cdd.function.utils.emit_utils import make_call_meth
from cdd.shared.pure_utils import PY_GTE_3_8, PY_GTE_3_9, rpartial

if PY_GTE_3_9:
Expand Down Expand Up @@ -170,7 +170,7 @@ def class_(
if len(internal_body) == 1
and isinstance(internal_body[0], FunctionDef)
and internal_body[0].name == "__call__"
else _make_call_meth(
else make_call_meth(
internal_body,
(
returns["return_type"]["default"]
Expand Down
3 changes: 2 additions & 1 deletion cdd/compound/doctrans_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from ast import (
AST,
AnnAssign,
Assign,
AsyncFunctionDef,
Expand Down Expand Up @@ -374,7 +375,7 @@ def doctransify_cst(cst_list, node):
if not is_func:
continue

cur_ast_node = ast_parse(
cur_ast_node: AST = ast_parse(
reindent_block_with_pass_body(cst_list[cst_idx].value),
skip_annotate=True,
skip_docstring_remit=True,
Expand Down
4 changes: 2 additions & 2 deletions cdd/function/utils/emit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)


def _make_call_meth(body, return_type, param_names, docstring_format, word_wrap):
def make_call_meth(body, return_type, param_names, docstring_format, word_wrap):
"""
Construct a `__call__` method from the provided `body`
Expand Down Expand Up @@ -115,4 +115,4 @@ def _make_call_meth(body, return_type, param_names, docstring_format, word_wrap)
)


__all__ = ["_make_call_meth"] # type: list[str]
__all__ = ["make_call_meth"] # type: list[str]
5 changes: 2 additions & 3 deletions cdd/function/utils/parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from cdd.shared.pure_utils import PY_GTE_3_8, rpartial

if PY_GTE_3_8:
from cdd.shared.pure_utils import FakeConstant
from cdd.shared.pure_utils import FakeConstant as Str

Num = Str = FakeConstant
del FakeConstant
Num = Str
else:
from ast import Num, Str

Expand Down
5 changes: 2 additions & 3 deletions cdd/shared/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,9 @@
FALLBACK_ARGPARSE_TYP = Name("str", Load(), lineno=None, col_offset=None)

if PY_GTE_3_8:
from cdd.shared.pure_utils import FakeConstant
from cdd.shared.pure_utils import FakeConstant as Str

Bytes = NameConstant = Num = Str = FakeConstant
del FakeConstant
Bytes = NameConstant = Num = Str
else:
from ast import Bytes, NameConstant, Num, Str

Expand Down
3 changes: 1 addition & 2 deletions cdd/shared/defaults_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from typing import Dict

from cdd.shared.pure_utils import PY_GTE_3_8, PY_GTE_3_9
from cdd.shared.pure_utils import FakeConstant as Str
from cdd.shared.pure_utils import (
count_iter_items,
location_within,
Expand All @@ -24,7 +23,7 @@
from cdd.shared.types import IntermediateRepr

if PY_GTE_3_8:
pass
from cdd.shared.pure_utils import FakeConstant as Str
else:
from ast import Str

Expand Down
7 changes: 3 additions & 4 deletions cdd/shared/docstring_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
from typing_extensions import * # noqa: F401,F403
from typing_extensions import TypedDict
else:
from cdd.shared.pure_utils import FakeConstant

Bytes = NameConstant = Num = Str = FakeConstant
del FakeConstant
from typing import TypedDict

from cdd.shared.pure_utils import FakeConstant as Str

Bytes = NameConstant = Num = Str
if sys.version_info[:2] > (3, 8):
from collections.abc import Callable
else:
Expand Down
3 changes: 1 addition & 2 deletions cdd/sqlalchemy/utils/parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import cdd.shared.ast_utils
import cdd.shared.source_transformer
from cdd.shared.pure_utils import PY_GTE_3_8
from cdd.shared.pure_utils import FakeConstant as Str
from cdd.shared.pure_utils import append_to_dict, indent_all_but_first, rpartial, tab

if PY_GTE_3_8:
pass
from cdd.shared.pure_utils import FakeConstant as Str
else:
from ast import Str

Expand Down
1 change: 1 addition & 0 deletions cdd/tests/test_docstring/test_parse_docstring_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_parse_adhoc_doc_for_typ(self) -> None:
),
("List[str]", "List of string."),
("Mapping[str, object]", "Dictionary of `{str: object}` pairs."),
(None, ""),
),
),
maxlen=0,
Expand Down
5 changes: 2 additions & 3 deletions cdd/tests/test_shared/test_ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@
from cdd.tests.utils_for_tests import inspectable_compile, run_ast_test, unittest_main

if PY_GTE_3_8:
from cdd.shared.pure_utils import FakeConstant
from cdd.shared.pure_utils import FakeConstant as Str

Bytes = NameConstant = Num = Str = FakeConstant
del FakeConstant
Bytes = NameConstant = Num = Str
else:
from ast import NameConstant, Num, Str

Expand Down
70 changes: 39 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,49 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
"/usr",
"/usr/local",
)
if prefix is None:
if standard_lib:
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
else:
prefix = plat_specific and EXEC_PREFIX or PREFIX

if os.name == "posix":
if plat_specific or standard_lib:
prefix = (
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
if standard_lib
else (EXEC_PREFIX or PREFIX)
)

class DistutilsPlatformError(Exception):
"""DistutilsPlatformError"""

assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
"I don't know where Python installs its library "
"on platform '{}'".format(os.name)
)
return (
(
# plat_specific or standard_lib:
# Platform-specific modules (any module from a non-pure-Python
# module distribution) or standard Python library modules.
libdir = sys.platlibdir
else:
# else:
# Pure Python
libdir = "lib"
libpython = os.path.join(prefix, libdir, "python" + get_python_version())
if standard_lib:
return libpython
elif is_default_prefix and not is_virtual_environment():
return os.path.join(prefix, "lib", "python3", "dist-packages")
else:
return os.path.join(libpython, "site-packages")
elif os.name == "nt":
if standard_lib:
return os.path.join(prefix, "Lib")
else:
return os.path.join(prefix, "Lib", "site-packages")
else:

class DistutilsPlatformError(Exception):
"""DistutilsPlatformError"""

raise DistutilsPlatformError(
"I don't know where Python installs its library "
"on platform '%s'" % os.name
lambda libpython: (
libpython
if standard_lib
else (
os.path.join(prefix, "lib", "python3", "dist-packages")
if is_default_prefix and not is_virtual_environment()
else os.path.join(libpython, "site-packages")
)
)
)(
os.path.join(
prefix,
sys.platlibdir if plat_specific or standard_lib else "lib",
"python" + get_python_version(),
)
)
if os.name == "posix"
else (
os.path.join(prefix, "Lib")
if standard_lib
else os.path.join(prefix, "Lib", "site-packages")
)
)

else:
from ast import Str
Expand Down

0 comments on commit 8d83ccb

Please sign in to comment.