From c74f3fb80b67633cb88bcec73de5e0d2d6c4111c Mon Sep 17 00:00:00 2001 From: Doggo <27985126+sabotagebeats@users.noreply.github.com> Date: Wed, 15 Jun 2022 18:57:44 -0700 Subject: [PATCH] feat: Adding packagemeta to config and project manager (#802) * feat: adding packagemeta to config and project manager * docs: rework meta docstring Co-authored-by: Juliya Smith * refactor: adds error for incorrect configuration of metadata Co-authored-by: Juliya Smith * fix: breakpoint Co-authored-by: Juliya Smith * fix: PackageMeta must be called Co-authored-by: Juliya Smith * 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 --- src/ape/managers/config.py | 9 +++++++++ src/ape/managers/project/manager.py | 15 ++++++++++----- tests/functional/test_project.py | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/ape/managers/config.py b/src/ape/managers/config.py index 17e21036b0..069fe5d22f 100644 --- a/src/ape/managers/config.py +++ b/src/ape/managers/config.py @@ -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 @@ -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 @@ -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") @@ -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" ) diff --git a/src/ape/managers/project/manager.py b/src/ape/managers/project/manager.py index 152531e930..bb6f9e1723 100644 --- a/src/ape/managers/project/manager.py +++ b/src/ape/managers/project/manager.py @@ -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 @@ -447,9 +447,14 @@ 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() @@ -457,6 +462,6 @@ def _get_contract(self, name: str) -> Optional[ContractContainer]: # 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 diff --git a/tests/functional/test_project.py b/tests/functional/test_project.py index e984f3d6fe..b43b66969d 100644 --- a/tests/functional/test_project.py +++ b/tests/functional/test_project.py @@ -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 ):