Skip to content

tox, poetry, ci, first cut #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/circle_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
poetry>=1.1.6
tox>=3.23.1
tox-poetry>=0.3.0
148 changes: 120 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2.1
commands:

abort_for_docs:
steps:
- run:
name: Avoid tests for docs
command: |
if [[ $CIRCLE_BRANCH == *docs ]]; then
echo "Identifies as documents PR, no testing required"
circleci step halt
fi

abort_for_noci:
steps:
- run:
name: Ignore CI for specific branches
command: |
if [[ $CIRCLE_BRANCH == *noci ]]; then
echo "Identifies as actively ignoring CI, no testing required."
circleci step halt
fi


early_return_for_forked_pull_requests:
description: >-
If this build is from a fork, stop executing the current job and return success.
Expand All @@ -12,33 +30,44 @@ commands:
- run:
name: Early return if this build is from a forked PR
command: |
if [ -n "$CIRCLE_PR_NUMBER" ]; then
if [[ -n "$CIRCLE_PR_NUMBER" ]]; then
echo "Nothing to do for forked PRs, so marking this step successful"
circleci step halt
fi
jobs:
build:
docker:
- image: circleci/python:3.6.1

- image: redislabs/redisgraph:edge

working_directory: ~/repo

build_and_test:
steps:
- abort_for_docs
- abort_for_noci
- checkout

- restore_cache: # Download and cache dependencies
keys:
- v1-dependencies-{{ checksum "pyproject.toml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run:
name: Install tox
command: sudo pip install tox
name: install tox dependencies
command: |
pip install --user --quiet -r .circleci/circle_requirements.txt

- save_cache:
paths:
- ./.tox
- ~/.cache/pip
key: v1-dependencies-{{ checksum "pyproject.toml" }}


- run:
name: Test package build
command: tox -e sdist
name: build sdist and wheels
command: |
poetry build

- run:
name: Run code styles
command: tox -e pep8
name: lint
command: |
tox -e linters

- run:
name: Run unittest with coverage
Expand All @@ -49,27 +78,90 @@ jobs:
command: tox -e func

- early_return_for_forked_pull_requests

- run:
name: codecove
name: codecov
command: |
. .tox/func/bin/activate
codecov --file .tox/cover/report/coverage.xml --name ${CODECOV_NAME}-unittests
codecov --file .tox/func/report/coverage.xml --name ${CODECOV_NAME}-functional

docker:
parameters:
docker_version:
type: string
default: "edge"
steps:
- setup_remote_docker
- run:
name: dockers
description: Build and release docker
command: |
bash <(curl -fsSL https://get.docker.com)
docker login -u redisfab -p $DOCKER_REDISFAB_PWD
docker build -t redisgraph:<<parameters.docker_version>> .
docker push

jobs:
build:
parameters:
python_version:
type: string
docker:
- image: circleci/python:<<parameters.python_version>>
- image: redislabs/redisgraph:edge
steps:
- build_and_test

# since this is used by cron, we by default build against latest
build_and_publish:
parameters:
docker_version:
type: string
default: "edge"
docker:
- image: circleci/python:latest
- image: redislabs/redisgraph:edge

steps:
- build_and_test
- docker

on-any-branch: &on-any-branch
filters:
branches:
only:
- /.*/
tags:
ignore: /.*/

on-master: &on-master
filters:
branches:
only:
- master

# the is to build and test, per commit against all supported python versions
python-versions: &python-versions
matrix:
parameters:
python_version:
- "3.6.9"
- "3.7.9"
- "3.8.9"
- "3.9.4"
- "latest"

workflows:
version: 2
commit:
jobs:
- build
- build:
<<: *on-any-branch
<<: *python-versions

nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
<<: *on-master
jobs:
- build
- build_and_publish
55 changes: 24 additions & 31 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
name: Publish Pypi
on:
release:
types: [published]
types: [ published ]

jobs:
publish:
name: publish
pytest:
name: Publish to PyPi
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- uses: actions/checkout@master
- name: Set up Python 2.7
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 2.7
python-version: 3.7

- name: Install twine
run: |
pip install twine

- name: Install wheel
run: |
pip install wheel

- name: Create a source distribution
run: |
python setup.py sdist
- name: Install Poetry
uses: dschep/[email protected]

- name: Create a wheel
run: |
python setup.py bdist_wheel
- name: Cache Poetry virtualenv
uses: actions/cache@v1
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ hashFiles('**/poetry.lock') }}

- name: Create a .pypirc
- name: Set Poetry config
run: |
echo -e "[pypi]" >> ~/.pypirc
echo -e "username = __token__" >> ~/.pypirc
echo -e "password = ${{ secrets.PYPI_TOKEN }}" >> ~/.pypirc
echo -e "[testpypi]" >> ~/.pypirc
echo -e "username = __token__" >> ~/.pypirc
echo -e "password = ${{ secrets.TESTPYPI_TOKEN }}" >> ~/.pypirc
poetry config virtualenvs.in-project false
poetry config virtualenvs.path ~/.virtualenvs

- name: Publish to Test PyPI
if: github.event_name == 'release'
run: |
twine upload --skip-existing -r testpypi dist/*
- name: Install Dependencies
run: poetry install
if: steps.cache.outputs.cache-hit != 'true'

- name: Publish to PyPI
if: github.event_name == 'release'
run: |
twine upload -r pypi dist/*
poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }} --build
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM redislabs/redisgraph:edge as builder

RUN apt update && apt install -y python3 python3-pip
ADD . /build
WORKDIR /build
RUN pip3 install poetry
RUN poetry config virtualenvs.create false
RUN poetry build

### clean docker stage
FROM redislabs/redisgraph:edge as runner

RUN apt update && apt install -y python3 python3-pip
RUN rm -rf /var/cache/apt/

COPY --from=builder /build/dist/redisgraph*.tar.gz /tmp/
RUN pip3 install /tmp/redisgraph*.tar.gz
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![PyPI version](https://badge.fury.io/py/redisgraph.svg)](https://badge.fury.io/py/redisgraph)
[![GitHub issues](https://img.shields.io/github/release/RedisGraph/redisgraph-py.svg)](https://github.com/RedisGraph/redisgraph-py/releases/latest)
[![Codecov](https://codecov.io/gh/RedisGraph/redisgraph-py/branch/master/graph/badge.svg)](https://codecov.io/gh/RedisGraph/redisgraph-py)
[![Known Vulnerabilities](https://snyk.io/test/github/RedisGraph/redisgraph-py/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/RedisGraph/redisgraph-py?targetFile=requirements.txt)
[![Known Vulnerabilities](https://snyk.io/test/github/RedisGraph/redisgraph-py/badge.svg?targetFile=pyproject.toml)](https://snyk.io/test/github/RedisGraph/redisgraph-py?targetFile=pyproject.toml)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/RedisGraph/redisgraph-py.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/RedisGraph/redisgraph-py/alerts/)

# redisgraph-py
Expand Down Expand Up @@ -91,7 +91,13 @@ pip install git+https://github.com/RedisGraph/redisgraph-py.git@master

### Install for development in env

```
tox -e env
source ./tox/env/bin/activate
```
1. Create a virtualenv to manage your python dependencies, and ensure it's active.
```virtualenv -v venv; source venv/bin/activate```

2. Install [pypoetry](https://python-poetry.org/) to manage your dependencies.
```pip install poetry```

3. Install dependencies.
```poetry install```

[tox](https://tox.readthedocs.io/en/latest/) runs all code linters as its default target.
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[tool.poetry]
name = "redisgraph"
version = "2.4.0"
description = "RedisGraph Python Client"
authors = ["RedisLabs <[email protected]>"]
license = "BSD-3-Clause"
readme = "README.md"
keywords = ["Redis", "Graph"]
classifiers=[
'Topic :: Database',
'Programming Language :: Python',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'License :: OSI Approved :: BSD License',
'Development Status :: 5 - Production/Stable'
]

[tool.poetry.urls]
url = "https://redisgraph.io"
repository = "https://github.com/RedisGraph/redisgraph-py"

[tool.poetry.dependencies]
python = "^3.6"
redis = "^3.5.3"
prettytable = "^2.1.0"

[tool.poetry.dev-dependencies]
tox = "^3.23.1"
pytest = "^6.2.4"
pytest-cov = "^2.12.0"
pytest-html = "^3.1.1"
testtools = "^2.4.0"
mock = "^4.0.3"
codecov = "^2.1.11"
flake8 = "^3.9.2"
tox-poetry = "^0.3.0"
vulture = "^2.3"
bandit = "^1.7.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion redisgraph/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def random_string(length=10):
"""
Returns a random N character long string.
"""
return ''.join(random.choice(string.ascii_lowercase) for x in range(length))
return ''.join(random.choice(string.ascii_lowercase) for x in range(length)) # nosec


def quote_string(v):
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

Loading