Skip to content

Commit

Permalink
fix processing additional folders
Browse files Browse the repository at this point in the history
- test(static dependencies): remove tool.pipenv-unlock section
- fix(backend_abc): from pyproject.toml process additional folders
- chore: turn all is_module_debug flags off
- chore(cli_unlock): comment out __debug__ blocks
  • Loading branch information
msftcangoblowm committed Sep 11, 2024
1 parent bb23341 commit cdb411c
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 63 deletions.
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ Changelog

.. scriv-start-here
.. _changes_1-7-2:

Version 1.7.2 — 2024-09-11
--------------------------

- test(static dependencies): remove tool.pipenv-unlock section
- fix(backend_abc): from pyproject.toml process additional folders
- chore: turn all is_module_debug flags off
- chore(cli_unlock): comment out __debug__ blocks

.. _changes_1-7-1:

Version 1.7.1 — 2024-09-10
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# @@@ editable
copyright = "2024–2024, Dave Faulkmore"
# The short X.Y.Z version.
version = "1.7.1"
version = "1.7.2"
# The full version, including alpha/beta/rc tags.
release = "1.7.1"
release = "1.7.2"
# The date of release, in "monthname day, year" format.
release_date = "September 10, 2024"
release_date = "September 11, 2024"
# @@@ end

v = parse(release)
Expand Down
4 changes: 2 additions & 2 deletions src/drain_swamp/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '1.7.1'
__version_tuple__ = version_tuple = (1, 7, 1)
__version__ = version = '1.7.2'
__version_tuple__ = version_tuple = (1, 7, 2)
122 changes: 99 additions & 23 deletions src/drain_swamp/backend_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

_logger = logging.getLogger(f"{g_app_name}.backend_abc")

is_module_debug = True
is_module_debug = False

# taken from pyproject.toml
entrypoint_name = "pipenv-unlock" # noqa: F401
Expand Down Expand Up @@ -271,6 +271,72 @@ def get_optionals_pyproject_toml(
pass


def get_additional_folders_pyproject_toml(
d_pyproject_toml,
path_config,
implied_folders,
is_bypass=False,
):
"""From ``pyproject.toml`` [tool.pipenv-unlock] get ``folders`` value.
Which is a :code:`list[str]`.
:param d_pyproject_toml: pyproject.toml dict
:type d_pyproject_toml: dict[str, typing.Any]
:param path_config: absolute folder path
:type path_config: pathlib.Path
:param implied_folders: Relative path of known folders containing ``.in``
:type implied_folders: set[pathlib.Path]
:param is_bypass: Default False. True checks if folder exists
:type is_bypass: bool | None
:returns: set of **relative paths** to folders containing ``.in`` files
:rtype set[pathlib.Path]
"""
if is_bypass is None or not isinstance(is_bypass, bool):
is_bypass = False

ret = set()
d_tool = d_pyproject_toml.get("tool", {}).get(entrypoint_name, {})
for key, mixed_blob in d_tool.items():
is_folders = (
key == "folders" and mixed_blob is not None and isinstance(mixed_blob, list)
)
if is_module_debug: # pragma: no cover
_logger.info(f"is_folders: {is_folders}")
else: # pragma: no cover
pass

if is_folders:
for folder_relpath in mixed_blob:
is_not_empty = (
folder_relpath is not None
and isinstance(folder_relpath, str)
and len(folder_relpath.strip()) != 0
)
if is_not_empty:
relpath_folder = Path(folder_relpath)
is_not_in_implied = relpath_folder not in implied_folders
path_abs = resolve_joinpath(path_config, folder_relpath)
if is_bypass is True and is_not_in_implied:
ret.add(relpath_folder)
elif is_bypass is False and is_not_in_implied:
is_dir = path_abs.exists() and path_abs.is_dir()
if is_dir:
ret.add(relpath_folder)
else: # pragma: no cover
pass
else: # pragma: no cover
# Not an additional. In implied folders
pass
else: # pragma: no cover
pass
else: # pragma: no cover
# in pyproject.toml [tool.pipenv-unlock], no folders key nor list[str] value
pass

return ret


def get_required_pyproject_toml(
d_pyproject_toml,
path_config,
Expand Down Expand Up @@ -465,7 +531,7 @@ def folders_implied_init(
return set_folders_implied


def folders_additional_init(
def folders_additional_cli(
parent_dir,
folders_implied,
additional_folders=(),
Expand All @@ -487,40 +553,37 @@ def folders_additional_init(
[tool.setuptools.dynamic]
# @@@ editable little_shop_of_horrors_shrine_candles
dependencies = { file = ["requirements/prod.lock"] }
optional-dependencies.pip = { file = ["requirements/pip.lock"] }
optional-dependencies.pip_tools = { file = ["requirements/pip-tools.lock"] }
optional-dependencies.dev = { file = ["requirements/dev.lock"] }
optional-dependencies.manage = { file = ["requirements/manage.lock"] }
optional-dependencies.docs = { file = ["docs/requirements.lock"] }
dependencies = { file = ['requirements/prod.lock'] }
optional-dependencies.pip = { file = ['requirements/pip.lock'] }
optional-dependencies.pip_tools = { file = ['requirements/pip-tools.lock'] }
optional-dependencies.dev = { file = ['requirements/dev.lock'] }
optional-dependencies.manage = { file = ['requirements/manage.lock'] }
optional-dependencies.docs = { file = ['docs/requirements.lock'] }
# @@@ end
[tool.pipenv-unlock]
folders = [
"docs",
"requirements",
"ci",
'ci',
]
required = { target = "prod", relative_path = "requirements/prod.in" }
required = { target = "prod", relative_path = 'requirements/prod.in' }
optionals = [
{ target = "pip", relative_path = "requirements/pip.in" },
{ target = "pip_tools", relative_path = "requirements/pip-tools.in" },
{ target = "dev", relative_path = "requirements/dev.in" },
{ target = "manage", relative_path = "requirements/manage.in" },
{ target = "docs", relative_path = "docs/requirements.in" },
{ target = "pip", relative_path = 'requirements/pip.in' },
{ target = "pip_tools", relative_path = 'requirements/pip-tools.in' },
{ target = "dev", relative_path = 'requirements/dev.in' },
{ target = "manage", relative_path = 'requirements/manage.in' },
{ target = "docs", relative_path = 'docs/requirements.in' },
]
The implied folders are determined from:
- tool.pipenv-unlock.required
- tool.pipenv-unlock.optionals
In this case, the implied folders are: :code:`{"requirements", "docs"}`
In this case, the implied folders are: :code:`{'requirements', 'docs'}`
tool.pipenv-unlock.folders contains the additional folder: :code:`{"ci"}`
tool.pipenv-unlock.folders contains the additional folder: :code:`{'ci'}`
:param parent_dir: absolute path to parent folder
:type parent_dir: pathlib.Path
Expand Down Expand Up @@ -778,12 +841,23 @@ def load(
required=required,
)

# _folders_additional
self._folders_additional = folders_additional_init(
# folders_additional -- pyproject.toml
set_folders_additional_0 = get_additional_folders_pyproject_toml(
d_pyproject_toml,
self.parent_dir,
self.folders_implied,
)
# _folders_additional -- cli
set_folders_additional_1 = folders_additional_cli(
self.parent_dir,
self.folders_implied,
additional_folders=additional_folders,
)
# combine two sets
self._folders_additional = set_folders_additional_0.union(
set_folders_additional_1,
)

# Annoying to make a unittest just for this property
assert self.folders_additional == self._folders_additional

Expand Down Expand Up @@ -1056,7 +1130,9 @@ def __repr__(self) -> str:
else:
# t_required is None when pyproject.toml contains static dependencies
# Remove <comma><space> token
ret = ret[:-2]
ret += "required=None"
# ret = ret[:-2]
pass

ret += ">"

Expand Down
8 changes: 7 additions & 1 deletion src/drain_swamp/backend_abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ def folders_implied_init(
optionals: dict[str, Path],
required: tuple[str, Path] | None = None,
) -> set[Path]: ...
def folders_additional_init(
def get_additional_folders_pyproject_toml(
d_pyproject_toml: dict[str, Any],
path_config: Path,
implied_folders: set[Path],
is_bypass: bool | None = False,
) -> set[Path]: ...
def folders_additional_cli(
parent_dir: Path,
folders_implied: set[Path],
additional_folders: tuple[Path] = ...,
Expand Down
11 changes: 10 additions & 1 deletion src/drain_swamp/cli_unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,6 @@ def create_links(path, is_set_lock, snippet_co):
:type snippet_co: str | None
"""
modpath = "drain_swamp.cli_unlock.create_links"
# resolve causing conversion into a str. Should be Path
if isinstance(path, str): # pragma: no cover
path = Path(path)
Expand All @@ -770,10 +769,14 @@ def create_links(path, is_set_lock, snippet_co):
# print logging to stdout if __debug__ and not test suite
set_debug_mode(is_ci=True)

"""
modpath = "drain_swamp.cli_unlock.create_links"
if __debug__: # pragma: no cover
_logger.info(f"{modpath} path: {path!r}")
else: # pragma: no cover
pass
"""
pass

try:
inst = BackendType(path)
Expand All @@ -790,10 +793,13 @@ def create_links(path, is_set_lock, snippet_co):
click.secho(str(e), fg="red", err=True)
sys.exit(4)

"""
if __debug__: # pragma: no cover
_logger.info(f"{modpath} inst: {inst.__repr__()}")
else: # pragma: no cover
pass
"""
pass

"""Create the .lnk (lock dependency state) symlinks
This normally occurs during package build time
Expand All @@ -818,10 +824,13 @@ def create_links(path, is_set_lock, snippet_co):
click.secho(msg_exc, fg="red", err=True)
sys.exit(7)

"""
if __debug__: # pragma: no cover
_logger.info(f"{modpath} update snippet...")
else: # pragma: no cover
pass
"""
pass

path_config = inst.path_config
err_or_none = snippet_replace_suffixes(path_config, snippet_co=snippet_co)
Expand Down
2 changes: 1 addition & 1 deletion src/drain_swamp/parser_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
__all__ = ("TomlParser",)

_logger = logging.getLogger(f"{g_app_name}.parser_in")
is_module_debug = True
is_module_debug = False


class TomlParser:
Expand Down
2 changes: 1 addition & 1 deletion src/drain_swamp/snip.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

mod_dotted_path = f"{g_app_name}.snip"
_logger = logging.getLogger()
is_module_debug = True
is_module_debug = False


class ReplaceResult(Enum):
Expand Down
2 changes: 1 addition & 1 deletion src/drain_swamp/snippet_pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"SNIPPET_VALIDATE_FAIL",
"snippet_replace_suffixes",
)
is_module_debug = True
is_module_debug = False
_logger = logging.getLogger(f"{g_app_name}.snippet_pyproject_toml")


Expand Down
13 changes: 0 additions & 13 deletions tests/_bad_files/static_dependencies.pyproject_toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,3 @@ include = ["complete_awesome_perfect*"]

[tool.drain-swamp]
copyright_start_year = 2024

[tool.pipenv-unlock]
folders = [
'ci',
]

required = { target = "prod", relative_path = 'requirements/prod.in' }

# underscore: hyphen
optionals = [
{ target = "pip", relative_path = 'requirements/pip.in' },
{ target = "manage", relative_path = 'requirements/manage.in' },
]
Loading

0 comments on commit cdb411c

Please sign in to comment.