Skip to content

Commit

Permalink
Merge pull request #147 from HyperLink-Technology/v1.0.0b8
Browse files Browse the repository at this point in the history
V1.0.0b8
  • Loading branch information
iamdefinitelyahuman authored Jun 30, 2019
2 parents 630e02f + 6e443dd commit 37c4149
Show file tree
Hide file tree
Showing 112 changed files with 4,690 additions and 2,936 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# .coveragerc to control coverage.py
[run]
branch = True
omit =
brownie/gui/*
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
1.0.0b8
-------

- Rebuild of coverage evaluation functionality using contract ASTs
- Split coverage eval results between branches and statements, add GUI support
- Add tracebacks for failed transactions, better call trace formatting
- Allow contract minification before compiling
- Enable output console in GUI (very basic for now)
- Rebuild brownie console using code.InteractiveConsole
- Significant code refactoring and reorganization
- Emphasis on standardized structure across modules and increased ease of testing
- More tests, coverage at 88%

1.0.0b7
-------

Expand Down
10 changes: 4 additions & 6 deletions brownie/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/usr/bin/python3

from brownie.network import (
from .network import (
accounts,
alert,
history,
network,
rpc,
web3
)
from brownie.project import (
from .project import (
compile_source,
project,
__project
__brownie_import_all__
)
from brownie.gui import Gui
from brownie.test import check
Expand All @@ -26,7 +24,7 @@
'rpc',
'web3',
'project',
'__project',
'__brownie_import_all__',
'check',
'compile_source',
'wei',
Expand Down
52 changes: 26 additions & 26 deletions brownie/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ def _load_default_config():
return config


def load_project_config():
def load_project_config(project_path):
'''Loads configuration settings from a project's brownie-config.json'''
project_path = Path(project_path)
if not project_path.exists():
raise ValueError("Project does not exist!")
CONFIG._unlock()
if CONFIG['folders']['project']:
path = Path(CONFIG['folders']['project']).joinpath("brownie-config.json")
if path.exists():
_recursive_update(CONFIG, json.load(path.open()), [])
else:
shutil.copy(
str(Path(CONFIG['folders']['brownie']).joinpath("data/config.json")),
str(path)
)
print("WARNING: No config file found for this project. A new one has been created.")
CONFIG['folders']['project'] = str(project_path)
config_path = project_path.joinpath("brownie-config.json")
if config_path.exists():
_recursive_update(CONFIG, json.load(config_path.open()), [])
else:
shutil.copy(
str(Path(CONFIG['folders']['brownie']).joinpath("data/config.json")),
str(config_path)
)
print("WARNING: No config file found for this project. A new one has been created.")
CONFIG.setdefault('active_network', {'name': None})
CONFIG._lock()


def modify_network_config(network=None):
Expand All @@ -58,11 +62,17 @@ def modify_network_config(network=None):
try:
if not network:
network = CONFIG['network_defaults']['name']
CONFIG['active_network'] = CONFIG['networks'][network].copy()

CONFIG['active_network'] = {
**CONFIG['network_defaults'],
**CONFIG['networks'][network]
}
CONFIG['active_network']['name'] = network
for key, value in CONFIG['network_defaults'].items():
if key not in CONFIG['active_network']:
CONFIG['active_network'][key] = value

if ARGV['cli'] == "test":
CONFIG['active_network'].update(CONFIG['test'])
if not CONFIG['active_network']['broadcast_reverting_tx']:
print("WARNING: Reverting transactions will NOT be broadcasted.")
except KeyError:
raise KeyError("Network '{}' is not defined in config.json".format(network))
finally:
Expand All @@ -85,18 +95,8 @@ def _recursive_update(original, new, base):
)


# move argv flags into FalseyDict
# create argv object
ARGV = _Singleton("Argv", (FalseyDict,), {})()
for key in [i for i in sys.argv if i[:2] == "--"]:
idx = sys.argv.index(key)
if len(sys.argv) >= idx+2 and sys.argv[idx+1][:2] != "--":
ARGV[key[2:]] = sys.argv[idx+1]
else:
ARGV[key[2:]] = True

# used to determine various behaviours in other modules
if len(sys.argv) > 1:
ARGV['cli'] = sys.argv[1]

# load config
CONFIG = _load_default_config()
41 changes: 16 additions & 25 deletions brownie/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from pathlib import Path
import sys

import brownie
from brownie.cli.utils import color
import brownie.project as project
from brownie import network
from brownie.cli.utils import color, notify
from brownie.exceptions import ProjectNotFound
from brownie._config import ARGV

__version__ = "1.0.0b7" # did you change this in docs/conf.py as well?
__version__ = "1.0.0b8" # did you change this in docs/conf.py as well?

__doc__ = """Usage: brownie <command> [<args>...] [options <args>]
Expand All @@ -31,38 +32,28 @@

def main():

print("Brownie v{} - Python development framework for Ethereum\n".format(__version__))
print(f"Brownie v{__version__} - Python development framework for Ethereum\n")

# remove options before calling docopt
if len(sys.argv) > 1 and sys.argv[1][0] != "-":
try:
idx = next(sys.argv.index(i) for i in sys.argv if i[0] == "-")
opts = sys.argv[idx:]
sys.argv = sys.argv[:idx]
except StopIteration:
opts = []

idx = next((sys.argv.index(i) for i in sys.argv if i.startswith("-")), len(sys.argv))
opts = sys.argv[idx:]
sys.argv = sys.argv[:idx]
args = docopt(__doc__)
sys.argv += opts

cmd_list = [i.stem for i in Path(__file__).parent.glob('[!_]*.py')]
if args['<command>'] not in cmd_list:
sys.exit("Invalid command. Try 'brownie --help' for available commands.")

if args['<command>'] not in ("init", "bake"):
path = project.check_for_project('.')
if not path:
sys.exit(
"ERROR: Brownie environment has not been initiated for this folder."
"\nType 'brownie init' to create the file structure."
)
if args['<command>'] != "compile" and "--help" not in opts:
for container in project.load(path):
setattr(brownie, container._name, container)
brownie.__all__.append(container._name)
brownie.a = brownie.accounts
brownie.__all__.append('a')
ARGV['cli'] = args['<command>']
sys.modules['brownie'].a = network.accounts
sys.modules['brownie'].__all__.append('a')

try:
importlib.import_module("brownie.cli."+args['<command>']).main()
except ProjectNotFound:
notify("ERROR", "Brownie environment has not been initiated for this folder.")
print("Type 'brownie init' to create the file structure.")
except Exception:
print(color.format_tb(sys.exc_info()))
34 changes: 4 additions & 30 deletions brownie/cli/bake.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#!/usr/bin/python3

from docopt import docopt
from io import BytesIO
from pathlib import Path
import requests
import shutil
import sys
import zipfile

from brownie._config import CONFIG

MIXES_URL = "https://github.com/brownie-mix/{}-mix/archive/master.zip"
from brownie import project
from brownie.cli.utils import notify

__doc__ = """Usage: brownie bake <mix> [<path>] [options]
Expand All @@ -31,24 +24,5 @@

def main():
args = docopt(__doc__)
path = Path(args['<path>'] or '.').resolve()
final_path = path.joinpath(args['<mix>'])
if final_path.exists():
sys.exit("ERROR: Bake folder already exists - {}".format(final_path))

if CONFIG['folders']['brownie'] in str(path):
sys.exit(
"ERROR: Cannot bake inside the main brownie installation folder.\n"
"Create a new folder for your project and run brownie bake there."
)

print("Downloading from "+MIXES_URL.format(args['<mix>'])+" ...")
request = requests.get(MIXES_URL.format(args['<mix>']))
with zipfile.ZipFile(BytesIO(request.content)) as zf:
zf.extractall(str(path))
path.joinpath(args['<mix>']+'-mix-master').rename(final_path)
shutil.copy(
str(Path(CONFIG['folders']['brownie']).joinpath("data/config.json")),
str(final_path.joinpath('brownie-config.json'))
)
print("Brownie mix '{}' has been initiated at {}".format(args['<mix>'], final_path))
path = project.pull(args['<mix>'], args['<path>'], args['--force'])
notify("SUCCESS", f"Brownie mix '{args['<mix>']}' has been initiated at {path}")
5 changes: 4 additions & 1 deletion brownie/cli/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from docopt import docopt
import shutil

import brownie.project as project
from brownie import project
from brownie.exceptions import ProjectNotFound

__doc__ = """Usage: brownie compile [options]
Expand All @@ -18,6 +19,8 @@
def main():
args = docopt(__doc__)
project_path = project.check_for_project('.')
if project_path is None:
raise ProjectNotFound
build_path = project_path.joinpath('build/contracts')
if args['--all']:
shutil.rmtree(build_path, ignore_errors=True)
Expand Down
Loading

0 comments on commit 37c4149

Please sign in to comment.