Skip to content

Commit

Permalink
use config.ARGV instead of sys.argv
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Feb 18, 2019
1 parent 0f8ee57 commit b04cc90
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lib/components/contract.py
Expand Up @@ -3,7 +3,6 @@
from collections import OrderedDict
import eth_event
import re
import sys

from lib.components.transaction import TransactionReceipt, VirtualMachineError
from lib.components.eth import web3, wei
Expand Down Expand Up @@ -355,7 +354,7 @@ def __call__(self, *args):
Returns:
Contract method return value(s).'''
if sys.argv[1] in ('test', 'coverage') and CONFIG['test']['always_transact']:
if config.ARGV['mode']=="script" and CONFIG['test']['always_transact']:
tx = self.transact(*args)
return tx.return_value
return self.call(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/components/network.py
Expand Up @@ -38,7 +38,7 @@ def __init__(self, module = None, setup = False):
self.setup()

def setup(self):
if self._init or sys.argv[1] == "console":
if self._init or config.ARGV['mode'] == "console":
verbose = True
self._init = False
else:
Expand Down
7 changes: 3 additions & 4 deletions lib/components/transaction.py
Expand Up @@ -4,7 +4,6 @@
import eth_event
from hexbytes import HexBytes
import json
import sys
import threading
import time

Expand Down Expand Up @@ -121,12 +120,12 @@ def __init__(self, txid, sender=None, silent=False, name='', callback=None):
t.start()
try:
t.join()
if sys.argv[1] != "console" and not self.status:
if config.ARGV['mode'] == "script" and not self.status:
raise VirtualMachineError(
{"message": "revert "+(self.revert_msg or ""), "source":self.error(1)}
)
except KeyboardInterrupt:
if sys.argv[1] != "console":
if config.ARGV['mode'] == "script":
raise

def _await_confirm(self, silent, callback):
Expand Down Expand Up @@ -159,7 +158,7 @@ def _await_confirm(self, silent, callback):
self.events = eth_event.decode_logs(receipt['logs'], topics())
except:
pass
if self.fn_name and '--gas' in sys.argv:
if self.fn_name and config.ARGV['gas']:
_profile_gas(self.fn_name, receipt['gasUsed'])
if not silent:
if CONFIG['logging']['tx'] >= 2:
Expand Down
2 changes: 1 addition & 1 deletion lib/init.py
Expand Up @@ -52,7 +52,7 @@ def main():
"Create a new folder for your project and run brownie init there.")

if CONFIG['folders']['project'] != os.path.abspath('.'):
if '--force' not in sys.argv:
if not config.ARGV['force']:
sys.exit("ERROR: Cannot init the subfolder of an existing brownie"
" project. Use --force to override.")
CONFIG['folders']['project'] = os.path.abspath('.')
Expand Down
2 changes: 1 addition & 1 deletion lib/services/color.py
Expand Up @@ -103,7 +103,7 @@ def print_colors(self, msg, key = None, value=None):

def format_tb(self, exc, filename = None, start = None, stop = None):
tb = [i.replace("./", "") for i in traceback.format_tb(exc[2])]
if filename and '--tb' not in sys.argv:
if filename and not config.ARGV['tb']:
try:
start = tb.index(next(i for i in tb if filename in i))
stop = tb.index(next(i for i in tb[::-1] if filename in i)) + 1
Expand Down
2 changes: 2 additions & 0 deletions lib/services/config.py
Expand Up @@ -50,6 +50,8 @@ def __getitem__(self, key):
ARGV[key] = sys.argv[idx+1]
else:
ARGV[key] = True

# used to determine various behaviours in other modules
ARGV['mode'] = "console" if sys.argv[1] == "console" else "script"


Expand Down
2 changes: 1 addition & 1 deletion lib/test.py
Expand Up @@ -149,7 +149,7 @@ def main():
traceback_info += tb
if not traceback_info:
print("\n{0[success]}SUCCESS{0}: All tests passed.".format(color))
if '--gas' in sys.argv:
if config.ARGV['gas']:
print('\nGas Profile:')
for i in sorted(tx.gas_profile):
print("{0} - avg: {1[avg]:.0f} low: {1[low]} high: {1[high]}".format(i, tx.gas_profile[i]))
Expand Down

0 comments on commit b04cc90

Please sign in to comment.