Skip to content

Commit

Permalink
Merge pull request #44 from iamdefinitelyahuman/binary-path2
Browse files Browse the repository at this point in the history
Binary path2
  • Loading branch information
iamdefinitelyahuman committed Feb 19, 2020
2 parents d0bde00 + 7eeb89e commit 98c0975
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions solcx/install.py
Expand Up @@ -154,15 +154,15 @@ 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()]
)
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


Expand Down
27 changes: 27 additions & 0 deletions tests/test_install.py
Expand Up @@ -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()

0 comments on commit 98c0975

Please sign in to comment.