From 320a9234f02de0f6c55667a90c529d5772896b4d Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Wed, 15 May 2019 15:15:37 +0200 Subject: [PATCH 1/4] Uninstall packages --- ethpm_cli/install.py | 24 ++++++++++++++++++++++-- tests/core/test_install.py | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/ethpm_cli/install.py b/ethpm_cli/install.py index 28b33dd..dcdc69d 100644 --- a/ethpm_cli/install.py +++ b/ethpm_cli/install.py @@ -7,7 +7,7 @@ from typing import Iterable, Tuple from eth_utils import to_dict, to_text -from eth_utils.toolz import assoc +from eth_utils.toolz import assoc, dissoc from ethpm.backends.ipfs import BaseIPFSBackend from ethpm.utils.ipfs import is_ipfs_uri @@ -36,7 +36,7 @@ def __init__(self, args: Namespace) -> None: def install_package(pkg: Package, config: Config) -> None: - if os.path.exists(config.ethpm_dir / pkg.alias): + if package_is_installed(pkg.alias, config): raise InstallError( "Installation conflict: A directory or file already exists at the install location " f"for the package '{pkg.manifest['package_name']}' aliased to '{pkg.alias}' on the " @@ -54,6 +54,20 @@ def install_package(pkg: Package, config: Config) -> None: update_ethpm_lock(pkg, (config.ethpm_dir / "ethpm.lock")) +def package_is_installed(package_name, config) -> bool: + return os.path.exists(config.ethpm_dir / package_name) + + +def uninstall_package(package_name: str, config: Config) -> None: + if not package_is_installed(package_name, config): + raise InstallError( + f"Unable to uninstall {package_name} from {config.ethpm_dir}" + ) + + shutil.rmtree(config.ethpm_dir / package_name) + uninstall_from_ethpm_lock(package_name, (config.ethpm_dir / "ethpm.lock")) + + def write_pkg_installation_files( pkg: Package, tmp_pkg_dir: Path, ipfs_backend: BaseIPFSBackend ) -> None: @@ -116,3 +130,9 @@ def update_ethpm_lock(pkg: Package, ethpm_lock: Path) -> None: new_pkg_data = pkg.generate_ethpm_lock() new_lock = assoc(old_lock, pkg.alias, new_pkg_data) ethpm_lock.write_text(f"{json.dumps(new_lock, sort_keys=True, indent=4)}\n") + + +def uninstall_from_ethpm_lock(package_name: str, ethpm_lock: Path): + old_lock = json.loads(ethpm_lock.read_text()) + new_lock = dissoc(old_lock, package_name) + ethpm_lock.write_text(f"{json.dumps(new_lock, sort_keys=True, indent=4)}\n") diff --git a/tests/core/test_install.py b/tests/core/test_install.py index 4e8ab41..4046513 100644 --- a/tests/core/test_install.py +++ b/tests/core/test_install.py @@ -5,7 +5,7 @@ from ethpm_cli._utils.testing import check_dir_trees_equal from ethpm_cli.exceptions import InstallError -from ethpm_cli.install import Config, install_package +from ethpm_cli.install import Config, install_package, uninstall_package from ethpm_cli.package import Package @@ -29,6 +29,13 @@ def owned_pkg(config): config.ipfs_backend, ) +@pytest.fixture +def wallet_pkg(config): + return Package( + "ipfs://QmRMSm4k37mr2T3A2MGxAj2eAHGR5veibVt1t9Leh5waV1", + None, + config.ipfs_backend, + ) @pytest.mark.parametrize( "uri,pkg_name,alias,install_type", @@ -95,12 +102,7 @@ def test_can_install_same_package_twice_if_aliased(config, owned_pkg, test_asset ) -def test_install_multiple_packges(config, test_assets_dir, owned_pkg): - wallet_pkg = Package( - "ipfs://QmRMSm4k37mr2T3A2MGxAj2eAHGR5veibVt1t9Leh5waV1", - None, - config.ipfs_backend, - ) +def test_install_multiple_packages(config, test_assets_dir, owned_pkg, wallet_pkg): install_package(owned_pkg, config) install_package(wallet_pkg, config) @@ -109,3 +111,25 @@ def test_install_multiple_packges(config, test_assets_dir, owned_pkg): assert check_dir_trees_equal( config.ethpm_dir, (test_assets_dir / "multiple" / "ethpm_packages") ) + + +@pytest.mark.parametrize( + "uninstall,keep", + ( + ("wallet", "owned"), + ("owned", "wallet"), + ) +) +def test_uninstall_packages(uninstall, keep, config, test_assets_dir, owned_pkg, wallet_pkg): + install_package(owned_pkg, config) + install_package(wallet_pkg, config) + uninstall_package(uninstall, config) + + assert (config.ethpm_dir / keep).is_dir() + assert not (config.ethpm_dir / uninstall).is_dir() + assert check_dir_trees_equal(config.ethpm_dir, (test_assets_dir / keep / "ipfs_uri" / "ethpm_packages")) + + +def test_uninstall_package_warns_if_package_doesnt_exist(config): + with pytest.raises(InstallError, match="Unable to uninstall"): + uninstall_package("invalid", config) From 0f74b0dc4cf624fce0bc9f031618b98f42e50803 Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Wed, 15 May 2019 16:11:39 +0200 Subject: [PATCH 2/4] Implement ethpm list --- ethpm_cli/install.py | 41 ++++++++++++++++++++++++++++---------- ethpm_cli/main.py | 17 ++++++++++++++-- tests/core/test_install.py | 38 +++++++++++++++++++++++++---------- tox.ini | 2 +- 4 files changed, 75 insertions(+), 23 deletions(-) diff --git a/ethpm_cli/install.py b/ethpm_cli/install.py index dcdc69d..fa07b63 100644 --- a/ethpm_cli/install.py +++ b/ethpm_cli/install.py @@ -1,12 +1,13 @@ from argparse import Namespace import json +import logging import os from pathlib import Path import shutil import tempfile from typing import Iterable, Tuple -from eth_utils import to_dict, to_text +from eth_utils import to_dict, to_list, to_text from eth_utils.toolz import assoc, dissoc from ethpm.backends.ipfs import BaseIPFSBackend from ethpm.utils.ipfs import is_ipfs_uri @@ -17,6 +18,8 @@ from ethpm_cli.package import Package from ethpm_cli.validation import validate_parent_directory +logger = logging.getLogger("ethpm_cli.install") + class Config: """ @@ -26,7 +29,11 @@ class Config: """ def __init__(self, args: Namespace) -> None: - self.ipfs_backend = get_ipfs_backend(args.local_ipfs) + if "local_ipfs" in args: + self.ipfs_backend = get_ipfs_backend(args.local_ipfs) + else: + self.ipfs_backend = get_ipfs_backend(True) + if args.ethpm_dir is None: self.ethpm_dir = Path.cwd() / ETHPM_DIR_NAME if not self.ethpm_dir.is_dir(): @@ -36,7 +43,7 @@ def __init__(self, args: Namespace) -> None: def install_package(pkg: Package, config: Config) -> None: - if package_is_installed(pkg.alias, config): + if is_package_installed(pkg.alias, config): raise InstallError( "Installation conflict: A directory or file already exists at the install location " f"for the package '{pkg.manifest['package_name']}' aliased to '{pkg.alias}' on the " @@ -47,19 +54,33 @@ def install_package(pkg: Package, config: Config) -> None: tmp_pkg_dir = Path(tempfile.mkdtemp()) write_pkg_installation_files(pkg, tmp_pkg_dir, config.ipfs_backend) - # Copy temp pacakge directory to ethpm dir namespace + # Copy temp package directory to ethpm dir namespace dest_pkg_dir = config.ethpm_dir / pkg.alias validate_parent_directory(config.ethpm_dir, dest_pkg_dir) shutil.copytree(tmp_pkg_dir, dest_pkg_dir) - update_ethpm_lock(pkg, (config.ethpm_dir / "ethpm.lock")) + install_to_ethpm_lock(pkg, (config.ethpm_dir / "ethpm.lock")) + + +def list_installed_packages(config: Config) -> None: + for pkg_data in get_installed_packages(config.ethpm_dir): + logger.info(pkg_data) + + +@to_list +def get_installed_packages(ethpm_dir: Path) -> Iterable[str]: + installed_pkgs = reversed(sorted(ethpm_dir.glob("**/manifest.json"))) + for manifest_path in installed_pkgs: + manifest = json.loads(manifest_path.read_text()) + num_deep = str(manifest_path.relative_to(ethpm_dir)).count("/") + yield f"{num_deep * '--'} " -def package_is_installed(package_name, config) -> bool: +def is_package_installed(package_name: str, config: Config) -> bool: return os.path.exists(config.ethpm_dir / package_name) def uninstall_package(package_name: str, config: Config) -> None: - if not package_is_installed(package_name, config): + if not is_package_installed(package_name, config): raise InstallError( f"Unable to uninstall {package_name} from {config.ethpm_dir}" ) @@ -77,7 +98,7 @@ def write_pkg_installation_files( write_sources_to_disk(pkg, tmp_pkg_dir, ipfs_backend) write_build_deps_to_disk(pkg, tmp_pkg_dir, ipfs_backend) tmp_ethpm_lock = tmp_pkg_dir.parent / "ethpm.lock" - update_ethpm_lock(pkg, tmp_ethpm_lock) + install_to_ethpm_lock(pkg, tmp_ethpm_lock) def write_sources_to_disk( @@ -121,7 +142,7 @@ def write_build_deps_to_disk( write_pkg_installation_files(dep_pkg, tmp_dep_dir, ipfs_backend) -def update_ethpm_lock(pkg: Package, ethpm_lock: Path) -> None: +def install_to_ethpm_lock(pkg: Package, ethpm_lock: Path) -> None: if ethpm_lock.is_file(): old_lock = json.loads(ethpm_lock.read_text()) else: @@ -132,7 +153,7 @@ def update_ethpm_lock(pkg: Package, ethpm_lock: Path) -> None: ethpm_lock.write_text(f"{json.dumps(new_lock, sort_keys=True, indent=4)}\n") -def uninstall_from_ethpm_lock(package_name: str, ethpm_lock: Path): +def uninstall_from_ethpm_lock(package_name: str, ethpm_lock: Path) -> None: old_lock = json.loads(ethpm_lock.read_text()) new_lock = dissoc(old_lock, package_name) ethpm_lock.write_text(f"{json.dumps(new_lock, sort_keys=True, indent=4)}\n") diff --git a/ethpm_cli/main.py b/ethpm_cli/main.py index 16d1ed0..16800aa 100644 --- a/ethpm_cli/main.py +++ b/ethpm_cli/main.py @@ -10,7 +10,7 @@ from ethpm_cli._utils.xdg import get_xdg_ethpmcli_root from ethpm_cli.constants import INFURA_HTTP_URI -from ethpm_cli.install import Config, install_package +from ethpm_cli.install import Config, install_package, list_installed_packages from ethpm_cli.package import Package from ethpm_cli.scraper import scrape from ethpm_cli.validation import validate_install_cli_args @@ -68,6 +68,7 @@ def parse_arguments() -> argparse.ArgumentParser: type=int, help="Block number to begin scraping from.", ) + install_parser = subparsers.add_parser("install", help="Install uri") install_parser.add_argument( "uri", @@ -91,6 +92,15 @@ def parse_arguments() -> argparse.ArgumentParser: action="store_true", help="Flag to use locally running IPFS node.", ) + + list_parser = subparsers.add_parser("list", help="List installed packages") + list_parser.add_argument( + "--ethpm-dir", + dest="ethpm_dir", + action="store", + type=Path, + help="Path to specific ethpm_packages dir.", + ) return parser @@ -111,8 +121,11 @@ def main() -> None: args.uri, config.ethpm_dir, ) - if args.command == "scrape": + elif args.command == "scrape": scraper(args) + elif args.command == "list": + config = Config(args) + list_installed_packages(config) else: parser.error( "%s is an invalid command. Use `ethpmcli --help` to " diff --git a/tests/core/test_install.py b/tests/core/test_install.py index 4046513..3153a40 100644 --- a/tests/core/test_install.py +++ b/tests/core/test_install.py @@ -1,11 +1,17 @@ from argparse import Namespace +import logging from pathlib import Path import pytest from ethpm_cli._utils.testing import check_dir_trees_equal from ethpm_cli.exceptions import InstallError -from ethpm_cli.install import Config, install_package, uninstall_package +from ethpm_cli.install import ( + Config, + install_package, + list_installed_packages, + uninstall_package, +) from ethpm_cli.package import Package @@ -29,6 +35,7 @@ def owned_pkg(config): config.ipfs_backend, ) + @pytest.fixture def wallet_pkg(config): return Package( @@ -37,6 +44,7 @@ def wallet_pkg(config): config.ipfs_backend, ) + @pytest.mark.parametrize( "uri,pkg_name,alias,install_type", ( @@ -113,23 +121,33 @@ def test_install_multiple_packages(config, test_assets_dir, owned_pkg, wallet_pk ) -@pytest.mark.parametrize( - "uninstall,keep", - ( - ("wallet", "owned"), - ("owned", "wallet"), - ) -) -def test_uninstall_packages(uninstall, keep, config, test_assets_dir, owned_pkg, wallet_pkg): +@pytest.mark.parametrize("uninstall,keep", (("wallet", "owned"), ("owned", "wallet"))) +def test_uninstall_packages( + uninstall, keep, config, test_assets_dir, owned_pkg, wallet_pkg +): install_package(owned_pkg, config) install_package(wallet_pkg, config) uninstall_package(uninstall, config) assert (config.ethpm_dir / keep).is_dir() assert not (config.ethpm_dir / uninstall).is_dir() - assert check_dir_trees_equal(config.ethpm_dir, (test_assets_dir / keep / "ipfs_uri" / "ethpm_packages")) + assert check_dir_trees_equal( + config.ethpm_dir, (test_assets_dir / keep / "ipfs_uri" / "ethpm_packages") + ) def test_uninstall_package_warns_if_package_doesnt_exist(config): with pytest.raises(InstallError, match="Unable to uninstall"): uninstall_package("invalid", config) + + +def test_list(config, owned_pkg, wallet_pkg, caplog): + install_package(owned_pkg, config) + install_package(wallet_pkg, config) + + with caplog.at_level(logging.INFO): + list_installed_packages(config) + assert "-- " in caplog.text + assert "------ " in caplog.text + assert "------ " in caplog.text + assert "-- " in caplog.text diff --git a/tox.ini b/tox.ini index 1abeff7..cc59a2d 100644 --- a/tox.ini +++ b/tox.ini @@ -43,4 +43,4 @@ commands= flake8 {toxinidir}/ethpm_cli {toxinidir}/tests mypy --follow-imports=silent --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p ethpm_cli black --check --diff {toxinidir}/ethpm_cli/ --check --diff {toxinidir}/tests/ - isort --check-only --recursive {toxinidir}/ethpm_cli/ {toxinidir}/tests/ + isort --check-only --recursive --diff {toxinidir}/ethpm_cli/ {toxinidir}/tests/ From 1a999df5801b780ed641f815f8bbfd4993743365 Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Fri, 17 May 2019 12:18:00 +0200 Subject: [PATCH 3/4] Refactor ethpm list --- ethpm_cli/_utils/terminal.py | 10 ++++ ethpm_cli/config.py | 22 ++++++++ ethpm_cli/install.py | 106 ++++++++++++++++++++++++----------- ethpm_cli/main.py | 64 ++------------------- ethpm_cli/parser.py | 59 +++++++++++++++++++ setup.py | 3 +- tests/core/test_install.py | 20 +++++-- 7 files changed, 185 insertions(+), 99 deletions(-) create mode 100644 ethpm_cli/_utils/terminal.py create mode 100644 ethpm_cli/config.py create mode 100644 ethpm_cli/parser.py diff --git a/ethpm_cli/_utils/terminal.py b/ethpm_cli/_utils/terminal.py new file mode 100644 index 0000000..9d15f26 --- /dev/null +++ b/ethpm_cli/_utils/terminal.py @@ -0,0 +1,10 @@ +import os +import sys + + +def get_terminal_width() -> int: + if sys.stdin.isatty(): + _, columns = os.popen("stty size", "r").read().split() + else: + columns = "100" + return int(columns) diff --git a/ethpm_cli/config.py b/ethpm_cli/config.py new file mode 100644 index 0000000..ddda78b --- /dev/null +++ b/ethpm_cli/config.py @@ -0,0 +1,22 @@ +from argparse import Namespace +from pathlib import Path + +from ethpm_cli._utils.ipfs import get_ipfs_backend +from ethpm_cli.constants import ETHPM_DIR_NAME + + +class Config: + """ + Class to manage CLI config options + - IPFS Backend + - Target ethpm_dir + """ + + def __init__(self, args: Namespace) -> None: + self.ipfs_backend = get_ipfs_backend(args.local_ipfs) + if args.ethpm_dir is None: + self.ethpm_dir = Path.cwd() / ETHPM_DIR_NAME + if not self.ethpm_dir.is_dir(): + self.ethpm_dir.mkdir() + else: + self.ethpm_dir = args.ethpm_dir diff --git a/ethpm_cli/install.py b/ethpm_cli/install.py index fa07b63..6d982ed 100644 --- a/ethpm_cli/install.py +++ b/ethpm_cli/install.py @@ -1,18 +1,19 @@ -from argparse import Namespace +from collections import namedtuple import json import logging import os from pathlib import Path import shutil import tempfile -from typing import Iterable, Tuple +from typing import Any, Dict, Iterable, Tuple from eth_utils import to_dict, to_list, to_text from eth_utils.toolz import assoc, dissoc from ethpm.backends.ipfs import BaseIPFSBackend from ethpm.utils.ipfs import is_ipfs_uri -from ethpm_cli._utils.ipfs import get_ipfs_backend +from ethpm_cli._utils.terminal import get_terminal_width +from ethpm_cli.config import Config from ethpm_cli.constants import ETHPM_DIR_NAME from ethpm_cli.exceptions import InstallError from ethpm_cli.package import Package @@ -21,27 +22,6 @@ logger = logging.getLogger("ethpm_cli.install") -class Config: - """ - Class to manage CLI config options - - IPFS Backend - - Target ethpm_dir - """ - - def __init__(self, args: Namespace) -> None: - if "local_ipfs" in args: - self.ipfs_backend = get_ipfs_backend(args.local_ipfs) - else: - self.ipfs_backend = get_ipfs_backend(True) - - if args.ethpm_dir is None: - self.ethpm_dir = Path.cwd() / ETHPM_DIR_NAME - if not self.ethpm_dir.is_dir(): - self.ethpm_dir.mkdir() - else: - self.ethpm_dir = args.ethpm_dir - - def install_package(pkg: Package, config: Config) -> None: if is_package_installed(pkg.alias, config): raise InstallError( @@ -61,18 +41,71 @@ def install_package(pkg: Package, config: Config) -> None: install_to_ethpm_lock(pkg, (config.ethpm_dir / "ethpm.lock")) +_InstalledPackageTree = namedtuple( + "InstalledPackageTree", "depth path manifest children content_hash" +) + + +class InstalledPackageTree(_InstalledPackageTree): + depth: int + path: Path + manifest: Dict[str, Any] + children: Tuple["InstalledPackageTree", ...] + content_hash: str + + @property + def package_name(self) -> str: + return self.manifest["package_name"] + + @property + def package_version(self) -> str: + return self.manifest["version"] + + @property + def format_for_display(self) -> str: + prefix = "- " * self.depth + columns = get_terminal_width() + main_info = f"{prefix}{self.package_name}=={self.package_version}..." + hash_info = f"({self.content_hash})" + diff = columns - len(main_info) - len(hash_info) + if self.children: + children = "\n" + "\n".join( + (child.format_for_display for child in self.children) + ) + else: + children = "" + return f"{main_info}{'.' * diff}{hash_info}{children}" + + def list_installed_packages(config: Config) -> None: - for pkg_data in get_installed_packages(config.ethpm_dir): - logger.info(pkg_data) + installed_packages = [ + get_installed_package_tree(base_dir) + for base_dir in config.ethpm_dir.glob("*/") + if base_dir.is_dir() + ] + for pkg in sorted(installed_packages): + logger.info(pkg.format_for_display) + + +def get_installed_package_tree(base_dir: Path, depth: int = 0) -> InstalledPackageTree: + manifest = json.loads((base_dir / "manifest.json").read_text()) + ethpm_lock = json.loads((base_dir.parent / "ethpm.lock").read_text()) + content_hash = ethpm_lock[base_dir.name]["resolved_uri"] + dependency_dirs = get_dependency_dirs(base_dir) + children = tuple( + get_installed_package_tree(dependency_dir, depth + 1) + for dependency_dir in dependency_dirs + ) + return InstalledPackageTree(depth, base_dir, manifest, children, content_hash) @to_list -def get_installed_packages(ethpm_dir: Path) -> Iterable[str]: - installed_pkgs = reversed(sorted(ethpm_dir.glob("**/manifest.json"))) - for manifest_path in installed_pkgs: - manifest = json.loads(manifest_path.read_text()) - num_deep = str(manifest_path.relative_to(ethpm_dir)).count("/") - yield f"{num_deep * '--'} " +def get_dependency_dirs(base_dir: Path) -> Iterable[Path]: + dep_dir = base_dir / "ethpm_packages" + if dep_dir.is_dir(): + for ddir in dep_dir.glob("*/"): + if ddir.is_dir() and ddir.name != "src": + yield ddir def is_package_installed(package_name: str, config: Config) -> bool: @@ -85,8 +118,13 @@ def uninstall_package(package_name: str, config: Config) -> None: f"Unable to uninstall {package_name} from {config.ethpm_dir}" ) - shutil.rmtree(config.ethpm_dir / package_name) - uninstall_from_ethpm_lock(package_name, (config.ethpm_dir / "ethpm.lock")) + tmp_pkg_dir = Path(tempfile.mkdtemp()) / "ethpm_packages" + shutil.copytree(config.ethpm_dir, tmp_pkg_dir) + shutil.rmtree(tmp_pkg_dir / package_name) + uninstall_from_ethpm_lock(package_name, (tmp_pkg_dir / "ethpm.lock")) + + shutil.rmtree(config.ethpm_dir) + tmp_pkg_dir.replace(config.ethpm_dir) def write_pkg_installation_files( diff --git a/ethpm_cli/main.py b/ethpm_cli/main.py index 16800aa..13492fb 100644 --- a/ethpm_cli/main.py +++ b/ethpm_cli/main.py @@ -1,6 +1,5 @@ import argparse import logging -from pathlib import Path import sys import pkg_resources @@ -9,9 +8,11 @@ from web3.providers.auto import load_provider_from_uri from ethpm_cli._utils.xdg import get_xdg_ethpmcli_root +from ethpm_cli.config import Config from ethpm_cli.constants import INFURA_HTTP_URI -from ethpm_cli.install import Config, install_package, list_installed_packages +from ethpm_cli.install import install_package, list_installed_packages from ethpm_cli.package import Package +from ethpm_cli.parser import get_ethpm_parser from ethpm_cli.scraper import scrape from ethpm_cli.validation import validate_install_cli_args @@ -47,66 +48,9 @@ def scraper(args: argparse.Namespace) -> None: ) -def parse_arguments() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description="ethpm-cli") - subparsers = parser.add_subparsers(help="commands", dest="command") - - scrape_parser = subparsers.add_parser( - "scrape", help="Scrape for new VersionRelease events." - ) - scrape_parser.add_argument( - "--ipfs-dir", - dest="ipfs_dir", - action="store", - type=Path, - help="path to specific IPFS assets dir.", - ) - scrape_parser.add_argument( - "--start-block", - dest="start_block", - action="store", - type=int, - help="Block number to begin scraping from.", - ) - - install_parser = subparsers.add_parser("install", help="Install uri") - install_parser.add_argument( - "uri", - action="store", - type=str, - help="IPFS / Github / Registry URI of package you want to install.", - ) - install_parser.add_argument( - "--ethpm-dir", - dest="ethpm_dir", - action="store", - type=Path, - help="Path to specific ethpm_packages dir.", - ) - install_parser.add_argument( - "--alias", action="store", type=str, help="Alias for installing package." - ) - install_parser.add_argument( - "--local-ipfs", - dest="local_ipfs", - action="store_true", - help="Flag to use locally running IPFS node.", - ) - - list_parser = subparsers.add_parser("list", help="List installed packages") - list_parser.add_argument( - "--ethpm-dir", - dest="ethpm_dir", - action="store", - type=Path, - help="Path to specific ethpm_packages dir.", - ) - return parser - - def main() -> None: logger = setup_cli_logger() - parser = parse_arguments() + parser = get_ethpm_parser() logger.info(f"EthPM CLI v{__version__}\n") args = parser.parse_args() diff --git a/ethpm_cli/parser.py b/ethpm_cli/parser.py new file mode 100644 index 0000000..17228dd --- /dev/null +++ b/ethpm_cli/parser.py @@ -0,0 +1,59 @@ +import argparse +from pathlib import Path + + +def get_ethpm_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="ethpm-cli") + subparsers = parser.add_subparsers(help="commands", dest="command") + + scrape_parser = subparsers.add_parser( + "scrape", help="Scrape for new VersionRelease events." + ) + scrape_parser.add_argument( + "--ipfs-dir", + dest="ipfs_dir", + action="store", + type=Path, + help="path to specific IPFS assets dir.", + ) + scrape_parser.add_argument( + "--start-block", + dest="start_block", + action="store", + type=int, + help="Block number to begin scraping from.", + ) + + install_parser = subparsers.add_parser("install", help="Install uri") + install_parser.add_argument( + "uri", + action="store", + type=str, + help="IPFS / Github / Registry URI of package you want to install.", + ) + install_parser.add_argument( + "--ethpm-dir", + dest="ethpm_dir", + action="store", + type=Path, + help="Path to specific ethpm_packages dir.", + ) + install_parser.add_argument( + "--alias", action="store", type=str, help="Alias for installing package." + ) + install_parser.add_argument( + "--local-ipfs", + dest="local_ipfs", + action="store_true", + help="Flag to use locally running IPFS node.", + ) + + list_parser = subparsers.add_parser("list", help="List installed packages") + list_parser.add_argument( + "--ethpm-dir", + dest="ethpm_dir", + action="store", + type=Path, + help="Path to specific ethpm_packages dir.", + ) + return parser diff --git a/setup.py b/setup.py index 5ba7823..8624755 100644 --- a/setup.py +++ b/setup.py @@ -49,9 +49,10 @@ url='https://github.com/ethereum/ethpm-cli', include_package_data=True, install_requires=[ + "certifi>=2019.3.9,<2020", "eth-hash[pysha3]>=0.2.0,<1", "eth-utils>=1,<2", - "ethpm>=0.1.4-a15,<2", + "ethpm>=0.1.4-a16,<2", ], setup_requires=['setuptools-markdown'], python_requires='>=3.6, <4', diff --git a/tests/core/test_install.py b/tests/core/test_install.py index 3153a40..02c09c2 100644 --- a/tests/core/test_install.py +++ b/tests/core/test_install.py @@ -147,7 +147,19 @@ def test_list(config, owned_pkg, wallet_pkg, caplog): with caplog.at_level(logging.INFO): list_installed_packages(config) - assert "-- " in caplog.text - assert "------ " in caplog.text - assert "------ " in caplog.text - assert "-- " in caplog.text + assert "owned==1.0.0..." in caplog.text + assert "wallet==1.0.0..." in caplog.text + assert "- safe-math-lib==1.0.0..." in caplog.text + assert "- owned==1.0.0..." in caplog.text + assert ( + "(ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW)\n" in caplog.text + ) + assert ( + "(ipfs://QmRMSm4k37mr2T3A2MGxAj2eAHGR5veibVt1t9Leh5waV1)\n" in caplog.text + ) + assert ( + "(ipfs://QmWgvM8yXGyHoGWqLFXvareJsoCZVsdrpKNCLMun3RaSJm)\n" in caplog.text + ) + assert ( + "(ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW)\n" in caplog.text + ) From 24bb48b9b56f858448783627292d673e3640452c Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Wed, 22 May 2019 11:50:27 +0200 Subject: [PATCH 4/4] Remove naming conflict b/w dir names and package names --- ethpm_cli/_utils/ipfs.py | 2 +- ethpm_cli/_utils/terminal.py | 10 ---- ethpm_cli/config.py | 6 ++- ethpm_cli/constants.py | 7 ++- ethpm_cli/install.py | 53 ++++++++----------- ethpm_cli/main.py | 4 +- ethpm_cli/parser.py | 3 ++ .../ethpm.lock | 0 .../owned/_src}/contracts/Owned.sol | 0 .../owned/manifest.json | 0 .../wallet/_ethpm_packages}/ethpm.lock | 0 .../owned/_src}/contracts/Owned.sol | 0 .../_ethpm_packages}/owned/manifest.json | 0 .../_src}/contracts/SafeMathLib.sol | 0 .../safe-math-lib/manifest.json | 0 .../wallet/_src}/contracts/Wallet.sol | 0 .../wallet/manifest.json | 0 .../ethpm.lock | 0 .../owned/_src}/contracts/Owned.sol | 0 .../owned/manifest.json | 0 .../ethpm.lock | 0 .../owned-alias/_src}/contracts/Owned.sol | 0 .../owned-alias/manifest.json | 0 .../ethpm.lock | 0 .../owned/_src}/contracts/Owned.sol | 0 .../owned/manifest.json | 0 .../ethpm.lock | 0 .../wallet/_ethpm_packages}/ethpm.lock | 0 .../owned/_src}/contracts/Owned.sol | 0 .../_ethpm_packages}/owned/manifest.json | 0 .../_src}/contracts/SafeMathLib.sol | 0 .../safe-math-lib/manifest.json | 0 .../wallet/_src}/contracts/Wallet.sol | 0 .../wallet/manifest.json | 0 tests/core/conftest.py | 4 +- tests/core/test_install.py | 39 +++++++------- 36 files changed, 62 insertions(+), 66 deletions(-) delete mode 100644 ethpm_cli/_utils/terminal.py rename tests/core/assets/multiple/{ethpm_packages => _ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/multiple/{ethpm_packages/owned/src => _ethpm_packages/owned/_src}/contracts/Owned.sol (100%) rename tests/core/assets/multiple/{ethpm_packages => _ethpm_packages}/owned/manifest.json (100%) rename tests/core/assets/multiple/{ethpm_packages/wallet/ethpm_packages => _ethpm_packages/wallet/_ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/multiple/{ethpm_packages/wallet/ethpm_packages/owned/src => _ethpm_packages/wallet/_ethpm_packages/owned/_src}/contracts/Owned.sol (100%) rename tests/core/assets/multiple/{ethpm_packages/wallet/ethpm_packages => _ethpm_packages/wallet/_ethpm_packages}/owned/manifest.json (100%) rename tests/core/assets/multiple/{ethpm_packages/wallet/ethpm_packages/safe-math-lib/src => _ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src}/contracts/SafeMathLib.sol (100%) rename tests/core/assets/multiple/{ethpm_packages/wallet/ethpm_packages => _ethpm_packages/wallet/_ethpm_packages}/safe-math-lib/manifest.json (100%) rename tests/core/assets/multiple/{ethpm_packages/wallet/src => _ethpm_packages/wallet/_src}/contracts/Wallet.sol (100%) rename tests/core/assets/multiple/{ethpm_packages => _ethpm_packages}/wallet/manifest.json (100%) rename tests/core/assets/owned/ipfs_uri/{ethpm_packages => _ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/owned/ipfs_uri/{ethpm_packages/owned/src => _ethpm_packages/owned/_src}/contracts/Owned.sol (100%) rename tests/core/assets/owned/ipfs_uri/{ethpm_packages => _ethpm_packages}/owned/manifest.json (100%) rename tests/core/assets/owned/ipfs_uri_alias/{ethpm_packages => _ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/owned/ipfs_uri_alias/{ethpm_packages/owned-alias/src => _ethpm_packages/owned-alias/_src}/contracts/Owned.sol (100%) rename tests/core/assets/owned/ipfs_uri_alias/{ethpm_packages => _ethpm_packages}/owned-alias/manifest.json (100%) rename tests/core/assets/owned/registry_uri/{ethpm_packages => _ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/owned/registry_uri/{ethpm_packages/owned/src => _ethpm_packages/owned/_src}/contracts/Owned.sol (100%) rename tests/core/assets/owned/registry_uri/{ethpm_packages => _ethpm_packages}/owned/manifest.json (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages => _ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages/wallet/ethpm_packages => _ethpm_packages/wallet/_ethpm_packages}/ethpm.lock (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages/wallet/ethpm_packages/owned/src => _ethpm_packages/wallet/_ethpm_packages/owned/_src}/contracts/Owned.sol (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages/wallet/ethpm_packages => _ethpm_packages/wallet/_ethpm_packages}/owned/manifest.json (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages/wallet/ethpm_packages/safe-math-lib/src => _ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src}/contracts/SafeMathLib.sol (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages/wallet/ethpm_packages => _ethpm_packages/wallet/_ethpm_packages}/safe-math-lib/manifest.json (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages/wallet/src => _ethpm_packages/wallet/_src}/contracts/Wallet.sol (100%) rename tests/core/assets/wallet/ipfs_uri/{ethpm_packages => _ethpm_packages}/wallet/manifest.json (100%) diff --git a/ethpm_cli/_utils/ipfs.py b/ethpm_cli/_utils/ipfs.py index 83c2545..de41a64 100644 --- a/ethpm_cli/_utils/ipfs.py +++ b/ethpm_cli/_utils/ipfs.py @@ -1,7 +1,7 @@ from ethpm.backends.ipfs import BaseIPFSBackend, InfuraIPFSBackend, LocalIPFSBackend -def get_ipfs_backend(ipfs: bool = None) -> BaseIPFSBackend: +def get_ipfs_backend(ipfs: bool = False) -> BaseIPFSBackend: if ipfs: return LocalIPFSBackend() return InfuraIPFSBackend() diff --git a/ethpm_cli/_utils/terminal.py b/ethpm_cli/_utils/terminal.py deleted file mode 100644 index 9d15f26..0000000 --- a/ethpm_cli/_utils/terminal.py +++ /dev/null @@ -1,10 +0,0 @@ -import os -import sys - - -def get_terminal_width() -> int: - if sys.stdin.isatty(): - _, columns = os.popen("stty size", "r").read().split() - else: - columns = "100" - return int(columns) diff --git a/ethpm_cli/config.py b/ethpm_cli/config.py index ddda78b..2fc8964 100644 --- a/ethpm_cli/config.py +++ b/ethpm_cli/config.py @@ -13,7 +13,11 @@ class Config: """ def __init__(self, args: Namespace) -> None: - self.ipfs_backend = get_ipfs_backend(args.local_ipfs) + if "local_ipfs" in args: + self.ipfs_backend = get_ipfs_backend(args.local_ipfs) + else: + self.ipfs_backend = get_ipfs_backend() + if args.ethpm_dir is None: self.ethpm_dir = Path.cwd() / ETHPM_DIR_NAME if not self.ethpm_dir.is_dir(): diff --git a/ethpm_cli/constants.py b/ethpm_cli/constants.py index ccf5c36..077f026 100644 --- a/ethpm_cli/constants.py +++ b/ethpm_cli/constants.py @@ -4,9 +4,12 @@ from ethpm_cli import CLI_ASSETS_DIR -ETHPM_DIR_NAME = "ethpm_packages" -ETHPM_ASSETS_DIR = "packages" +ETHPM_DIR_NAME = "_ethpm_packages" IPFS_ASSETS_DIR = "ipfs" +LOCKFILE_NAME = "ethpm.lock" +SRC_DIR_NAME = "_src" + + VERSION_RELEASE_ABI = json.loads((CLI_ASSETS_DIR / "1.0.1.json").read_text())[ "contract_types" ]["Log"]["abi"] diff --git a/ethpm_cli/install.py b/ethpm_cli/install.py index 6d982ed..1d938d0 100644 --- a/ethpm_cli/install.py +++ b/ethpm_cli/install.py @@ -1,20 +1,18 @@ -from collections import namedtuple import json import logging import os from pathlib import Path import shutil import tempfile -from typing import Any, Dict, Iterable, Tuple +from typing import Any, Dict, Iterable, NamedTuple, Tuple -from eth_utils import to_dict, to_list, to_text +from eth_utils import to_dict, to_text, to_tuple from eth_utils.toolz import assoc, dissoc from ethpm.backends.ipfs import BaseIPFSBackend from ethpm.utils.ipfs import is_ipfs_uri -from ethpm_cli._utils.terminal import get_terminal_width from ethpm_cli.config import Config -from ethpm_cli.constants import ETHPM_DIR_NAME +from ethpm_cli.constants import ETHPM_DIR_NAME, LOCKFILE_NAME, SRC_DIR_NAME from ethpm_cli.exceptions import InstallError from ethpm_cli.package import Package from ethpm_cli.validation import validate_parent_directory @@ -38,19 +36,14 @@ def install_package(pkg: Package, config: Config) -> None: dest_pkg_dir = config.ethpm_dir / pkg.alias validate_parent_directory(config.ethpm_dir, dest_pkg_dir) shutil.copytree(tmp_pkg_dir, dest_pkg_dir) - install_to_ethpm_lock(pkg, (config.ethpm_dir / "ethpm.lock")) + install_to_ethpm_lock(pkg, (config.ethpm_dir / LOCKFILE_NAME)) -_InstalledPackageTree = namedtuple( - "InstalledPackageTree", "depth path manifest children content_hash" -) - - -class InstalledPackageTree(_InstalledPackageTree): +class InstalledPackageTree(NamedTuple): depth: int path: Path manifest: Dict[str, Any] - children: Tuple["InstalledPackageTree", ...] + children: Tuple[Any, ...] # Expects InstalledPackageTree content_hash: str @property @@ -64,23 +57,21 @@ def package_version(self) -> str: @property def format_for_display(self) -> str: prefix = "- " * self.depth - columns = get_terminal_width() - main_info = f"{prefix}{self.package_name}=={self.package_version}..." + main_info = f"{prefix}{self.package_name}=={self.package_version}" hash_info = f"({self.content_hash})" - diff = columns - len(main_info) - len(hash_info) if self.children: children = "\n" + "\n".join( (child.format_for_display for child in self.children) ) else: children = "" - return f"{main_info}{'.' * diff}{hash_info}{children}" + return f"{main_info} --- {hash_info}{children}" def list_installed_packages(config: Config) -> None: installed_packages = [ get_installed_package_tree(base_dir) - for base_dir in config.ethpm_dir.glob("*/") + for base_dir in config.ethpm_dir.iterdir() if base_dir.is_dir() ] for pkg in sorted(installed_packages): @@ -89,7 +80,7 @@ def list_installed_packages(config: Config) -> None: def get_installed_package_tree(base_dir: Path, depth: int = 0) -> InstalledPackageTree: manifest = json.loads((base_dir / "manifest.json").read_text()) - ethpm_lock = json.loads((base_dir.parent / "ethpm.lock").read_text()) + ethpm_lock = json.loads((base_dir.parent / LOCKFILE_NAME).read_text()) content_hash = ethpm_lock[base_dir.name]["resolved_uri"] dependency_dirs = get_dependency_dirs(base_dir) children = tuple( @@ -99,12 +90,12 @@ def get_installed_package_tree(base_dir: Path, depth: int = 0) -> InstalledPacka return InstalledPackageTree(depth, base_dir, manifest, children, content_hash) -@to_list +@to_tuple def get_dependency_dirs(base_dir: Path) -> Iterable[Path]: - dep_dir = base_dir / "ethpm_packages" + dep_dir = base_dir / ETHPM_DIR_NAME if dep_dir.is_dir(): - for ddir in dep_dir.glob("*/"): - if ddir.is_dir() and ddir.name != "src": + for ddir in dep_dir.iterdir(): + if ddir.is_dir(): yield ddir @@ -115,13 +106,13 @@ def is_package_installed(package_name: str, config: Config) -> bool: def uninstall_package(package_name: str, config: Config) -> None: if not is_package_installed(package_name, config): raise InstallError( - f"Unable to uninstall {package_name} from {config.ethpm_dir}" + f"No package with the name {package_name} found installed under {config.ethpm_dir}." ) - tmp_pkg_dir = Path(tempfile.mkdtemp()) / "ethpm_packages" + tmp_pkg_dir = Path(tempfile.mkdtemp()) / ETHPM_DIR_NAME shutil.copytree(config.ethpm_dir, tmp_pkg_dir) shutil.rmtree(tmp_pkg_dir / package_name) - uninstall_from_ethpm_lock(package_name, (tmp_pkg_dir / "ethpm.lock")) + uninstall_from_ethpm_lock(package_name, (tmp_pkg_dir / LOCKFILE_NAME)) shutil.rmtree(config.ethpm_dir) tmp_pkg_dir.replace(config.ethpm_dir) @@ -135,7 +126,7 @@ def write_pkg_installation_files( write_sources_to_disk(pkg, tmp_pkg_dir, ipfs_backend) write_build_deps_to_disk(pkg, tmp_pkg_dir, ipfs_backend) - tmp_ethpm_lock = tmp_pkg_dir.parent / "ethpm.lock" + tmp_ethpm_lock = tmp_pkg_dir.parent / LOCKFILE_NAME install_to_ethpm_lock(pkg, tmp_ethpm_lock) @@ -144,12 +135,12 @@ def write_sources_to_disk( ) -> None: sources = resolve_sources(pkg, ipfs_backend) for path, source_contents in sources.items(): - target_file = pkg_dir / "src" / path + target_file = pkg_dir / SRC_DIR_NAME / path target_dir = target_file.parent if not target_dir.is_dir(): target_dir.mkdir(parents=True) target_file.touch() - validate_parent_directory((pkg_dir / "src"), target_file) + validate_parent_directory((pkg_dir / SRC_DIR_NAME), target_file) target_file.write_text(source_contents) @@ -194,4 +185,6 @@ def install_to_ethpm_lock(pkg: Package, ethpm_lock: Path) -> None: def uninstall_from_ethpm_lock(package_name: str, ethpm_lock: Path) -> None: old_lock = json.loads(ethpm_lock.read_text()) new_lock = dissoc(old_lock, package_name) - ethpm_lock.write_text(f"{json.dumps(new_lock, sort_keys=True, indent=4)}\n") + temp_ethpm_lock = Path(tempfile.NamedTemporaryFile().name) + temp_ethpm_lock.write_text(f"{json.dumps(new_lock, sort_keys=True, indent=4)}\n") + temp_ethpm_lock.replace(ethpm_lock) diff --git a/ethpm_cli/main.py b/ethpm_cli/main.py index 13492fb..c3f536d 100644 --- a/ethpm_cli/main.py +++ b/ethpm_cli/main.py @@ -12,7 +12,7 @@ from ethpm_cli.constants import INFURA_HTTP_URI from ethpm_cli.install import install_package, list_installed_packages from ethpm_cli.package import Package -from ethpm_cli.parser import get_ethpm_parser +from ethpm_cli.parser import ETHPM_PARSER from ethpm_cli.scraper import scrape from ethpm_cli.validation import validate_install_cli_args @@ -50,7 +50,7 @@ def scraper(args: argparse.Namespace) -> None: def main() -> None: logger = setup_cli_logger() - parser = get_ethpm_parser() + parser = ETHPM_PARSER logger.info(f"EthPM CLI v{__version__}\n") args = parser.parse_args() diff --git a/ethpm_cli/parser.py b/ethpm_cli/parser.py index 17228dd..cf34be8 100644 --- a/ethpm_cli/parser.py +++ b/ethpm_cli/parser.py @@ -57,3 +57,6 @@ def get_ethpm_parser() -> argparse.ArgumentParser: help="Path to specific ethpm_packages dir.", ) return parser + + +ETHPM_PARSER = get_ethpm_parser() diff --git a/tests/core/assets/multiple/ethpm_packages/ethpm.lock b/tests/core/assets/multiple/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/ethpm.lock rename to tests/core/assets/multiple/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/multiple/ethpm_packages/owned/src/contracts/Owned.sol b/tests/core/assets/multiple/_ethpm_packages/owned/_src/contracts/Owned.sol similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/owned/src/contracts/Owned.sol rename to tests/core/assets/multiple/_ethpm_packages/owned/_src/contracts/Owned.sol diff --git a/tests/core/assets/multiple/ethpm_packages/owned/manifest.json b/tests/core/assets/multiple/_ethpm_packages/owned/manifest.json similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/owned/manifest.json rename to tests/core/assets/multiple/_ethpm_packages/owned/manifest.json diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/ethpm.lock b/tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/ethpm.lock rename to tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/owned/src/contracts/Owned.sol b/tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/owned/_src/contracts/Owned.sol similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/owned/src/contracts/Owned.sol rename to tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/owned/_src/contracts/Owned.sol diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/owned/manifest.json b/tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/owned/manifest.json rename to tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/safe-math-lib/src/contracts/SafeMathLib.sol b/tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/contracts/SafeMathLib.sol similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/safe-math-lib/src/contracts/SafeMathLib.sol rename to tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/contracts/SafeMathLib.sol diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/safe-math-lib/manifest.json b/tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/ethpm_packages/safe-math-lib/manifest.json rename to tests/core/assets/multiple/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/src/contracts/Wallet.sol b/tests/core/assets/multiple/_ethpm_packages/wallet/_src/contracts/Wallet.sol similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/src/contracts/Wallet.sol rename to tests/core/assets/multiple/_ethpm_packages/wallet/_src/contracts/Wallet.sol diff --git a/tests/core/assets/multiple/ethpm_packages/wallet/manifest.json b/tests/core/assets/multiple/_ethpm_packages/wallet/manifest.json similarity index 100% rename from tests/core/assets/multiple/ethpm_packages/wallet/manifest.json rename to tests/core/assets/multiple/_ethpm_packages/wallet/manifest.json diff --git a/tests/core/assets/owned/ipfs_uri/ethpm_packages/ethpm.lock b/tests/core/assets/owned/ipfs_uri/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/owned/ipfs_uri/ethpm_packages/ethpm.lock rename to tests/core/assets/owned/ipfs_uri/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/owned/ipfs_uri/ethpm_packages/owned/src/contracts/Owned.sol b/tests/core/assets/owned/ipfs_uri/_ethpm_packages/owned/_src/contracts/Owned.sol similarity index 100% rename from tests/core/assets/owned/ipfs_uri/ethpm_packages/owned/src/contracts/Owned.sol rename to tests/core/assets/owned/ipfs_uri/_ethpm_packages/owned/_src/contracts/Owned.sol diff --git a/tests/core/assets/owned/ipfs_uri/ethpm_packages/owned/manifest.json b/tests/core/assets/owned/ipfs_uri/_ethpm_packages/owned/manifest.json similarity index 100% rename from tests/core/assets/owned/ipfs_uri/ethpm_packages/owned/manifest.json rename to tests/core/assets/owned/ipfs_uri/_ethpm_packages/owned/manifest.json diff --git a/tests/core/assets/owned/ipfs_uri_alias/ethpm_packages/ethpm.lock b/tests/core/assets/owned/ipfs_uri_alias/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/owned/ipfs_uri_alias/ethpm_packages/ethpm.lock rename to tests/core/assets/owned/ipfs_uri_alias/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/owned/ipfs_uri_alias/ethpm_packages/owned-alias/src/contracts/Owned.sol b/tests/core/assets/owned/ipfs_uri_alias/_ethpm_packages/owned-alias/_src/contracts/Owned.sol similarity index 100% rename from tests/core/assets/owned/ipfs_uri_alias/ethpm_packages/owned-alias/src/contracts/Owned.sol rename to tests/core/assets/owned/ipfs_uri_alias/_ethpm_packages/owned-alias/_src/contracts/Owned.sol diff --git a/tests/core/assets/owned/ipfs_uri_alias/ethpm_packages/owned-alias/manifest.json b/tests/core/assets/owned/ipfs_uri_alias/_ethpm_packages/owned-alias/manifest.json similarity index 100% rename from tests/core/assets/owned/ipfs_uri_alias/ethpm_packages/owned-alias/manifest.json rename to tests/core/assets/owned/ipfs_uri_alias/_ethpm_packages/owned-alias/manifest.json diff --git a/tests/core/assets/owned/registry_uri/ethpm_packages/ethpm.lock b/tests/core/assets/owned/registry_uri/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/owned/registry_uri/ethpm_packages/ethpm.lock rename to tests/core/assets/owned/registry_uri/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/owned/registry_uri/ethpm_packages/owned/src/contracts/Owned.sol b/tests/core/assets/owned/registry_uri/_ethpm_packages/owned/_src/contracts/Owned.sol similarity index 100% rename from tests/core/assets/owned/registry_uri/ethpm_packages/owned/src/contracts/Owned.sol rename to tests/core/assets/owned/registry_uri/_ethpm_packages/owned/_src/contracts/Owned.sol diff --git a/tests/core/assets/owned/registry_uri/ethpm_packages/owned/manifest.json b/tests/core/assets/owned/registry_uri/_ethpm_packages/owned/manifest.json similarity index 100% rename from tests/core/assets/owned/registry_uri/ethpm_packages/owned/manifest.json rename to tests/core/assets/owned/registry_uri/_ethpm_packages/owned/manifest.json diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/ethpm.lock b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/ethpm.lock rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/ethpm.lock b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/ethpm.lock rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/owned/src/contracts/Owned.sol b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/owned/_src/contracts/Owned.sol similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/owned/src/contracts/Owned.sol rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/owned/_src/contracts/Owned.sol diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/owned/manifest.json b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/owned/manifest.json rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/safe-math-lib/src/contracts/SafeMathLib.sol b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/contracts/SafeMathLib.sol similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/safe-math-lib/src/contracts/SafeMathLib.sol rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/contracts/SafeMathLib.sol diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/safe-math-lib/manifest.json b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/ethpm_packages/safe-math-lib/manifest.json rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/src/contracts/Wallet.sol b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_src/contracts/Wallet.sol similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/src/contracts/Wallet.sol rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/_src/contracts/Wallet.sol diff --git a/tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/manifest.json b/tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/manifest.json similarity index 100% rename from tests/core/assets/wallet/ipfs_uri/ethpm_packages/wallet/manifest.json rename to tests/core/assets/wallet/ipfs_uri/_ethpm_packages/wallet/manifest.json diff --git a/tests/core/conftest.py b/tests/core/conftest.py index 2d70e2d..b7edfed 100644 --- a/tests/core/conftest.py +++ b/tests/core/conftest.py @@ -3,6 +3,8 @@ import pytest +from ethpm_cli.constants import ETHPM_DIR_NAME + ASSETS_DIR = Path(__file__).parent / "assets" @@ -13,7 +15,7 @@ def test_assets_dir(): @pytest.fixture def owned_pkg_data(test_assets_dir): - owned_dir = test_assets_dir / "owned" / "ipfs_uri" / "ethpm_packages" / "owned" + owned_dir = test_assets_dir / "owned" / "ipfs_uri" / ETHPM_DIR_NAME / "owned" owned_raw_manifest = (owned_dir / "manifest.json").read_bytes() return { "raw_manifest": owned_raw_manifest, diff --git a/tests/core/test_install.py b/tests/core/test_install.py index 02c09c2..6d21f88 100644 --- a/tests/core/test_install.py +++ b/tests/core/test_install.py @@ -5,6 +5,7 @@ import pytest from ethpm_cli._utils.testing import check_dir_trees_equal +from ethpm_cli.constants import ETHPM_DIR_NAME from ethpm_cli.exceptions import InstallError from ethpm_cli.install import ( Config, @@ -18,7 +19,7 @@ @pytest.fixture def config(tmpdir): namespace = Namespace() - ethpm_dir = Path(tmpdir) / "ethpm_packages" + ethpm_dir = Path(tmpdir) / ETHPM_DIR_NAME ethpm_dir.mkdir() namespace.local_ipfs = False namespace.target_uri = None @@ -78,7 +79,7 @@ def test_install_package(uri, pkg_name, alias, install_type, config, test_assets pkg = Package(uri, alias, config.ipfs_backend) install_package(pkg, config) - expected_package = test_assets_dir / pkg_name / install_type / "ethpm_packages" + expected_package = test_assets_dir / pkg_name / install_type / ETHPM_DIR_NAME assert check_dir_trees_equal(config.ethpm_dir, expected_package) @@ -101,12 +102,12 @@ def test_can_install_same_package_twice_if_aliased(config, owned_pkg, test_asset assert (config.ethpm_dir / "owned").is_dir() assert check_dir_trees_equal( config.ethpm_dir / "owned", - test_assets_dir / "owned" / "ipfs_uri" / "ethpm_packages" / "owned", + test_assets_dir / "owned" / "ipfs_uri" / ETHPM_DIR_NAME / "owned", ) assert (config.ethpm_dir / "owned-alias").is_dir() assert check_dir_trees_equal( config.ethpm_dir / "owned-alias", - test_assets_dir / "owned" / "ipfs_uri_alias" / "ethpm_packages" / "owned-alias", + test_assets_dir / "owned" / "ipfs_uri_alias" / ETHPM_DIR_NAME / "owned-alias", ) @@ -117,7 +118,7 @@ def test_install_multiple_packages(config, test_assets_dir, owned_pkg, wallet_pk assert (config.ethpm_dir / "wallet").is_dir() assert (config.ethpm_dir / "owned").is_dir() assert check_dir_trees_equal( - config.ethpm_dir, (test_assets_dir / "multiple" / "ethpm_packages") + config.ethpm_dir, (test_assets_dir / "multiple" / ETHPM_DIR_NAME) ) @@ -132,12 +133,12 @@ def test_uninstall_packages( assert (config.ethpm_dir / keep).is_dir() assert not (config.ethpm_dir / uninstall).is_dir() assert check_dir_trees_equal( - config.ethpm_dir, (test_assets_dir / keep / "ipfs_uri" / "ethpm_packages") + config.ethpm_dir, (test_assets_dir / keep / "ipfs_uri" / ETHPM_DIR_NAME) ) def test_uninstall_package_warns_if_package_doesnt_exist(config): - with pytest.raises(InstallError, match="Unable to uninstall"): + with pytest.raises(InstallError, match="No package with the name invalid"): uninstall_package("invalid", config) @@ -147,19 +148,19 @@ def test_list(config, owned_pkg, wallet_pkg, caplog): with caplog.at_level(logging.INFO): list_installed_packages(config) - assert "owned==1.0.0..." in caplog.text - assert "wallet==1.0.0..." in caplog.text - assert "- safe-math-lib==1.0.0..." in caplog.text - assert "- owned==1.0.0..." in caplog.text assert ( - "(ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW)\n" in caplog.text - ) + "owned==1.0.0 --- (ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW)\n" + in caplog.text + ) # noqa: E501 assert ( - "(ipfs://QmRMSm4k37mr2T3A2MGxAj2eAHGR5veibVt1t9Leh5waV1)\n" in caplog.text - ) + "wallet==1.0.0 --- (ipfs://QmRMSm4k37mr2T3A2MGxAj2eAHGR5veibVt1t9Leh5waV1)\n" + in caplog.text + ) # noqa: E501 assert ( - "(ipfs://QmWgvM8yXGyHoGWqLFXvareJsoCZVsdrpKNCLMun3RaSJm)\n" in caplog.text - ) + "- safe-math-lib==1.0.0 --- (ipfs://QmWgvM8yXGyHoGWqLFXvareJsoCZVsdrpKNCLMun3RaSJm)\n" + in caplog.text + ) # noqa: E501 assert ( - "(ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW)\n" in caplog.text - ) + "- owned==1.0.0 --- (ipfs://QmbeVyFLSuEUxiXKwSsEjef6icpdTdA4kGG9BcrJXKNKUW)\n" + in caplog.text + ) # noqa: E501