Skip to content

Simplify Implementation + Minor Document #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7353411
Comments and Style
Behemyth Dec 19, 2021
c2c80a8
More Comments
Behemyth Dec 19, 2021
b889379
Update Pytest Library Fixtures
Behemyth Dec 22, 2021
a8be9bb
Update pdm.lock
Behemyth Jan 11, 2022
8ceffd1
Fix Test Discovery
Behemyth Jan 11, 2022
6fade4e
Changes
Behemyth Jan 13, 2022
d0a48be
Broken Test
Behemyth Jan 14, 2022
69c0850
Ya
Behemyth Jan 14, 2022
a3bdf79
Update Versioning
Behemyth Jan 19, 2022
1685aa6
Update Versions
Behemyth Jan 27, 2022
24e3bac
Typing
Behemyth Feb 1, 2022
ac665f4
More Type Fixing
Behemyth Feb 2, 2022
c843f49
Update Chore
Behemyth Feb 3, 2022
1ab173b
Docstrings
Behemyth Feb 3, 2022
987bdd1
Update Chore
Behemyth Feb 4, 2022
7419d21
Add Defaults
Behemyth Feb 5, 2022
018e6a2
Fix Tests
Behemyth Feb 6, 2022
0c343bc
Add Schema Test
Behemyth Feb 6, 2022
921cbee
us
Behemyth Feb 6, 2022
52c2e27
Remove Unused
Behemyth Feb 6, 2022
bee8241
Removed Unused Tests
Behemyth Feb 6, 2022
506548e
Removed duplicated schema tests
Behemyth Feb 6, 2022
f1cb0ce
Update Chore
Behemyth Feb 7, 2022
890aab1
Plugin Tests + Remove MP Tests
Behemyth Feb 7, 2022
9f1e7d1
Remove x-dist
Behemyth Feb 7, 2022
a7485b3
Proper Entry Points
Behemyth Feb 8, 2022
7699b2e
Remove Interface Plugin + Update Chore
Behemyth Feb 8, 2022
3d36713
Strip Project to Essentials
Behemyth Feb 9, 2022
891d5df
Type Cleanup
Behemyth Feb 9, 2022
2f4b109
Data
Behemyth Feb 9, 2022
3ec5498
Update Plugin Test
Behemyth Feb 9, 2022
19ceac5
Tests
Behemyth Feb 9, 2022
1491bd2
Integration Tests
Behemyth Feb 10, 2022
ef07902
Pydantic Types
Behemyth Feb 10, 2022
5104c1d
Chores
Behemyth Feb 11, 2022
b5733ac
Type Cleanup
Behemyth Feb 11, 2022
a1dc394
Type Fixes
Behemyth Feb 11, 2022
c6ee3af
Remove Outdated Tests
Behemyth Feb 11, 2022
048a369
Readd Generator Read
Behemyth Feb 11, 2022
21cdcf2
Update Chore
Behemyth Feb 12, 2022
e30769a
Fix Tests
Behemyth Feb 12, 2022
90b5d60
Comments
Behemyth Feb 12, 2022
bd65745
Pass through Data
Behemyth Feb 12, 2022
50cd1e0
Fix CMake Tests
Behemyth Feb 12, 2022
0e2bd77
Chore
Behemyth Feb 13, 2022
1243dcf
Call install
Behemyth Feb 13, 2022
9de7904
Remove conftest
Behemyth Feb 13, 2022
d76a8bf
Comments
Behemyth Feb 14, 2022
e06afad
Command Update
Behemyth Feb 14, 2022
b754e0e
test_interface
Behemyth Feb 14, 2022
c746a1e
Test Comments
Behemyth Feb 15, 2022
ff80734
SchemaTODOs
Behemyth Feb 15, 2022
9a468a5
More TODOs
Behemyth Feb 15, 2022
aea4635
Fix TODOs
Behemyth Feb 15, 2022
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
15 changes: 13 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
"python.testing.pytestArgs": [
"tests"
],
"python.formatting.provider": "black",
"python.formatting.blackPath": "${workspaceRoot}/__pypackages__/3.10/Scripts/black",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.autoComplete.extraPaths": ["__pypackages__/<major.minor>/lib"],
"python.analysis.extraPaths": ["__pypackages__/<major.minor>/lib"]
"python.autoComplete.extraPaths": [
"__pypackages__/3.10/lib"
],
"python.analysis.extraPaths": [
"__pypackages__/3.10/lib"
],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.analysis.typeCheckingMode": "basic"
}
16 changes: 13 additions & 3 deletions cppython/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@


class ConfigError(Exception):
def __init__(self, error: Exception) -> None:
"""
Raised when there is a configuration error
"""

def __init__(self, error: str) -> None:
self._error = error

super().__init__(str(error))
super().__init__(error)

@property
def error(self) -> Exception:
def error(self) -> str:
"""
Returns the underlying error

Returns:
str -- The underlying error
"""
return self._error
41 changes: 21 additions & 20 deletions cppython/plugins/generator/cmake.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
from cppython.schema import Generator, Metadata
"""
The default generator implementation for CPPython
"""
from typing import Type

from cppython.schema import Generator, GeneratorData, PyProject

class CMakeGenerator(Generator):

class CMakeData(GeneratorData):
"""
A CPPython generator implementing a CMake backend
The data schema required for the CMake tooling
"""

def __init__(self) -> None:
pass

class CMakeGenerator(Generator):
"""
Plugin Contract
A CPPython generator implementing a CMake backend
"""

def __init__(self, pyproject: PyProject, cmake_data: CMakeData) -> None:
super().__init__(pyproject, cmake_data)

@staticmethod
def name() -> str:
"""
The name of the generator
"""
return "cmake"

"""
Generator Contract
"""

def populate_metadata(self, data: dict):
@staticmethod
def data_type() -> Type[GeneratorData]:
"""
data - The CPPoetry data taken from pyproject.toml
Returns the pydantic type to cast the generator configuration data to
"""
pass
return CMakeData

def populate_plugin(self, data: dict):
def install_generator(self) -> bool:
"""
data - The data taken from pyproject.toml that belongs to this generator
Installs the external tooling required by the generator if necessary
Returns whether anything was installed or not
"""
pass

"""
API Contract
"""
return False

def install(self) -> None:
raise NotImplementedError()
Expand Down
103 changes: 48 additions & 55 deletions cppython/plugins/interface/console.py
Original file line number Diff line number Diff line change
@@ -1,119 +1,112 @@
from cppython.project import Project
from cppython.schema import Interface, PEP621
"""
A click CLI for CPPython interfacing
"""

from pathlib import Path
from typing import Type

import click
import tomlkit

from cppython.project import Project
from cppython.schema import GeneratorData, GeneratorDataType, Interface, PyProject


def _create_pyproject():

def _read_data():
# Search for a path upward
path = Path.cwd()

while not path.glob("pyproject.toml"):
if path.is_absolute():
assert (
"This is not a valid project. No pyproject.toml found in the current directory or any of its parents."
)
False
), "This is not a valid project. No pyproject.toml found in the current directory or any of its parents."

return tomlkit.loads(Path(path / "pyproject.toml").read_text(encoding="utf-8"))
path = Path(path / "pyproject.toml")

# Load file
data = tomlkit.loads(path.read_text(encoding="utf-8"))

class Config(object):
# Interpret and validate data
return PyProject(**data)


class Config:
"""
The data object that will be expanded alongside 'pass_obj'
"""

def __init__(self):

data = _read_data()
pyproject = _create_pyproject()

# Initialize the object hook into CPPython
interface = ConsoleInterface(data)
interface = ConsoleInterface(pyproject)

# Initialize the CPPython context
self.project = Project(interface)

def load(self):
self.project.load()


pass_config = click.make_pass_decorator(Config)


@click.group()
@click.pass_context
def cli(context):
"""
entry_point group for the CLI commands
"""
context.ensure_object(Config)

# Initialize cppython
context.obj.load()


@cli.command()
@pass_config
def install(config):
"""
Fulfills the 'install' API requirement
"""
config.project.install()


@cli.command()
@pass_config
def update(config):
"""
Fulfills the 'update' API requirement
"""
config.project.update()


@cli.result_callback()
@cli.command()
@pass_config
def cleanup(config, result):
pass


class ConsoleInterface(Interface):
def build(config):
"""
TODO: Description
Fulfills the 'build' API requirement
"""
config.project.build()

def __init__(self, data: dict) -> None:
self._data = data

@cli.result_callback()
@pass_config
def cleanup(config, result):
"""
Plugin Contract
Post-command cleanup
"""

@staticmethod
def name() -> str:
"""
The name of the generator
"""
return "console"

class ConsoleInterface(Interface):
"""
Interface Contract
Interface implementation to pass to the project
"""

@staticmethod
def external_config() -> bool:
"""
True if the plugin can read its own configuration.
False otherwise
"""

return False

@staticmethod
def parse_pep_621(data: dict) -> PEP621:
def read_generator_data(self, generator_data_type: Type[GeneratorDataType]) -> GeneratorDataType:
"""
Requests the plugin to read the available PEP 621 information. Only requested if the plugin is not the entrypoint
Requests generator information
"""
raise NotImplementedError()
return generator_data_type()

def pep_621(self) -> PEP621:
def write_pyproject(self) -> None:
"""
Requests PEP 621 information from the pyproject
Write output
"""
return self.parse_pep_621(self._data)

def write_pyproject(self) -> None:
raise NotImplementedError()

def read_pyproject(self) -> dict:
return self._data
pass
15 changes: 15 additions & 0 deletions cppython/plugins/test/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Defaulted data to help testing
"""

from pathlib import Path

from cppython.schema import PEP621, CPPythonData, PyProject, TargetEnum

default_pep621 = PEP621(name="test_name", version="1.0")

# CMake is a default plugin
# TODO: Provide dynamic default
default_cppython_data = CPPythonData(generator="cmake", target=TargetEnum.EXE, install_path=Path())

default_pyproject = PyProject(pep_621=default_pep621, cppython_data=default_cppython_data)
Loading