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 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 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()