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

Registry explore cmd #92

Merged
merged 8 commits into from
Mar 30, 2020
Merged

Conversation

corydickson
Copy link
Contributor

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 corresponding version and manifest_uri as well as the package name.

Cute Animal Picture

put a cute animal picture link inside the parentheses

Add tests for cli output

Fix pm functions

More formatting / linting
pkg_version,
namespaced_asset,
ens,
) = parse_registry_uri(uri)
Copy link
Contributor Author

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

Copy link
Contributor

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")
Copy link
Contributor Author

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 😭

Copy link
Contributor Author

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

Copy link
Contributor

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.

@corydickson
Copy link
Contributor Author

I'll push a fix for the linter if the formatting looks good on the output and add the corresponding tests!

Copy link
Contributor

@njgheorghita njgheorghita left a 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

pkg_version,
namespaced_asset,
ens,
) = parse_registry_uri(uri)
Copy link
Contributor

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

namespaced_asset,
ens,
) = parse_registry_uri(uri)
config.w3.enable_unstable_package_management_api()
Copy link
Contributor

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

@@ -141,6 +142,12 @@ def add_package_version_to_parser(
)


def add_uri_to_parser(parser: argparse.ArgumentParser, help_msg: str,) -> None:
Copy link
Contributor

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.",
Copy link
Contributor

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

Copy link
Contributor Author

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

@@ -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):
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

display_packages(package_names, config)

else:
raise UriNotSupportedError("Cannot resolve both an alias and registry uri.")
Copy link
Contributor

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.")

Copy link
Contributor Author

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?

Copy link
Contributor

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

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
Copy link
Contributor

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:

(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"
Copy link
Contributor

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")
Copy link
Contributor

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.

@corydickson
Copy link
Contributor Author

corydickson commented Feb 28, 2020

Should have the tests ready this weekend, bit busy this week sorry for the delay

@njgheorghita
Copy link
Contributor

@corydickson No worries! just ping me whenever this is ready for a review

@corydickson
Copy link
Contributor Author

@njgheorghita Thank you for the patience, should be ready for review!

@corydickson
Copy link
Contributor Author

May I make the changes suggested by the linter here?

Copy link
Contributor

@njgheorghita njgheorghita left a 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')}: ")
Copy link
Contributor

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

assert registry.alias == expected["alias"]
registry = resolve_uri_or_alias(uri, store_path)
assert registry.uri == expected["uri"]
else:
Copy link
Contributor

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.

Copy link
Contributor Author

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

@@ -203,3 +216,15 @@ def generate_registry_store_data(
"alias": alias,
"active": activate,
}


def display_packages(all_package_names: Iterable[str], config: Config) -> None:
Copy link
Contributor

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.

Copy link
Contributor Author

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")
Copy link
Contributor

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.

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"
Copy link
Contributor

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.

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")
Copy link
Contributor

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.

Copy link
Contributor Author

@corydickson corydickson Mar 28, 2020

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

@njgheorghita
Copy link
Contributor

Also the mypy fixes are in master now if you want to rebase against master to fix the linting errors.

@corydickson corydickson force-pushed the registry-explore-cmd branch 5 times, most recently from 74fd6aa to 2b660af Compare March 28, 2020 01:12
@corydickson
Copy link
Contributor Author

lol sorry for the fp was having issues... should be rebased correctly

@njgheorghita
Copy link
Contributor

Looks good, thanks @corydickson !!

@njgheorghita njgheorghita merged commit 432e3aa into ethpm:master Mar 30, 2020
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.

2 participants