This README is how to further develop ocean.py. (Compare to the quickstarts which show how to use it.) Steps:
- Install dependencies
- Run barge services
- Set up contracts
- Test
- Merge the changes via a PR
- Release
- Linux/MacOS
- Docker, allowing non-root users
- Python 3.8.5+
In a new console that we'll call the work console (as we'll use it later):
#clone the repo and enter into it
git clone https://github.com/oceanprotocol/ocean.py
cd ocean.py
#Install OS dependencies
sudo apt-get install -y python3-dev gcc python-pytest
#Initialize virtual environment and activate it.
python -m venv venv
source venv/bin/activate
#Install modules in the environment.
pip install -r requirements_dev.txt
In a new console:
#grab repo
git clone https://github.com/oceanprotocol/barge
cd barge
#clean up old containers (to be sure)
docker system prune -a --volumes
#run barge: start ganache, Provider, Aquarius; deploy contracts; update ~/.ocean
./start_ocean.sh --with-provider2
(Or, run services separately.)
In work console:
#specify config file as an envvar
export OCEAN_CONFIG_FILE=config.ini
#set private keys of two accounts
export TEST_PRIVATE_KEY1=0x5d75837394b078ce97bc289fa8d75e21000573520bfa7784a9d28ccaae602bf8
export TEST_PRIVATE_KEY2=0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209
In work console:
export OPERATOR_SERVICE_URL=https://c2d-dev.operator.oceanprotocol.com/
#run a single test
pytest ocean_lib/models/test/test_btoken.py::test_ERC20
#run all tests in a file
pytest ocean_lib/models/test/test_btoken.py
#run all tests
pytest
#run all tests, using CI tooling
tox
For envvars that aren't set, pytest
uses values in pytest.ini
, and tox
uses values in tox.ini
.
Bonus: see the appendix for even more tests.
Merge the changes via a pull request (PR) etc.
Specifically, follow this workflow.
Release for pip etc.
Specifically, follow the Release Process instructions.
In main console (with venv on):
pre-commit install
Now, this will auto-apply isort (import sorting), flake8 (linting) and black (automatic code formatting) to commits. Black formatting is the standard and is checked as part of pull requests.
Use codacy-analysis-cli.
First, install once. In a new console:
curl -L https://github.com/codacy/codacy-analysis-cli/archive/master.tar.gz | tar xvz
cd codacy-analysis-cli-* && sudo make install
In main console (with venv on):
#run all tools, plus Metrics and Clones data.
codacy-analysis-cli analyze --directory ~/code/ocean.py/ocean_lib/ocean
#run tools individually
codacy-analysis-cli analyze --directory ~/code/ocean.py/ocean_lib/ocean --tool Pylint
codacy-analysis-cli analyze --directory ~/code/ocean.py/ocean_lib/ocean --tool Prospector
codacy-analysis-cli analyze --directory ~/code/ocean.py/ocean_lib/ocean --tool Bandit
You'll get a report that looks like this.
Found [Info] `First line should end with a period (D415)` in ocean_compute.py:50 (Prospector_pep257)
Found [Info] `Missing docstring in __init__ (D107)` in ocean_assets.py:42 (Prospector_pep257)
Found [Info] `Method could be a function` in ocean_pool.py:473 (PyLint_R0201)
Found [Warning] `Possible hardcoded password: ''` in ocean_exchange.py:23 (Bandit_B107)
Found [Metrics] in ocean_exchange.py:
LOC - 68
CLOC - 4
#methods - 6
(C)LOC = (Commented) Lines Of Code.
Finally, you can go here to see results of remotely-run tests. (You may need special permissions.)
You are welcome to contribute to ocean.py docs and READMEs. For clean markdowns in the READMEs folder, we use the remark
tool for automatic markdown formatting.
OCEAN has an official repository containing remark settings, so please follow the instructions here.
To update the documentation shown in https://docs.oceanprotocol.com/references/read-the-docs/ocean-py/, go to https://github.com/oceanprotocol/readthedocs, and follow the steps.