Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from CasperLabs/release-v0.20
Browse files Browse the repository at this point in the history
Merge Release v0.20 to master
  • Loading branch information
TomVasile authored Jul 21, 2020
2 parents 11d7738 + 0987245 commit ed5645a
Show file tree
Hide file tree
Showing 107 changed files with 10,266 additions and 66 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.tox/
.eggs/
.pytest_cache/
casperlabs_client/proto/
dist/
casperlabs_client.egg-info/
manual-test/
155 changes: 155 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
platform:
os: linux
arch: amd64

# Begin
clone:
git-clone:
commands: |
set -ex
git clone -b ${DRONE_TAG:-$DRONE_BRANCH} $DRONE_REMOTE_URL .
if [ x$DRONE_PULL_REQUEST != x ]; then
git fetch origin refs/pull/$DRONE_PULL_REQUEST/head
EMAIL=ci git merge --no-edit FETCH_HEAD
fi
git rev-parse HEAD
image: "casperlabs/buildenv"

# NOTE: Anchors are per document
# Anchor for default buildenv
__buildenv: &buildenv
image: "casperlabs/buildenv:latest"

kind: pipeline
name: build

steps:
- name: update-test-version
<<: *buildenv
commands:
- "VERSION=`cat casperlabs_client/VERSION`"
- "echo $VERSION.$DRONE_BUILD_NUMBER > casperlabs_client/VERSION"
- sed -i 's/NAME = \"casperlabs_client\"/NAME = \"casperlabs_client_test\"/g' setup.py

- name: build-python-client
<<: *buildenv
commands:
- "make clean"
- "make build"
depends_on:
- update-test-version

- name: test-python-client
<<: *buildenv
commands:
- "make clean-make"
- "make test-all"
depends_on:
- build-python-client

- name: test-pypi-publish
image: tvasile1012/pypi:latest
failure: "ignore"
settings:
username:
from_secret: test_pypi_user
password:
from_secret: test_pypi_pass
repository: "https://test.pypi.org/legacy/"
setupfile: "./setup.py"
dist_dir: "./dist/"
skip_build: true
when:
branch:
- dev
event:
- push
depends_on:
- build-python-client

trigger:
branch:
- dev
- master
- trying
- staging

---
# Anchor for default buildenv
__buildenv: &buildenv
image: "casperlabs/buildenv:latest"

kind: pipeline
name: on-tag

steps:
- name: build-python-client-tag
<<: *buildenv
commands:
- "make clean"
- "make build"

- name: pypi-publish-tag
image: tvasile1012/pypi:latest
failure: "ignore"
settings:
username:
from_secret: pypi_user
password:
from_secret: pypi_pass
setupfile: "./setup.py"
dist_dir: "./dist/"
skip_build: true
depends_on:
- build-python-client-tag

- name: github-publish-tag
settings:
api_key:
from_secret: github_token
checksum:
- sha256
- md5
files:
- "./dist/*.gz"
prerelease:
- true
image: plugins/github-release
depends_on:
- build-python-client-tag

trigger:
ref:
- refs/tags/v*

---
kind: pipeline
name: failed-build-alert

clone:
disable: true

steps:
- name: notify
image: plugins/slack
settings:
webhook:
from_secret: slack_webhook
template:
- |
client-py build status: *{{ uppercasefirst build.status }}*
Author: {{ build.author }}
Drone Build: <{{ build.link }}|#{{ build.number }}>
Commit Link: <https://github.com/{{repo.owner}}/{{repo.name}}/commit/{{build.commit}}|{{ truncate build.commit 10 }}>
trigger:
status:
- failure
branch:
- dev
- master
- trying
- staging

depends_on:
- build
75 changes: 9 additions & 66 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ share/python-wheels/
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Expand All @@ -51,56 +45,12 @@ coverage.xml
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
Expand All @@ -110,20 +60,13 @@ ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# PyCharm
.idea/

# Pyre type checker
.pyre/
# Project specific
*_pb2.py
*_pb2_grpc.py
casperlabs_client/proto
casperlabs_client/*_grpc.py
report.json
*.wasm
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: debug-statements
- id: check-docstring-first
- id: trailing-whitespace
- id: fix-encoding-pragma
- id: flake8
args:
- --ignore=E203, E501, W503, E402
- --exclude=(\*_pb2.py|\*_pb2_grpc.py)
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3
61 changes: 61 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Building the Python Client

Python 3.7+ is the required version for the client. The `Pipenv` and `Pipenv.lock` is using
Python 3.7.

### Requirements

Compilation is needed for some of the cryptography dependencies for the client, so `python3.7-dev` should be installed
with `sudo apt install python3.7-dev`.

We use `pipenv` for the virtual environment. This isolates installed packages for the client from your system
python install. This can be installed on Debian based systems with `sudo apt install pipenv`.

`pipenv` is installed to the user's `.local/bin` folder. This will not be accessible without adding your
`~/.local/bin` folder to `$PATH` in `.bashrc` or with other means.

### Initialize pipenv

`pipenv sync` will install all packages needed from the `Pipenv.lock` file.

`pipenv shell` will open a shell inside the virtual environment.

### Setup git precommit hooks

This repo uses the python `pre-commit` package for pre-commit hooks. This package and `flake8` should be installed
during the `pipenv sync` above.

Inside the `pipenv`, run `python -m pre-commit install`.

To run the hook outside of git triggered events, you can use:

`pre-commit run` or `pre-commit run --all-files`. This are also available as part of the Makefile.

### Makefile

Many functions are available in the Makefile. To see all commands use `make help`.

### CasperLabs repo dependency

Building this package depends on the `proto` files available in the CasperLabs repo. This is expected
to be in the same level directory of `client-py` repo.

For running tests inside `manual-test`, the `CasperLabs/hack/docker` network stand-up is used. This expects
all of the prerequisites to run `make docker-build-all` in the root of `CasperLabs` repo as well as
`make contracts-rs` in `CasperLabs/execution-engine` for some `.wasm` contracts that are used in testing.

### Building Distribution package

`python setup.py sdist` will build the Python Client for distributing into `dist/casperlabs_client-X.X.X.tar.gz`.
`make build` performs this command.

The package can be installed for testing with `python -m pip install dist/casperlabs_client-X.X.X.tar.gz`.

If run outside of the pipenv, use `python3.7 -m pip install dist/casperlavs_client-X.X.X.tar.gz`

### Building Development package

It is best practice to test the installed version of a Python package. The tests have been created to run on the installed version.

Inside the pipenv, run `python setup.py develop` or `make develop`. This makes the `casperlabs_client` library and CLI available, but
will also reference actual source in the package. So changes to source files immediately affect the installed package.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.8-slim-buster
MAINTAINER "CasperLabs, LLC. <[email protected]>"

USER root
WORKDIR /opt/docker

RUN apt-get update \
&& apt-get install -y --no-install-recommends g++ protobuf-compiler make \
&& apt-get clean

ENTRYPOINT ["casperlabs_client"]

# COPY and run pip install before other source, so cached with src changes.
COPY requirements.txt /src/requirements.txt
RUN cd /src \
&& pip install -r requirements.txt

COPY . /src

RUN cd /src \
&& python setup.py sdist \
&& python -m pip install dist/casperlabs_client* \
&& pytest tests
Loading

0 comments on commit ed5645a

Please sign in to comment.