Skip to content

Commit

Permalink
Merge pull request #1216 from njgheorghita/pm-api-unstable-flag
Browse files Browse the repository at this point in the history
Disable pm api by default
  • Loading branch information
njgheorghita authored Jan 18, 2019
2 parents 02da228 + 8416c8a commit c679af1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
33 changes: 24 additions & 9 deletions docs/web3.pm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@ To learn more about the EthPM spec, visit the `documentation <http://ethpm.githu
To learn more about the Py-EthPM library used in this module, visit the `documentation <https://py-ethpm.readthedocs.io/en/latest/>`__.


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
<web3.pm.PM at 0x....>
Methods
-------
Expand Down
3 changes: 1 addition & 2 deletions tests/core/pm-module/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from web3 import Web3
from web3.pm import (
PM,
SolidityReferenceRegistry,
VyperReferenceRegistry,
)
Expand Down Expand Up @@ -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


Expand Down
4 changes: 1 addition & 3 deletions tests/core/pm-module/test_ens_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
InvalidAddress,
)
from web3.pm import (
PM,
VyperReferenceRegistry,
)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions tests/core/pm-module/test_registry_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
PMError,
)
from web3.pm import (
PM,
ERCRegistry,
VyperReferenceRegistry,
get_vyper_registry_manifest,
Expand All @@ -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


Expand Down
15 changes: 15 additions & 0 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit c679af1

Please sign in to comment.