From a6b54f27dc713c4053c2067e38fda9cf7865e4c5 Mon Sep 17 00:00:00 2001 From: stephen cyron Date: Wed, 13 Apr 2022 13:37:40 -0400 Subject: [PATCH 1/4] Added --no-compile as option to console command --- brownie/_cli/console.py | 1 + tests/cli/test_cli_main.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/brownie/_cli/console.py b/brownie/_cli/console.py index 4b3437735..34c266c9a 100644 --- a/brownie/_cli/console.py +++ b/brownie/_cli/console.py @@ -34,6 +34,7 @@ --network Use a specific network (default {CONFIG.settings['networks']['default']}) --tb -t Show entire python traceback on exceptions --help -h Display this message + --no-compile Use previous contracts compilation Connects to the network and opens the brownie console. """ diff --git a/tests/cli/test_cli_main.py b/tests/cli/test_cli_main.py index ff82eecb1..3cc49f01a 100644 --- a/tests/cli/test_cli_main.py +++ b/tests/cli/test_cli_main.py @@ -193,3 +193,16 @@ def test_no_args_shows_help(cli_tester, capfd): def test_cli_pm(cli_tester): cli_tester.run_and_test_parameters("pm list", None) + +def test_cli_console_doesnt_accept_compile(cli_tester): + with pytest.raises(SystemExit): + cli_tester.run_and_test_parameters('console --compile') + +def test_cli_console_accepts_no_compile(cli_tester): + cli_tester.monkeypatch.setattr("brownie._cli.console.main", cli_tester.mock_subroutines) + + cli_tester.run_and_test_parameters("console") + cli_tester.run_and_test_parameters("console --no-compile") + + assert cli_tester.mock_subroutines.called is True + assert cli_tester.mock_subroutines.call_count == 2 \ No newline at end of file From 6e34dbfe265c38ce614cac398874e07c508868ed Mon Sep 17 00:00:00 2001 From: stephen cyron Date: Wed, 13 Apr 2022 13:46:13 -0400 Subject: [PATCH 2/4] Added newline at end of test_cli_main.py --- tests/cli/test_cli_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/test_cli_main.py b/tests/cli/test_cli_main.py index 3cc49f01a..f4caea325 100644 --- a/tests/cli/test_cli_main.py +++ b/tests/cli/test_cli_main.py @@ -205,4 +205,4 @@ def test_cli_console_accepts_no_compile(cli_tester): cli_tester.run_and_test_parameters("console --no-compile") assert cli_tester.mock_subroutines.called is True - assert cli_tester.mock_subroutines.call_count == 2 \ No newline at end of file + assert cli_tester.mock_subroutines.call_count == 2 From b7c3fb49bb2f228e5bc6cf1750bd07bb2e726370 Mon Sep 17 00:00:00 2001 From: stephen cyron Date: Wed, 13 Apr 2022 16:36:41 -0400 Subject: [PATCH 3/4] Added compile as optional parameter to both load functions and init --- brownie/project/main.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/brownie/project/main.py b/brownie/project/main.py index 7ab1f68bb..9858990f8 100644 --- a/brownie/project/main.py +++ b/brownie/project/main.py @@ -175,7 +175,7 @@ class Project(_ProjectBase): _build: project Build object """ - def __init__(self, name: str, project_path: Path) -> None: + def __init__(self, name: str, project_path: Path, compile: bool = True) -> None: self._path: Path = project_path self._envvars = _load_project_envvars(project_path) self._structure = expand_posix_vars( @@ -185,9 +185,9 @@ def __init__(self, name: str, project_path: Path) -> None: self._name = name self._active = False - self.load() + self.load(compile=compile) - def load(self, raise_if_loaded: bool = True) -> None: + def load(self, raise_if_loaded: bool = True, compile: bool = True) -> None: """Compiles the project contracts, creates ContractContainer objects and populates the namespace.""" if self._active: @@ -236,14 +236,15 @@ def load(self, raise_if_loaded: bool = True) -> None: self._build._add_interface(build_json) interface_hashes[path.stem] = build_json["sha1"] - self._compiler_config = expand_posix_vars( - _load_project_compiler_config(self._path), self._envvars - ) + if compile: + self._compiler_config = expand_posix_vars( + _load_project_compiler_config(self._path), self._envvars + ) - # compile updated sources, update build - changed = self._get_changed_contracts(interface_hashes) - self._compile(changed, self._compiler_config, False) - self._compile_interfaces(interface_hashes) + # compile updated sources, update build + changed = self._get_changed_contracts(interface_hashes) + self._compile(changed, self._compiler_config, False) + self._compile_interfaces(interface_hashes) self._load_dependency_artifacts() self._create_containers() @@ -713,6 +714,7 @@ def load( project_path: Union[Path, str, None] = None, name: Optional[str] = None, raise_if_loaded: bool = True, + compile: bool = True ) -> "Project": """Loads a project and instantiates various related objects. @@ -765,7 +767,7 @@ def load( _add_to_sys_path(project_path) # load sources and build - return Project(name, project_path) + return Project(name, project_path, compile=compile) def _install_dependencies(path: Path) -> None: From 3313a634c2e75a553bdb6832c117516678dbf262 Mon Sep 17 00:00:00 2001 From: stephen cyron Date: Thu, 14 Apr 2022 06:24:26 -0400 Subject: [PATCH 4/4] Added one test with nocompile --- tests/cli/test_console.py | 14 ++++++++++++++ tests/conftest.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py index 41c160600..f2f1ed78f 100644 --- a/tests/cli/test_console.py +++ b/tests/cli/test_console.py @@ -41,6 +41,20 @@ def test_multiple_commands(testproject, accounts, history, console): assert len(history) == 2 assert testproject.BrownieTester[0].owner() == accounts[0] +def test_multiple_commands_with_nocompile(testproject_nocompile, accounts, history, console): + shell = console(testproject_nocompile) + _run_cmd( + shell, + [ + "config", + "accounts[0].deploy(BrownieTester, True)", + "BrownieTester[0].doNothing()", + 'accounts.add("0x416b8a7d9290502f5661da81f0cf43893e3d19cb9aea3c426cfb36e8186e9c09")', + ], + ) + assert len(history) == 2 + assert testproject_nocompile.BrownieTester[0].owner() == accounts[0] + def test_multiline_commands(accounts, history, console): shell = console() diff --git a/tests/conftest.py b/tests/conftest.py index a7f2bd754..93a2f4423 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -180,6 +180,14 @@ def testproject(_project_factory, project, tmp_path): os.chdir(path) return project.load(path, "TestProject") +# same as function above but doesn't compile +@pytest.fixture +def testproject_nocompile(_project_factory, project, tmp_path): + path = tmp_path.joinpath("testproject") + _copy_all(_project_factory, path) + os.chdir(path) + return project.load(path, "TestProject", compile=False) + @pytest.fixture def tp_path(testproject):