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

Conversation

sabotagebeats
Copy link
Contributor

@sabotagebeats sabotagebeats commented Jun 13, 2022

What I did

Adding the package meta to the project config and project manager

fixes: #793

How I did it

following instructions laid out in issue #793

How to verify it

When it works, the package meta should be filled out in the contract manifest

Checklist

  • All changes are completed
  • New test cases have been added
  • Documentation has been updated

@sabotagebeats
Copy link
Contributor Author

sabotagebeats commented Jun 13, 2022

src/ape/managers/project/manager.py:452: error: "PluginConfig" has no attribute "serialize"

@sabotagebeats
Copy link
Contributor Author

code is not hitting my breakpoint within publish_manifest(self):

src/ape/managers/config.py Outdated Show resolved Hide resolved
src/ape/managers/project/manager.py Outdated Show resolved Hide resolved

def publish_manifest(self):
manifest = self.manifest.dict()
if not manifest["name"]:
Copy link
Member

Choose a reason for hiding this comment

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

If name was not in the manifest, I believe self.manifest would already raise a ValidationError, no?
We should leave this method commented out, but at the same time, we could probably remove the if not checks here since they happen at the model-level now.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, name and version field are optional in spec, but recommended/required for publishing
https://github.com/ApeWorX/ethpm-types/blob/770ba756947215a58a41391c71cbe717708e8ab8/ethpm_types/manifest.py#L58-L60

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this resolved since this code has now been commented out for the time being?

src/ape/managers/project/manager.py Outdated Show resolved Hide resolved
src/ape/managers/project/manager.py Outdated Show resolved Hide resolved
src/ape/managers/config.py Outdated Show resolved Hide resolved
src/ape/managers/project/manager.py Outdated Show resolved Hide resolved
src/ape/managers/config.py Outdated Show resolved Hide resolved
src/ape/managers/project/manager.py Outdated Show resolved Hide resolved
src/ape/managers/project/manager.py Outdated Show resolved Hide resolved
src/ape/managers/project/manager.py Outdated Show resolved Hide resolved

def publish_manifest(self):
manifest = self.manifest.dict()
if not manifest["name"]:
Copy link
Member

Choose a reason for hiding this comment

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

Actually, name and version field are optional in spec, but recommended/required for publishing
https://github.com/ApeWorX/ethpm-types/blob/770ba756947215a58a41391c71cbe717708e8ab8/ethpm_types/manifest.py#L58-L60

src/ape/managers/project/manager.py Outdated Show resolved Hide resolved
Comment on lines 463 to 464
# TODO: Publish sources to IPFS and replace with CIDs
# TODO: Publish to IPFS
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

# 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

Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

  • Update config.md to include information about meta

It might be also worth adding a test in tests/functional/test_project.py like test_manifest_config() and use the temp_config() fixture to temporary adjust the project config and make sure you can read it on the meta() property you are adding as well other publishing related fields you are going to add over time, including name and version

# def meta(self) -> PackageMeta:
# return PackageMeta(**self.config_manager.get_config("ethpm").serialize())
@property
def meta(self) -> PackageMeta:
Copy link
Member

@antazoey antazoey Jun 14, 2022

Choose a reason for hiding this comment

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

  • add doc str to this property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

docstring added: e892b36 please review for completeness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added test, probably should be reworked: 230b1b5

Comment on lines 463 to 464
# TODO: Publish sources to IPFS and replace with CIDs
# TODO: Publish to IPFS
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?

@sabotagebeats
Copy link
Contributor Author

@unparalleled-js ipfs publishing is not required for this PR, this issue here is for IPFS publishing: #365

@sabotagebeats
Copy link
Contributor Author

sabotagebeats commented Jun 14, 2022

I can't seem to get this to actually function properly:

In [1]: manifest = project.Token.project_manager.extract_manifest()

In [2]: manifest.meta

In [3]: type(manifest.meta)
Out[3]: NoneType
In [5]: manifest.meta()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [5], in <module>
----> 1 manifest.meta()

TypeError: 'NoneType' object is not callable

@fubuloubu
Copy link
Member

I can't seem to get this to actually function properly:

In [1]: manifest = project.Token.project_manager.extract_manifest()

In [2]: manifest.meta

In [3]: type(manifest.meta)
Out[3]: NoneType
In [5]: manifest.meta()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [5], in <module>
----> 1 manifest.meta()

TypeError: 'NoneType' object is not callable

PackageManifest.meta is an optional field, so you have to handle when it is None by raising in that scenario

Although, more broadly speaking might need to fill in the meta fields for when dependencies get downloaded via DependencyAPI?

@sabotagebeats
Copy link
Contributor Author

need to add testing and make sure functionality works

Comment on lines 456 to 460
meta = self.config_manager.get_config("meta")
try:
return PackageMeta(**meta.serialize())
except Exception as e:
raise ConfigError(f"Incorrect configuration of package metadata:\n{meta}") from e
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this code isn't getting ran when compiling or extracting manifest. I also have the following error in mypy src/ape/managers/project/manager.py:459: error: "PluginConfig" has no attribute "serialize"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does get ran when I do this command in console: In [1]: project.Token.project_manager.meta

@@ -147,6 +152,7 @@ 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", "")
self.meta = configs["meta"] = user_config.pop("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.

does this look right?

@sabotagebeats sabotagebeats requested a review from antazoey June 14, 2022 19:03
Comment on lines 456 to 458
meta = self.config_manager.get_config("meta")
try:
return PackageMeta(**meta.serialize())
Copy link
Member

Choose a reason for hiding this comment

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

Try this:

Suggested change
meta = self.config_manager.get_config("meta")
try:
return PackageMeta(**meta.serialize())
try:
return self.config_manager.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.

I was able to get the meta into the project by using this
0b68bf1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

still need to get the meta into the manifest

@@ -147,6 +152,7 @@ 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", "")
self.meta = configs["meta"] = user_config.pop("meta", "")
Copy link
Member

Choose a reason for hiding this comment

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

Along with this

Suggested change
self.meta = configs["meta"] = user_config.pop("meta", "")
self.meta = configs["meta"] = PackageMeta(**user_config.pop("meta", ""))

Comment on lines 456 to 459
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 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.

@property
def meta(self) -> PackageMeta: # type: ignore
"""
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.

@sabotagebeats sabotagebeats requested a review from antazoey June 14, 2022 19:58
@@ -45,6 +46,12 @@ def test_extract_manifest(dependency_config, project_manager):
assert type(manifest) == PackageManifest


def test_meta(dependency_config, project_manager):
Copy link
Member

@antazoey antazoey Jun 14, 2022

Choose a reason for hiding this comment

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

Instead of using dependency_config, use the temp_config fixture to make your own meta config:

def test_meta(temp_config, project_manager):
    meta_config = {"meta": {"authors": ["Test Testerson"]}}
    with temp_config(meta_config):
        assert project_amager.meta.authors == ["Test Testerson"]

Copy link
Member

Choose a reason for hiding this comment

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

Expand on my example a little, add the other properties and stuff

@sabotagebeats sabotagebeats requested a review from antazoey June 14, 2022 23:30
Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

LGTM

@sabotagebeats sabotagebeats merged commit c74f3fb into ApeWorX:main Jun 16, 2022
@sabotagebeats sabotagebeats deleted the feat/meta branch June 16, 2022 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Meta field not stored in contract manifest
3 participants