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

load_source hook point #584

Merged
merged 1 commit into from
May 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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