Skip to content
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

feat: Adding packagemeta to config and project manager #802

Merged
merged 21 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d6ef1df
feat: adding packagemeta to config and project manager
sabotagebeats Jun 13, 2022
06de772
docs: rework meta docstring
sabotagebeats Jun 13, 2022
67ccc3a
refactor: adds error for incorrect configuration of metadata
sabotagebeats Jun 13, 2022
93be732
fix: breakpoint
sabotagebeats Jun 13, 2022
cd76db4
fix: PackageMeta must be called
sabotagebeats Jun 13, 2022
2c9526a
docs: removed unnecessary TODO
sabotagebeats Jun 13, 2022
9e6539c
fix: import configerror from ape.exceptions
sabotagebeats Jun 13, 2022
099d610
refactor: commented out publish_manifest method
sabotagebeats Jun 13, 2022
3e47528
style: linting
sabotagebeats Jun 13, 2022
e892b36
docs: added docstring for packagemeta method
sabotagebeats Jun 14, 2022
ed41979
fix: add meta to plugin config manager
sabotagebeats Jun 14, 2022
0b68bf1
fix: project now has meta
sabotagebeats Jun 14, 2022
218fe1c
style: linting
sabotagebeats Jun 14, 2022
6a06e23
docs: type ignore and docstring for meta
sabotagebeats Jun 14, 2022
d8537b2
style: linting
sabotagebeats Jun 14, 2022
230b1b5
test: added test for meta
sabotagebeats Jun 14, 2022
863083d
test: test meta with temp_config fixture
sabotagebeats Jun 14, 2022
f97e1d2
test: filled out extra meta fields in test temp_config
sabotagebeats Jun 14, 2022
c72aba2
Merge branch 'main' of https://github.com/apeworx/ape into feat/meta
sabotagebeats Jun 15, 2022
552ce43
fix: removed exception for meta
sabotagebeats Jun 15, 2022
b6b9f74
chore: Merge remote-tracking branch 'upstream/main' into feat/meta
sabotagebeats Jun 16, 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
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
19 changes: 13 additions & 6 deletions src/ape/managers/project/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
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
from ape.exceptions import ProjectError
from ape.exceptions import ConfigError, ProjectError
from ape.managers.base import BaseManager
from ape.managers.project.types import ApeProject, BrownieProject

Expand Down Expand Up @@ -447,16 +447,23 @@ 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: # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably put the type ignore on the return stmt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this fixed the type issue.

"""
Populate package manifest with metadata as per EIP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not populate the manifest, so I would change this doc.
This just reads the value from the config manager.

Try something like

Metadata about the active project as per EIP ...
Use when publishing your package manifest.

https://eips.ethereum.org/EIPS/eip-2678#the-package-meta-object
"""
try:
return self.config_manager.meta
except Exception as e:
raise ConfigError(f"Incorrect configuration of package metadata:\n{meta}") from e
Copy link
Contributor Author

@sabotagebeats sabotagebeats Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flake8 . ./src/ape/managers/project/manager.py:459:80: F821 undefined name 'meta'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unparalleled-js I'm still having this issue and not sure how to resolve it.


# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this would require looping through all the sources and publishing them to IPFS as well, then updating all of the links in the package from local links to global ones.

Also side-note is that eventually DependencyAPI should store everything as IPFS content locally to make it super easy to publish

# TODO: Publish to IPFS
Comment on lines 466 to 467
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs #208 to complete these TODOs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required for this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we are building towards that though with the Deployments story

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#365 also this related issue for IPFS