From 4521673a0a2c27651af6dd6065b6e1d7edf5fcad Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 19 Feb 2020 12:00:50 +0400 Subject: [PATCH 1/3] add solc_binary_path kwarg to install_solc_pragma --- solcx/install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solcx/install.py b/solcx/install.py index 19c3d5a..582594c 100644 --- a/solcx/install.py +++ b/solcx/install.py @@ -154,7 +154,7 @@ def set_solc_version_pragma(pragma_string, silent=False, check_new=False): LOGGER.info("Newer compatible solc version exists: {}".format(latest)) -def install_solc_pragma(pragma_string, install=True, show_progress=False): +def install_solc_pragma(pragma_string, install=True, show_progress=False, solcx_binary_path=None): version = _select_pragma_version( pragma_string, [Version(i[1:]) for i in get_available_solc_versions()] @@ -162,7 +162,7 @@ def install_solc_pragma(pragma_string, install=True, show_progress=False): if not version: raise ValueError("Compatible solc version does not exist") if install: - install_solc(version, show_progress=show_progress) + install_solc(version, show_progress=show_progress, solcx_binary_path=solcx_binary_path) return version From ab8b8d4a902695e2a0fcb5a49e032bb7e8527f16 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 19 Feb 2020 12:08:32 +0400 Subject: [PATCH 2/3] update readme with information about SOLCX_BINARY_PATH env var --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e69c8ef..269219c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ Or via the command line: python -m solcx.install v0.4.25 ``` +By default, `solc` versions are installed at `~/.solcx/`. If you wish to use a different directory you can specify it with the `SOLCX_BINARY_PATH` environment variable. + +## Setting the `solc` Version + Py-solc-x defaults to the most recent installed version set as the active one. To check or modify the active version: ```python From 7eeb89edece28191bca97471ff6b928687c8ed6a Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 19 Feb 2020 12:22:46 +0400 Subject: [PATCH 3/3] add env var test cases --- tests/test_install.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_install.py b/tests/test_install.py index dbb6d14..64e3121 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -48,3 +48,30 @@ def test_install_osx(): def test_progress_bar(nosolc): solcx.install_solc('0.6.0', show_progress=True) + + +def test_environment_var_path(monkeypatch, tmp_path): + install_folder = solcx.get_solc_folder() + monkeypatch.setenv('SOLCX_BINARY_PATH', tmp_path.as_posix()) + assert solcx.get_solc_folder() != install_folder + + monkeypatch.undo() + assert solcx.get_solc_folder() == install_folder + + +def test_environment_var_versions(monkeypatch, tmp_path): + versions = solcx.get_installed_solc_versions() + monkeypatch.setenv('SOLCX_BINARY_PATH', tmp_path.as_posix()) + assert solcx.get_installed_solc_versions() != versions + + monkeypatch.undo() + assert solcx.get_installed_solc_versions() == versions + + +def test_environment_var_install(monkeypatch, tmp_path): + assert not tmp_path.joinpath('solc-v0.6.0').exists() + + monkeypatch.setenv('SOLCX_BINARY_PATH', tmp_path.as_posix()) + + solcx.install_solc('0.6.0') + assert tmp_path.joinpath('solc-v0.6.0').exists()