Skip to content

Commit

Permalink
Merge pull request #584 from eth-brownie/feat-precompile-hook
Browse files Browse the repository at this point in the history
load_source hook point
  • Loading branch information
iamdefinitelyahuman committed May 31, 2020
2 parents 81dae6e + 65c46ea commit 742095d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions brownie/project/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3

import importlib
import json
import os
import shutil
Expand All @@ -9,6 +10,7 @@
from hashlib import sha1
from io import BytesIO
from pathlib import Path
from types import ModuleType
from typing import Any, Dict, Iterator, KeysView, List, Optional, Set, Tuple, Union
from urllib.parse import urlparse

Expand Down Expand Up @@ -701,13 +703,22 @@ def _load_sources(project_path: Path, subfolder: str, allow_json: bool) -> Dict:
if allow_json:
suffixes = suffixes + (".json",)

# one day this will be a beautiful plugin system
hooks: Optional[ModuleType] = None
if project_path.joinpath("brownie_hooks.py").exists():
hooks = importlib.import_module("brownie_hooks")

for path in project_path.glob(f"{subfolder}/**/*"):
if path.suffix not in suffixes:
continue
if next((i for i in path.relative_to(project_path).parts if i.startswith("_")), False):
continue
with path.open() as fp:
source = fp.read()

if hasattr(hooks, "brownie_load_source"):
source = hooks.brownie_load_source(path, source) # type: ignore

path_str: str = path.relative_to(project_path).as_posix()
contract_sources[path_str] = source
return contract_sources
Expand Down

0 comments on commit 742095d

Please sign in to comment.