Skip to content

Commit

Permalink
feat: Adding packagemeta to config and project manager (#802)
Browse files Browse the repository at this point in the history
* feat: adding packagemeta to config and project manager

* docs: rework meta docstring

Co-authored-by: Juliya Smith <yingthi@live.com>

* refactor: adds error for incorrect configuration of metadata

Co-authored-by: Juliya Smith <yingthi@live.com>

* fix: breakpoint

Co-authored-by: Juliya Smith <yingthi@live.com>

* fix: PackageMeta must be called

Co-authored-by: Juliya Smith <yingthi@live.com>

* docs: removed unnecessary TODO

* fix: import configerror from ape.exceptions

* refactor: commented out publish_manifest method

* style: linting

* docs: added docstring for packagemeta method

* fix: add meta to plugin config manager

* fix: project now has meta

* style: linting

* docs: type ignore and docstring for meta

* style: linting

* test: added test for meta

* test: test meta with temp_config fixture

* test: filled out extra meta fields in test temp_config

* fix: removed exception for meta

Co-authored-by: Juliya Smith <yingthi@live.com>
  • Loading branch information
sabotagebeats and antazoey authored Jun 16, 2022
1 parent 8eeb203 commit c74f3fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/ape/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
if TYPE_CHECKING:
from .project import ProjectManager

from ethpm_types import PackageMeta

CONFIG_FILE_NAME = "ape-config.yaml"
DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT = 120
Expand Down Expand Up @@ -86,6 +87,9 @@ class ConfigManager(BaseInterfaceModel):
version: str = ""
"""The project's version."""

meta: PackageMeta = PackageMeta()
"""Metadata about the project."""

contracts_folder: Path = None # type: ignore
"""
The path to the project's ``contracts/`` directory
Expand Down Expand Up @@ -131,6 +135,7 @@ def _plugin_configs(self) -> Dict[str, PluginConfig]:
self.name = cache.get("name", "")
self.version = cache.get("version", "")
self.default_ecosystem = cache.get("default_ecosystem", "ethereum")
self.meta = PackageMeta.parse_obj(cache.get("meta", {}))
self.dependencies = cache.get("dependencies", [])
self.deployments = cache.get("deployments", {})
self.contracts_folder = cache.get("contracts_folder", self.PROJECT_FOLDER / "contracts")
Expand All @@ -147,6 +152,10 @@ def _plugin_configs(self) -> Dict[str, PluginConfig]:
user_config = load_config(config_file) if config_file.exists() else {}
self.name = configs["name"] = user_config.pop("name", "")
self.version = configs["version"] = user_config.pop("version", "")
meta_dict = user_config.pop("meta", {})
meta_obj = PackageMeta.parse_obj(meta_dict)
configs["meta"] = meta_dict
self.meta = meta_obj
self.default_ecosystem = configs["default_ecosystem"] = user_config.pop(
"default_ecosystem", "ethereum"
)
Expand Down
15 changes: 10 additions & 5 deletions src/ape/managers/project/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Dict, List, Optional, Type, Union

from ethpm_types import Compiler, ContractType, PackageManifest
from ethpm_types import Compiler, ContractType, PackageManifest, PackageMeta

from ape.api import DependencyAPI, ProjectAPI
from ape.contracts import ContractContainer, ContractNamespace
Expand Down Expand Up @@ -447,16 +447,21 @@ def _get_contract(self, name: str) -> Optional[ContractContainer]:

return None

# @property
# def meta(self) -> PackageMeta:
# return PackageMeta(**self.config_manager.get_config("ethpm").serialize())
@property
def meta(self) -> PackageMeta:
"""
Metadata about the active project as per EIP
https://eips.ethereum.org/EIPS/eip-2678#the-package-meta-object
Use when publishing your package manifest.
"""
return self.config_manager.meta # type: ignore

# def publish_manifest(self):
# manifest = self.manifest.dict()
# if not manifest["name"]:
# raise ProjectError("Need name to release manifest")
# if not manifest["version"]:
# raise ProjectError("Need version to release manifest")
# TODO: Clean up manifest and minify it

# TODO: Publish sources to IPFS and replace with CIDs
# TODO: Publish to IPFS
18 changes: 18 additions & 0 deletions tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ def test_extract_manifest(dependency_config, project_manager):
assert type(manifest) == PackageManifest


def test_meta(temp_config, project_manager):
meta_config = {
"meta": {
"authors": ["Test Testerson"],
"license": "MIT",
"description": "test",
"keywords": ["testing"],
"links": {"apeworx.io": "https://apeworx.io"},
}
}
with temp_config(meta_config):
assert project_manager.meta.authors == ["Test Testerson"]
assert project_manager.meta.license == "MIT"
assert project_manager.meta.description == "test"
assert project_manager.meta.keywords == ["testing"]
assert "https://apeworx.io" in project_manager.meta.links["apeworx.io"]


def test_dependency_with_longer_contracts_folder(
dependency_config, config, mocker, project_manager
):
Expand Down

0 comments on commit c74f3fb

Please sign in to comment.