Skip to content

Latest commit

 

History

History
170 lines (115 loc) · 4.71 KB

developers.md

File metadata and controls

170 lines (115 loc) · 4.71 KB

Developing ocean.py

This README is how to further develop ocean.py. (Compare to the quickstarts which show how to use it.) Steps:

  1. Install dependencies
  2. Run barge services
  3. Set up contracts
  4. Test
  5. Merge the changes via a PR
  6. Release

1. Install dependencies

Prerequisites

Do Install

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

2. Run barge services

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

3. Set up contracts

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

4. Test

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.

5. Merge

Merge the changes via a pull request (PR) etc.

Specifically, follow this workflow.

6. Release

Release for pip etc.

Specifically, follow the Release Process instructions.

7. Appendix: More tests

7.1 Pre-commit hooks

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.

7.2 Code quality tests

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

8. Appendix: Contributing to docs

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.