Skip to content

Commit

Permalink
Merge pull request #1507 from scyron6/no-compile-enhancement
Browse files Browse the repository at this point in the history
No compile enhancement
  • Loading branch information
iamdefinitelyahuman authored Jan 29, 2024
2 parents fc250a6 + 3313a63 commit 0602cca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions brownie/_cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
--network <name> 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.
"""
Expand Down
24 changes: 13 additions & 11 deletions brownie/project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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(
Expand All @@ -186,9 +186,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:
Expand Down Expand Up @@ -249,14 +249,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()
Expand Down Expand Up @@ -726,6 +727,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.
Expand Down Expand Up @@ -778,7 +780,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:
Expand Down
13 changes: 13 additions & 0 deletions tests/cli/test_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0602cca

Please sign in to comment.