Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions cppython/console/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,23 @@ def generate_project(self) -> Project:

@click.group()
@click.option("-v", "--verbose", count=True, help="Print additional output")
@click.option("--debug/--no-debug", default=False)
@pass_config
def cli(config: Configuration, verbose: int) -> None:
def cli(config: Configuration, verbose: int, debug: bool) -> None:
"""entry_point group for the CLI commands

Args:
config: The CLI configuration object
verbose: The verbosity level
debug: Debug mode
"""
config.configuration.verbosity = verbose
config.configuration.debug = debug


@cli.command()
@cli.command(name="info")
@pass_config
def info(config: Configuration) -> None:
def info_command(config: Configuration) -> None:
"""Prints project information

Args:
Expand All @@ -96,9 +99,22 @@ def info(config: Configuration) -> None:
config.logger.info("The SCM project version is: %s", version)


@cli.command()
@cli.command(name="list")
@pass_config
def install(config: Configuration) -> None:
def list_command(config: Configuration) -> None:
"""Prints project information

Args:
config: The CLI configuration object
"""

version = config.query_scm()
config.logger.info("The SCM project version is: %s", version)


@cli.command(name="install")
@pass_config
def install_command(config: Configuration) -> None:
"""Install API call

Args:
Expand All @@ -108,9 +124,9 @@ def install(config: Configuration) -> None:
project.install()


@cli.command()
@cli.command(name="update")
@pass_config
def update(config: Configuration) -> None:
def update_command(config: Configuration) -> None:
"""Update API call

Args:
Expand Down
61 changes: 36 additions & 25 deletions cppython/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cppython_core.exceptions import ConfigError, PluginError
from cppython_core.resolution import resolve_name
from cppython_core.schema import CoreData, Interface, ProjectConfiguration, PyProject
from pydantic import ValidationError

from cppython.builder import Builder
from cppython.schema import API
Expand All @@ -32,39 +33,49 @@ def __init__(

self.logger.info("Initializing project")

if (pyproject := PyProject(**pyproject_data)) is None:
raise ConfigError("PyProject data is not defined")
try:
if (pyproject := PyProject(**pyproject_data)) is None:
raise ConfigError("Table [project] is not defined")

if pyproject.tool is None:
raise ConfigError("Table [tool] is not defined")

if pyproject.tool is None:
raise ConfigError("Table [tool] is not defined")
if pyproject.tool.cppython is None:
raise ConfigError("Table [tool.cppython] is not defined")

if pyproject.tool.cppython is None:
raise ConfigError("Table [tool.cppython] is not defined")
builder = Builder(self.logger)

builder = Builder(self.logger)
self._core_data = builder.generate_core_data(configuration, pyproject.project, pyproject.tool.cppython)

self._core_data = builder.generate_core_data(configuration, pyproject.project, pyproject.tool.cppython)
raw_generator_plugins = builder.find_generators()
generator_plugins = builder.filter_plugins(
raw_generator_plugins,
self.core_data.project_data.pyproject_file.parent,
self.core_data.cppython_data.generator_name,
"Generator",
)

raw_generator_plugins = builder.find_generators()
generator_plugins = builder.filter_plugins(
raw_generator_plugins,
self.core_data.project_data.pyproject_file.parent,
self.core_data.cppython_data.generator_name,
"Generator",
)
raw_provider_plugins = builder.find_providers()
provider_plugins = builder.filter_plugins(
raw_provider_plugins,
self.core_data.project_data.pyproject_file.parent,
self.core_data.cppython_data.provider_name,
"Provider",
)

raw_provider_plugins = builder.find_providers()
provider_plugins = builder.filter_plugins(
raw_provider_plugins,
self.core_data.project_data.pyproject_file.parent,
self.core_data.cppython_data.provider_name,
"Provider",
)
generator_type, provider_type = builder.solve(generator_plugins, provider_plugins)

generator_type, provider_type = builder.solve(generator_plugins, provider_plugins)
self._generator = builder.create_generator(
self.core_data, pyproject.tool.cppython.generator, generator_type
)
self._provider = builder.create_provider(self.core_data, pyproject.tool.cppython.provider, provider_type)

self._generator = builder.create_generator(self.core_data, pyproject.tool.cppython.generator, generator_type)
self._provider = builder.create_provider(self.core_data, pyproject.tool.cppython.provider, provider_type)
except ConfigError:
logging.exception("Unhandled configuration. CPPython will process no further")
return
except ValidationError as error:
logging.error(error)
return

self._enabled = True

Expand Down
23 changes: 18 additions & 5 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ paths = ["LICENSE.md"]
homepage = "https://github.com/Synodic-Software/CPPython"
repository = "https://github.com/Synodic-Software/CPPython"

[project.optional-dependencies]
[tool.pdm]
version = {use_scm = true}

Expand All @@ -42,6 +43,7 @@ lint = [
test = [
"pytest>=7.1.2",
"pytest-cov>=3.0.0",
"pytest-click>=1.1",
"pytest-mock>=3.8.2",
"pytest-cppython>=0.2.0.dev0",
]
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/test_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Tests the click interface type"""

from click.testing import CliRunner

from cppython.console.interface import cli


class TestInterface:
"""Various tests for the click interface"""

def test_info(self, cli_runner: CliRunner) -> None:
"""Verifies that the info command functions with CPPython hooks

Args:
cli_runner: The click runner
"""

result = cli_runner.invoke(cli, ["info"], catch_exceptions=False)
assert result.exit_code == 0

def test_list(self, cli_runner: CliRunner) -> None:
"""Verifies that the list command functions with CPPython hooks

Args:
cli_runner: The click runner
"""

result = cli_runner.invoke(cli, ["list"], catch_exceptions=False)
assert result.exit_code == 0

def test_update(self, cli_runner: CliRunner) -> None:
"""Verifies that the update command functions with CPPython hooks

Args:
cli_runner: The click runner
"""

result = cli_runner.invoke(cli, ["update"], catch_exceptions=False)
assert result.exit_code == 0

def test_install(self, cli_runner: CliRunner) -> None:
"""Verifies that the install command functions with CPPython hooks

Args:
cli_runner: The click runner
"""

result = cli_runner.invoke(cli, ["install"], catch_exceptions=False)
assert result.exit_code == 0
52 changes: 52 additions & 0 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Tests the Project type"""


from pathlib import Path

import tomlkit
from cppython_core.schema import ProjectConfiguration
from pytest import FixtureRequest
from pytest_cppython.mock.interface import MockInterface

from cppython.project import Project


class TestProject:
"""Various tests for the project object"""

def test_default_construction(self, request: FixtureRequest) -> None:
"""The project type should be constructable without pyproject.toml support.
The CPPython project uses a working pyproject.toml file, and this file is used as the test data

Args:
request: The pytest request fixture
"""

# Use the CPPython directory as the test data
file = request.config.rootpath / "pyproject.toml"
project_configuration = ProjectConfiguration(pyproject_file=file, version=None)
interface = MockInterface()

pyproject_data = tomlkit.loads(file.read_text(encoding="utf-8"))
project = Project(project_configuration, interface, pyproject_data)

assert project

def test_missing_project_table(self, tmp_path: Path) -> None:
"""The project type should be constructable without the top level table

Args:
tmp_path: Temporary directory for dummy data
"""

file_path = tmp_path / "pyproject.toml"

with open(file_path, "a", encoding="utf8") as file:
file.write("")

project_configuration = ProjectConfiguration(pyproject_file=file_path, version=None)
interface = MockInterface()

project = Project(project_configuration, interface, {})

assert project