Skip to content

Commit

Permalink
[cdd/compound/exmod_utils.py] Comment out unused function ; [cdd/test…
Browse files Browse the repository at this point in the history
…s/test_compound/test_exmod.py] `test_exmod_single_folder_early_exit` ; [cdd/__init__.py] Bump version ; [cdd/tests/test_shared/test_pkg_utils.py] `test_get_python_lib` add debug for windows
  • Loading branch information
SamuelMarks committed Mar 16, 2024
1 parent 50d14a9 commit e92a2d9
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 39 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.99rc42" # type: str
__version__ = "0.0.99rc43" # type: str
__description__ = (
"Open API to/fro routes, models, and tests. "
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."
Expand Down
70 changes: 35 additions & 35 deletions cdd/compound/exmod_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ast import walk as ast_walk
from collections import OrderedDict, defaultdict, deque
from functools import partial
from inspect import getfile, ismodule
from inspect import getfile
from itertools import chain
from operator import attrgetter, eq
from os import environ, extsep, makedirs, path
Expand Down Expand Up @@ -156,40 +156,40 @@ def get_module_contents(obj, module_root_dir, current_module=None, _result={}):
return _result


def _process_module_contents(_result, current_module, module_root_dir, name, symbol):
"""
Internal function to get the symbol and store it with a fully-qualified name in `_result`
:param current_module: The current module
:type current_module: ```Optional[str]```
:param module_root_dir: Root of module
:type module_root_dir: ```str```
:param name: Name—first value—from `dir(module)`
:type name: ```str```
:param symbol: Symbol—second value—from `dir(module)`
:type symbol: ```type```
"""
fq: str = "{current_module}.{name}".format(current_module=current_module, name=name)
try:
symbol_location: Optional[str] = getfile(symbol)
except TypeError:
symbol_location: Optional[str] = None
if symbol_location is not None and symbol_location.startswith(module_root_dir):
if isinstance(symbol, type):
_result[fq] = symbol
elif (
current_module != getattr(symbol, "__name__", current_module)
and ismodule(symbol)
and fq not in _result
):
get_module_contents(
symbol,
module_root_dir=module_root_dir,
current_module=symbol.__name__,
)
# def _process_module_contents(_result, current_module, module_root_dir, name, symbol):
# """
# Internal function to get the symbol and store it with a fully-qualified name in `_result`
#
# :param current_module: The current module
# :type current_module: ```Optional[str]```
#
# :param module_root_dir: Root of module
# :type module_root_dir: ```str```
#
# :param name: Name—first value—from `dir(module)`
# :type name: ```str```
#
# :param symbol: Symbol—second value—from `dir(module)`
# :type symbol: ```type```
# """
# fq: str = "{current_module}.{name}".format(current_module=current_module, name=name)
# try:
# symbol_location: Optional[str] = getfile(symbol)
# except TypeError:
# symbol_location: Optional[str] = None
# if symbol_location is not None and symbol_location.startswith(module_root_dir):
# if isinstance(symbol, type):
# _result[fq] = symbol
# elif (
# current_module != getattr(symbol, "__name__", current_module)
# and ismodule(symbol)
# and fq not in _result
# ):
# get_module_contents(
# symbol,
# module_root_dir=module_root_dir,
# current_module=symbol.__name__,
# )


def emit_file_on_hierarchy(
Expand Down
26 changes: 25 additions & 1 deletion cdd/tests/test_compound/test_exmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from unittest.mock import patch

import cdd.class_.parse
from cdd.compound.exmod import exmod
from cdd.compound.exmod import exmod, exmod_single_folder
from cdd.shared.ast_utils import maybe_type_comment, set_value
from cdd.shared.pkg_utils import relative_filename
from cdd.shared.pure_utils import (
Expand Down Expand Up @@ -429,6 +429,30 @@ def test_exmod_dry_run(self) -> None:
finally:
self._pip(["uninstall", "-y", self.package_root_name])

def test_exmod_single_folder_early_exit(self):
"""
Tests that `exmod_single_folder` exits early
"""
self.assertIsNone(
exmod_single_folder(
emit_name="sqlalchemy",
module="mod",
blacklist=["tmp.mod"],
whitelist=[],
output_directory="tmp",
first_output_directory="tmp",
mock_imports=True,
no_word_wrap=True,
dry_run=False,
module_root_dir="tmp",
module_root="tmp",
module_name="mod",
new_module_name="mod_new",
filesystem_layout="as_input",
extra_modules_to_all=None,
)
)

def create_and_install_pkg(self, root):
"""
Create and install the pacakge
Expand Down
17 changes: 15 additions & 2 deletions cdd/tests/test_shared/test_pkg_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
""" Tests for pkg utils """

from functools import partial
from operator import eq
from os import path
from site import getsitepackages
from unittest import TestCase

from cdd.shared.pkg_utils import get_python_lib, relative_filename
from cdd.shared.pure_utils import rpartial
from cdd.shared.pure_utils import rpartial, pp
from cdd.tests.utils_for_tests import unittest_main


Expand All @@ -23,6 +22,20 @@ def test_get_python_lib(self) -> None:
"""Tests that `get_python_lib` works"""
python_lib: str = get_python_lib()
site_packages: str = getsitepackages()[0]
two_dirs_above: str = path.dirname(path.dirname(site_packages))
pp(
{
"python_lib": python_lib,
"two_dirs_above": two_dirs_above,
"site_packages": site_packages,
'path.join(two_dir_above, "Lib", "site-packages")': path.join(
two_dirs_above, "Lib", "site-packages"
),
'path.join(two_dir_above, "python3", "dist-packages")': path.join(
two_dirs_above, "python3", "dist-packages"
),
}
)
site_packages: str = next(
filter(
rpartial(eq, python_lib),
Expand Down

0 comments on commit e92a2d9

Please sign in to comment.