def test_gets_correct_files_default_dir(project_dir, write_project_file): project = Project(project_dir) project.config['compilation']['backend'] = { 'class': 'populus.compilation.backends.VyperBackend', } compiler_backend = project.get_compiler_backend() file_names = tuple(itertools.chain.from_iterable( compiler_backend.get_project_source_paths(source_dir) for source_dir in project.contracts_source_dirs )) should_match = { 'contracts/SolidityContract.v.py', 'contracts/AnotherFile.vy', } should_not_match = { 'contracts/Swapfile.v.py.swp', 'contracts/Swapfile.v.py.txt', 'contracts/BackedUpContract.vy.bak', 'contracts/not-contract.vy.txt', } for filename in should_match: write_project_file(filename) for filename in should_not_match: write_project_file(filename) for file_name in file_names: assert os.path.exists(file_name) assert any(is_same_path(file_name, path) for path in should_match) assert not any(is_same_path(file_name, path) for path in should_not_match)
def test_gets_correct_files_default_dir(project_dir, write_project_file): project = Project(project_dir, create_config_file=True) compiler_backend = project.get_compiler_backend() file_names = tuple( itertools.chain.from_iterable( compiler_backend.get_project_source_paths(source_dir) for source_dir in project.contracts_source_dirs)) should_match = { 'contracts/SolidityContract.sol', 'contracts/AnotherFile.sol', } should_not_match = { 'contracts/BackedUpContract.sol.bak', 'contracts/Swapfile.sol.swp', 'contracts/not-contract.txt', } for filename in should_match: write_project_file(filename) for filename in should_not_match: write_project_file(filename) for file_name in file_names: assert os.path.exists(file_name) assert any(is_same_path(file_name, path) for path in should_match) assert not any( is_same_path(file_name, path) for path in should_not_match)
def test_gets_correct_files_default_dir(project_dir, write_project_file): project = Project(project_dir) project.config['compilation']['backend'] = { 'class': 'populus.compilation.backends.ViperBackend', } compiler_backend = project.get_compiler_backend() file_names = tuple(itertools.chain.from_iterable( compiler_backend.get_project_source_paths(source_dir) for source_dir in project.contracts_source_dirs )) should_match = { 'contracts/SolidityContract.v.py', 'contracts/AnotherFile.vy', } should_not_match = { 'contracts/Swapfile.v.py.swp', 'contracts/Swapfile.v.py.txt', 'contracts/BackedUpContract.vy.bak', 'contracts/not-contract.vy.txt', } for filename in should_match: write_project_file(filename) for filename in should_not_match: write_project_file(filename) for file_name in file_names: assert os.path.exists(file_name) assert any(is_same_path(file_name, path) for path in should_match) assert not any(is_same_path(file_name, path) for path in should_not_match)
def test_project_directory_properties(project_dir): project = Project() contracts_source_dir = get_contracts_source_dir(project_dir) assert is_same_path(project.contracts_source_dir, contracts_source_dir) build_asset_dir = get_build_asset_dir(project_dir) assert is_same_path(project.build_asset_dir, build_asset_dir) compiled_contracts_asset_path = get_compiled_contracts_asset_path(build_asset_dir) assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path) base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir) assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir)
def test_project_directory_properties(project_dir): project = Project(project_dir) contracts_source_dirs = get_contracts_source_dirs(project_dir) for left, right in zip(project.contracts_source_dirs, contracts_source_dirs): assert is_same_path(left, right) build_asset_dir = get_build_asset_dir(project_dir) assert is_same_path(project.build_asset_dir, build_asset_dir) compiled_contracts_asset_path = get_compiled_contracts_asset_path(build_asset_dir) assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path) base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir) assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir)
def test_project_directory_properties(project_dir): project = Project(project_dir, create_config_file=True) contracts_source_dirs = get_contracts_source_dirs(project_dir) for left, right in zip(project.contracts_source_dirs, contracts_source_dirs): assert is_same_path(left, right) build_asset_dir = get_build_asset_dir(project_dir) assert is_same_path(project.build_asset_dir, build_asset_dir) compiled_contracts_asset_path = get_compiled_contracts_asset_path(build_asset_dir) assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path) base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir) assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir)
def main(ctx, config): """ Populus """ if not config and check_if_ini_config_file_exists(): click.echo("Attempting to upgrade legacy `populus.ini` config file") try: backup_ini_config_file_path = upgrade_legacy_config_file(os.getcwd()) except: click.echo( "The following error occured while trying to upgrade the legacy " "`populus.ini` config file:" ) raise else: click.echo( "Project configuration upgraded. New config file " "`populus.json` has been written. Old config file was renamed " "to `{0}`".format(backup_ini_config_file_path) ) project = Project(config) if not any(is_same_path(p, project.project_dir) for p in sys.path): # ensure that the project directory is in the sys.path sys.path.insert(0, project.project_dir) ctx.obj = {} ctx.obj['PROJECT'] = project
def test_getting_source_file_for_project_contract_with_library_dependency( project): source_file_path = get_contract_source_file_path( project.compiled_contract_data['Multiply13']) expected_path = os.path.join(project.contracts_source_dir, 'Multiply13.sol') assert is_same_path(source_file_path, expected_path)
def test_project_directory_properties(project_dir): project = Project() contracts_dir = get_contracts_dir(project_dir) assert is_same_path(project.contracts_dir, contracts_dir) build_dir = get_build_dir(project_dir) assert is_same_path(project.build_dir, build_dir) compiled_contracts_file_path = get_compiled_contracts_file_path( project_dir) assert is_same_path(project.compiled_contracts_file_path, compiled_contracts_file_path) blockchains_dir = get_blockchains_dir(project_dir) assert is_same_path(project.blockchains_dir, blockchains_dir) data_dir = get_data_dir(project_dir, 'some-test-chain-name') assert is_same_path( project.get_blockchain_data_dir('some-test-chain-name'), data_dir) chaindata_dir = get_chaindata_dir(data_dir) assert is_same_path( project.get_blockchain_chaindata_dir('some-test-chain-name'), chaindata_dir) geth_ipc_path = get_geth_ipc_path(data_dir) assert is_same_path( project.get_blockchain_ipc_path('some-test-chain-name'), geth_ipc_path)
def main(ctx, config_file_path): """ Populus """ logger = get_logger_with_click_handler('populus') if not config_file_path and check_if_ini_config_file_exists(): logger.info("Attempting to upgrade legacy `populus.ini` config file") try: backup_ini_config_file_path = upgrade_legacy_config_file( os.getcwd()) except: logger.error( "The following error occured while trying to upgrade the legacy " "`populus.ini` config file:") raise else: logger.info( "Project configuration upgraded. New config file " "`populus.json` has been written. Old config file was renamed " "to `{0}`".format(backup_ini_config_file_path)) project = Project(config_file_path) config_version = project.config['version'] subcommand_bypasses_config_version = ctx.invoked_subcommand in { 'config', 'init' } if not subcommand_bypasses_config_version and config_version != LATEST_VERSION: old_config_version_msg = ( "================ warning =================\n" "Your populus config file is current at version {0}. " "The latest version is {1}. You can use the `populus config " "upgrade` command to upgrade your config file to the latest version\n" "================ warning =================\n\n".format( config_version, LATEST_VERSION, )) warnings.warn(DeprecationWarning(old_config_version_msg)) logger.warning(old_config_version_msg) proceed_msg = ( "Without and up-to-date configuration file Populus may not function " "correctly. Would you still like to proceed?") if not click.confirm(proceed_msg): ctx.exit(1) if not any(is_same_path(p, project.project_dir) for p in sys.path): # ensure that the project directory is in the sys.path sys.path.insert(0, project.project_dir) ctx.obj = {} ctx.obj['PROJECT'] = project
def main(ctx, config): """ Populus """ project = Project(config) if not any(is_same_path(p, project.project_dir) for p in sys.path): # ensure that the project directory is in the sys.path sys.path.insert(0, project.project_dir) ctx.obj = {} ctx.obj['PROJECT'] = project
def test_project_directory_properties(project_dir): project = Project(project_dir, create_config_file=True) if sys.version_info.major != 2: with pytest.warns(DeprecationWarning): project.contracts_source_dir contracts_source_dirs = get_contracts_source_dirs(project_dir) for left, right in zip(project.contracts_source_dirs, contracts_source_dirs): assert is_same_path(left, right) build_asset_dir = get_build_asset_dir(project_dir) assert is_same_path(project.build_asset_dir, build_asset_dir) compiled_contracts_asset_path = get_compiled_contracts_asset_path( build_asset_dir) assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path) base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir) assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir)
def main(ctx, project_dir, logging_level): """ Populus """ logger = get_logger_with_click_handler('populus', level=logging_level) ctx.obj = {} ctx.obj['PROJECT_DIR'] = project_dir if ctx.invoked_subcommand not in ('init', 'upgrade'): project = Project(project_dir) config_version = project.config['version'] subcommand_bypasses_config_version = ctx.invoked_subcommand in { 'config' } if not subcommand_bypasses_config_version and config_version != LATEST_VERSION: old_config_version_msg = ( "================ warning =================\n" "Your populus config file is current at version {0}. " "The latest version is {1}. You can use the `populus config " "upgrade` command to upgrade your config file to the latest version\n" "================ warning =================\n\n".format( config_version, LATEST_VERSION, )) warnings.warn(DeprecationWarning(old_config_version_msg)) logger.warning(old_config_version_msg) proceed_msg = ( "Without and up-to-date configuration file Populus may not function " "correctly. Would you still like to proceed?") if not click.confirm(proceed_msg): ctx.exit(1) if not any(is_same_path(p, project.project_dir) for p in sys.path): # ensure that the project directory is in the sys.path sys.path.insert(0, project.project_dir) ctx.obj['PROJECT'] = project
def main(ctx, project_dir, logging_level): """ Populus """ logger = get_logger_with_click_handler('populus', level=logging_level) ctx.obj = {} ctx.obj['PROJECT_DIR'] = project_dir if ctx.invoked_subcommand not in ('init', 'upgrade'): project = Project(project_dir) config_version = project.config['version'] subcommand_bypasses_config_version = ctx.invoked_subcommand in {'config'} if not subcommand_bypasses_config_version and config_version != LATEST_VERSION: old_config_version_msg = ( "================ warning =================\n" "Your populus config file is current at version {0}. " "The latest version is {1}. You can use the `populus config " "upgrade` command to upgrade your config file to the latest version\n" "================ warning =================\n\n".format( config_version, LATEST_VERSION, ) ) warnings.warn(DeprecationWarning(old_config_version_msg)) logger.warning(old_config_version_msg) proceed_msg = ( "Without and up-to-date configuration file Populus may not function " "correctly. Would you still like to proceed?" ) if not click.confirm(proceed_msg): ctx.exit(1) if not any(is_same_path(p, project.project_dir) for p in sys.path): # ensure that the project directory is in the sys.path sys.path.insert(0, project.project_dir) ctx.obj['PROJECT'] = project
def test_project_directory_properties(project_dir): project = Project() contracts_dir = get_contracts_dir(project_dir) assert is_same_path(project.contracts_dir, contracts_dir) build_dir = get_build_dir(project_dir) assert is_same_path(project.build_dir, build_dir) compiled_contracts_file_path = get_compiled_contracts_file_path(project_dir) assert is_same_path(project.compiled_contracts_file_path, compiled_contracts_file_path) blockchains_dir = get_blockchains_dir(project_dir) assert is_same_path(project.blockchains_dir, blockchains_dir) data_dir = get_data_dir(project_dir, "some-test-chain-name") assert is_same_path(project.get_blockchain_data_dir("some-test-chain-name"), data_dir) chaindata_dir = get_chaindata_dir(data_dir) assert is_same_path(project.get_blockchain_chaindata_dir("some-test-chain-name"), chaindata_dir) geth_ipc_path = get_geth_ipc_path(data_dir) assert is_same_path(project.get_blockchain_ipc_path("some-test-chain-name"), geth_ipc_path)
def test_project_dir_defaults_to_cwd(project_dir): project = Project(project_dir, create_config_file=True) assert is_same_path(project.project_dir, project_dir)
def test_project_directory_properties(project_dir): project = Project() contracts_source_dir = get_contracts_source_dir(project_dir) assert is_same_path(project.contracts_source_dir, contracts_source_dir) with pytest.warns(DeprecationWarning): assert is_same_path(project.contracts_dir, contracts_source_dir) build_asset_dir = get_build_asset_dir(project_dir) assert is_same_path(project.build_asset_dir, build_asset_dir) with pytest.warns(DeprecationWarning): assert is_same_path(project.build_dir, build_asset_dir) compiled_contracts_asset_path = get_compiled_contracts_asset_path( build_asset_dir) assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path) with pytest.warns(DeprecationWarning): assert is_same_path(project.compiled_contracts_file_path, compiled_contracts_asset_path) base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir) assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir) with pytest.warns(DeprecationWarning): assert is_same_path(project.blockchains_dir, base_blockchain_storage_dir) data_dir = get_data_dir(project_dir, 'some-test-chain-name') with pytest.warns(DeprecationWarning): assert is_same_path( project.get_blockchain_data_dir('some-test-chain-name'), data_dir) chaindata_dir = get_chaindata_dir(data_dir) with pytest.warns(DeprecationWarning): assert is_same_path( project.get_blockchain_chaindata_dir('some-test-chain-name'), chaindata_dir) geth_ipc_path = get_geth_ipc_path(data_dir) with pytest.warns(DeprecationWarning): assert is_same_path( project.get_blockchain_ipc_path('some-test-chain-name'), geth_ipc_path)
def test_project_fixture(request, project_dir): project = request.getfuncargvalue('project') assert is_same_path(project.project_dir, project_dir)
def test_project_dir_defaults_to_cwd(project_dir): project = Project() assert is_same_path(project.project_dir, project_dir)
def test_project_dir_defaults_to_cwd(project_dir): project = Project(project_dir) assert is_same_path(project.project_dir, project_dir)
def test_paths_that_dont_exist(project_dir): assert not os.path.exists('not-a-real-path') assert not os.path.exists('also-not-a-real-path') assert not is_same_path('not-a-real-path', 'also-not-a-real-path')
def test_relpath_and_abspath(project_dir): abs_path = os.path.abspath('this-is-a-path') rel_path = os.path.relpath('this-is-a-path') assert abs_path != rel_path assert is_same_path(abs_path, rel_path)
def test_project_fixture(request, project_dir): project = request.getfixturevalue('project') assert is_same_path(project.project_dir, project_dir)
def test_paths_that_exist(project_dir, write_project_file): write_project_file('not-a-real-path') write_project_file('also-not-a-real-path') assert not is_same_path('not-a-real-path', 'also-not-a-real-path')
def test_getting_source_file_for_project_contract(project): source_file_path = get_contract_source_file_path( project.compiled_contract_data['Math']) expected_path = os.path.join(project.contracts_source_dir, 'Math.sol') assert is_same_path(source_file_path, expected_path)