From 8416c8a75e3d1e3cef0f068b2f71bd090d324e2f Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Thu, 17 Jan 2019 19:45:00 +0100 Subject: [PATCH] Disable pm api by default --- docs/web3.pm.rst | 33 ++++++++++++++----- tests/core/pm-module/conftest.py | 3 +- tests/core/pm-module/test_ens_integration.py | 4 +-- .../pm-module/test_registry_integration.py | 3 +- web3/main.py | 15 +++++++++ 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/docs/web3.pm.rst b/docs/web3.pm.rst index 7cf836313c..1c96c8e0bd 100644 --- a/docs/web3.pm.rst +++ b/docs/web3.pm.rst @@ -8,15 +8,30 @@ To learn more about the EthPM spec, visit the `documentation `__. -Attaching ---------- - To use ``web3.pm``, attach it to your ``web3`` instance. - - .. code-block:: python - - from web3.pm import PM - PM.attach(web3, 'pm') - +.. WARNING:: + + The ``web3.pm`` API is still under development and likely to change quickly. + + Now is a great time to get familiar with the API, and test out writing + code that uses some of the great upcoming features. + + By default, access to this module has been turned off in the stable version of Web3.py: + + .. code-block:: python + + >>> from web3.auto import w3 + >>> w3.pm + ... + AttributeError: The Package Management feature is disabled by default ... + + In order to access these features, you can turn it on with... + + .. code-block:: python + + >>> web3.enable_unstable_package_management_api() + >>> w3.pm + + Methods ------- diff --git a/tests/core/pm-module/conftest.py b/tests/core/pm-module/conftest.py index b65412c6ab..1ad31719b1 100644 --- a/tests/core/pm-module/conftest.py +++ b/tests/core/pm-module/conftest.py @@ -27,7 +27,6 @@ from web3 import Web3 from web3.pm import ( - PM, SolidityReferenceRegistry, VyperReferenceRegistry, ) @@ -61,7 +60,7 @@ def setup_w3(): w3 = Web3(Web3.EthereumTesterProvider(ethereum_tester=t)) w3.eth.defaultAccount = w3.eth.accounts[0] w3.eth.defaultContractFactory = LinkableContract - PM.attach(w3, 'pm') + w3.enable_unstable_package_management_api() return w3 diff --git a/tests/core/pm-module/test_ens_integration.py b/tests/core/pm-module/test_ens_integration.py index 30d7e96ab6..239171f413 100644 --- a/tests/core/pm-module/test_ens_integration.py +++ b/tests/core/pm-module/test_ens_integration.py @@ -13,7 +13,6 @@ InvalidAddress, ) from web3.pm import ( - PM, VyperReferenceRegistry, ) @@ -119,19 +118,18 @@ def ens_setup(deployer): def ens(ens_setup, mocker): mocker.patch('web3.middleware.stalecheck._isfresh', return_value=True) ens_setup.web3.eth.defaultAccount = ens_setup.web3.eth.coinbase + ens_setup.web3.enable_unstable_package_management_api() return ens_setup def test_ens_must_be_set_before_ens_methods_can_be_used(ens): w3 = ens.web3 - PM.attach(w3, 'pm') with pytest.raises(InvalidAddress): w3.pm.set_registry("tester.eth") def test_web3_ens(ens): w3 = ens.web3 - PM.attach(w3, 'pm') ns = ENS.fromWeb3(w3, ens.ens.address) w3.ens = ns registry = VyperReferenceRegistry.deploy_new_instance(w3) diff --git a/tests/core/pm-module/test_registry_integration.py b/tests/core/pm-module/test_registry_integration.py index cf7ced9114..20d9ff8903 100644 --- a/tests/core/pm-module/test_registry_integration.py +++ b/tests/core/pm-module/test_registry_integration.py @@ -16,7 +16,6 @@ PMError, ) from web3.pm import ( - PM, ERCRegistry, VyperReferenceRegistry, get_vyper_registry_manifest, @@ -28,7 +27,7 @@ def fresh_w3(): w3 = Web3(Web3.EthereumTesterProvider()) w3.eth.defaultAccount = w3.eth.accounts[0] w3.eth.defaultContractFactory = LinkableContract - PM.attach(w3, "pm") + w3.enable_unstable_package_management_api() return w3 diff --git a/web3/main.py b/web3/main.py index 4c3290053e..8bc95d9e94 100644 --- a/web3/main.py +++ b/web3/main.py @@ -206,3 +206,18 @@ def ens(self): @ens.setter def ens(self, new_ens): self._ens = new_ens + + @property + def pm(self): + if self._pm is not None: + return self._pm + else: + raise AttributeError( + "The Package Management feature is disabled by default until " + "its API stabilizes. To use these features, please enable them by running " + "`w3.enable_unstable_package_management_api()` and try again." + ) + + def enable_unstable_package_management_api(self): + from web3.pm import PM + PM.attach(self, '_pm')