-
Notifications
You must be signed in to change notification settings - Fork 12
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
Registry explore cmd #92
Conversation
Add tests for cli output Fix pm functions More formatting / linting
ethpm_cli/commands/registry.py
Outdated
pkg_version, | ||
namespaced_asset, | ||
ens, | ||
) = parse_registry_uri(uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need any of these other than the address
but was unable to find a suitable function, I'll use underscore to remove these unused variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse_registry_uri(uri)
returns a RegistryURI
type, which is a custom NamedTuple
- so you should be able to do something like
parsed_registry_uri = parse_registry_uri(uri)
and then access properties on it like
parsed_registry_uri.address
f"ethpm registry explore erc1319://0x16763EaE3709e47eE6140507Ff84A61c23B0098A:1" | ||
) | ||
child_five.expect(ENTRY_DESCRIPTION) | ||
child_five.expect("\r\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you like the current formatting I'll add additional tests for an existing registry live on mainnet, hopefully something with fewer entries 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually after some thought that might be a bit flaky in the future if people add packages and the order is not preserved... maybe we should just add a new test case that releases a local package to a fresh registry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! That would be ideal - but I think that would require us to have the tester chain up and running? But, we get a free out of jail card here b/c of the way the registry contract is written it returns the package ids in the same order every time - new ones are at the end of the list. So, you should be safe to use one of the mainnet registries and just test that the first handful of packages are displayed.
I'll push a fix for the linter if the formatting looks good on the output and add the corresponding tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a great start, thanks! Just some changes to be made - let me know if you have any questions
ethpm_cli/commands/registry.py
Outdated
pkg_version, | ||
namespaced_asset, | ||
ens, | ||
) = parse_registry_uri(uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse_registry_uri(uri)
returns a RegistryURI
type, which is a custom NamedTuple
- so you should be able to do something like
parsed_registry_uri = parse_registry_uri(uri)
and then access properties on it like
parsed_registry_uri.address
ethpm_cli/commands/registry.py
Outdated
namespaced_asset, | ||
ens, | ||
) = parse_registry_uri(uri) | ||
config.w3.enable_unstable_package_management_api() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure you need this line here - was it raising an error without it? The enable_unstable_package_management_api()
flag should have been handled in config.py
ethpm_cli/parser.py
Outdated
@@ -141,6 +142,12 @@ def add_package_version_to_parser( | |||
) | |||
|
|||
|
|||
def add_uri_to_parser(parser: argparse.ArgumentParser, help_msg: str,) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the trailing comma after str
here. Trailing commas are typically only useful when there is only one argument per line aka
things = (
parser: argparse.ArgumentParser,
help_msg: str,
)
"explore", help="Explore a registry's list of released packages and manifest uris.", | ||
) | ||
add_uri_to_parser( | ||
registry_explore_parser, "Registry URI for target registry.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we thinking of also supporting any aliased registries? I think it'd be more useful than requiring the entire uri everytime you want to explore a registry. imo ethpm registry explore ens
> ethpm registry explore ethpm://ens.snakecharmers.eth/
for example. I think we do something similar for ethpm registry activate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh okay I see the desired behavior; I'll remove the error thrown directly in explore_registry
and just use resolve_uri_or_alias
tests/core/test_registry.py
Outdated
@@ -141,3 +142,8 @@ def test_unable_to_activate_nonexistent_aliased_registry(config): | |||
add_registry(URI_1, "mine", config) | |||
with pytest.raises(InstallError): | |||
activate_registry("other", config) | |||
|
|||
|
|||
def test_explore_uri_invalid_raises_error(config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great place to use @pytest.mark.parametrize
- we're big fans of this decorator and tend to use it a lot. It lets you test a lot of varied assumptions without a ton of bloat. I'd load it up with any useful or weird edge cases you want to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To follow up the rest of the review would we want to even test that this function is throwing an error here anymore? Instead make it something like test_resolve_uri_or_alias_raises_error
and try to hit all the cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a better idea, i'd just write tests that resolve_uri_or_alias
fails/passes for all the various edge cases.
ethpm_cli/commands/registry.py
Outdated
display_packages(package_names, config) | ||
|
||
else: | ||
raise UriNotSupportedError("Cannot resolve both an alias and registry uri.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this error message. It seems as though we currently aren't accepting an alias? Also, I tend to use f-strings a lot in my error messages - displaying the incorrect variable in the mesage can be extremely useful for users and yourself later on.
Something more like...
else:
raise UriNotSupportedError(f"Invalid URI: {uri}, unable to explore. Registry URI definition can be found at https://docs.ethpm.com/uris#registry-uris.")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the other comment below but I think it's okay to get rid of this if we are going to use existing error messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that looks like it should be fine
ethpm_cli/commands/registry.py
Outdated
all_releases = config.w3.pm.get_all_package_releases(package_name) | ||
cli_logger.info(f"Retrieving releases for {bold_blue(package_name)}: \n") | ||
for release in all_releases: | ||
(version, manifest_uri) = release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do for version, manifest_uri in all_releases:
ethpm_cli/commands/registry.py
Outdated
(version, manifest_uri) = release | ||
cli_logger.info(f"{bold_green(version)} --- ({bold_white(manifest_uri)})") | ||
cli_logger.info( | ||
f"Total: {config.w3.pm.get_release_count(package_name)}\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick be a bit more descriptive here - total what?
f"ethpm registry explore erc1319://0x16763EaE3709e47eE6140507Ff84A61c23B0098A:1" | ||
) | ||
child_five.expect(ENTRY_DESCRIPTION) | ||
child_five.expect("\r\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! That would be ideal - but I think that would require us to have the tester chain up and running? But, we get a free out of jail card here b/c of the way the registry contract is written it returns the package ids in the same order every time - new ones are at the end of the list. So, you should be safe to use one of the mainnet registries and just test that the first handful of packages are displayed.
Should have the tests ready this weekend, bit busy this week sorry for the delay |
@corydickson No worries! just ping me whenever this is ready for a review |
@njgheorghita Thank you for the patience, should be ready for review! |
May I make the changes suggested by the linter here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just a couple nitpicks left. Thanks for wrapping this one up - hope you're well!
child_five.expect("\r\n") | ||
child_five.expect(f"Total releases: 1") | ||
child_five.expect("\r\n\r\n") | ||
child_five.expect_exact(f"Retrieving all releases for {bold_blue('dai-dai')}: ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool! Wasn't aware of expect_exact
tests/core/test_registry.py
Outdated
assert registry.alias == expected["alias"] | ||
registry = resolve_uri_or_alias(uri, store_path) | ||
assert registry.uri == expected["uri"] | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure I've given you conflicting rules of thumbs on how to do this, but imo - if
statements are a good indicator that a test should be split up - especially if it's for valid/invalid cases. In this instance I'd split this test b/w the valid/invalid cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I'll split these up
ethpm_cli/commands/registry.py
Outdated
@@ -203,3 +216,15 @@ def generate_registry_store_data( | |||
"alias": alias, | |||
"active": activate, | |||
} | |||
|
|||
|
|||
def display_packages(all_package_names: Iterable[str], config: Config) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably get away with just passing the w3
that exists on config
here rather than the entire config
instance - just to tidy things up a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call
def display_packages(all_package_names: Iterable[str], config: Config) -> None: | ||
for package_name in all_package_names: | ||
all_releases = config.w3.pm.get_all_package_releases(package_name) | ||
cli_logger.info(f"Retrieving all releases for {bold_blue(package_name)}: \n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put line 224 above 223 - since the call to w3 to fetch all of the releases could take a couple of seconds, it would be better to have this message displayed before that call is made.
ethpm_cli/commands/registry.py
Outdated
for version, manifest_uri in all_releases: | ||
cli_logger.info(f"{bold_green(version)} --- ({bold_white(manifest_uri)})") | ||
cli_logger.info( | ||
f"Total releases: {config.w3.pm.get_release_count(package_name)}\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to get away without this w3
call and just use len(all_releases)
to get the count.
ethpm_cli/commands/registry.py
Outdated
cli_logger.info( | ||
f"Total releases: {config.w3.pm.get_release_count(package_name)}\n" | ||
) | ||
cli_logger.info(f"Packages in the registry: {config.w3.pm.get_package_count()}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason that this comes at the end of the function? It might be more useful at the beginning - like if there are 1000 packages available, it'd be better to know before all of the calls for each particular package rather than after all 1000 calls have been made and displayed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason but your suggestion makes a lot more sense. I'm not going to add a test for this line though to prevent it from being flaky in the future
Also the mypy fixes are in master now if you want to rebase against master to fix the linting errors. |
74fd6aa
to
2b660af
Compare
2b660af
to
f7c6689
Compare
lol sorry for the fp was having issues... should be rebased correctly |
Looks good, thanks @corydickson !! |
What was wrong?
Issue #88
How was it fixed?
Added a new subparser to
registry
that accepts a valid URI and prints the total releases with their correspondingversion
andmanifest_uri
as well as the package name.Cute Animal Picture