Skip to content

Commit 1a568d9

Browse files
committed
Silent Exit
1 parent 0285618 commit 1a568d9

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

cppython/build/prepare.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ def prepare(self) -> BuildPreparationResult:
7878

7979
pyproject_data = self._load_pyproject()
8080

81-
# Check if CPPython is configured
82-
tool_data = pyproject_data.get('tool', {})
83-
if 'cppython' not in tool_data:
84-
self.logger.info('CPPython: No [tool.cppython] configuration found, skipping preparation')
85-
return BuildPreparationResult()
86-
8781
# Get version from pyproject if available
8882
project_data = pyproject_data.get('project', {})
8983
version = project_data.get('version')

cppython/plugins/pdm/plugin.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,21 @@ def on_post_install(self, project: Project, dry_run: bool, **_kwargs: Any) -> No
5050
_kwargs: Sink for unknown arguments
5151
"""
5252
root = project.root.absolute()
53+
pdm_pyproject = project.pyproject.open_for_read()
5354

5455
# Attach configuration for CPPythonPlugin callbacks
5556
version = project.pyproject.metadata.get('version')
5657
verbosity = project.core.ui.verbosity
5758

5859
project_configuration = ProjectConfiguration(project_root=root, verbosity=verbosity, version=version)
5960

60-
self.logger.info("CPPython: Entered 'on_post_install'")
61-
62-
if (pdm_pyproject := project.pyproject.open_for_read()) is None:
63-
self.logger.info('CPPython: Project data was not available')
64-
return
65-
66-
cppython_project = CPPythonProject(project_configuration, self, pdm_pyproject)
61+
try:
62+
cppython_project = CPPythonProject(project_configuration, self, pdm_pyproject)
6763

68-
if not dry_run:
69-
cppython_project.install()
64+
if not dry_run:
65+
cppython_project.install()
66+
except Exception:
67+
self.logger.debug('CPPython: Error during post-install hook', exc_info=True)
7068

7169

7270
class CPPythonCommand(BaseCommand):

cppython/project.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def __init__(
2828
self._interface = interface
2929
self.logger = logging.getLogger('cppython')
3030

31+
# Early exit: if no CPPython configuration table, do nothing silently
32+
tool_data = pyproject_data.get('tool')
33+
if not tool_data or not isinstance(tool_data, dict) or not tool_data.get('cppython'):
34+
return
35+
3136
builder = Builder(project_configuration, self.logger)
3237

3338
self.logger.info('Initializing project')

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ select = [
8888
[tool.ruff.lint.pydocstyle]
8989
convention = "google"
9090

91+
[tool.ruff.lint.per-file-ignores]
92+
"cppython/console/entry.py" = ["PT"] # CLI commands, not pytest tests
93+
9194
[tool.ruff.format]
9295
docstring-code-format = true
9396
indent-style = "space"

tests/unit/test_project.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tomllib
55
from importlib import metadata
66
from pathlib import Path
7+
from typing import Any
78

89
import pytest
910
from pytest_mock import MockerFixture
@@ -46,6 +47,31 @@ def test_self_construction(request: pytest.FixtureRequest) -> None:
4647
# Doesn't have the cppython table
4748
assert not project.enabled
4849

50+
@staticmethod
51+
def test_missing_tool_table_raw_dict(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
52+
"""Constructing Project with a raw dict lacking tool.cppython should produce zero log output.
53+
54+
This simulates input from a host tool like PDM that passes raw pyproject data
55+
rather than a model_dump() result.
56+
57+
Args:
58+
tmp_path: Temporary directory for dummy data
59+
caplog: Pytest fixture for capturing logs
60+
"""
61+
project_configuration = ProjectConfiguration(project_root=tmp_path, version=None)
62+
interface = MockInterface()
63+
64+
# Raw dict as PDM would provide — no tool table at all
65+
raw_data: dict[str, Any] = {'project': {'name': 'some-other-project', 'version': '1.0.0'}}
66+
67+
with caplog.at_level(logging.DEBUG):
68+
project = Project(project_configuration, interface, raw_data)
69+
70+
# Absolutely no log output for projects without CPPython configuration
71+
assert len(caplog.records) == 0
72+
73+
assert not project.enabled
74+
4975
@staticmethod
5076
def test_missing_tool_table(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
5177
"""The project type should be constructable without the tool table

0 commit comments

Comments
 (0)