Skip to content

Commit

Permalink
[chore] Updates Python version, migrates to poetry (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenoak authored Oct 9, 2023
1 parent 450ca7e commit 5f29095
Show file tree
Hide file tree
Showing 10 changed files with 876 additions and 414 deletions.
189 changes: 18 additions & 171 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,192 +1,39 @@
version: 2.1

commands:

bumpversion:
description: "Uses bump2version to increase version number"
parameters:
version_part:
type: enum
enum: ['major', 'minor', 'patch', 'pre_release', 'pre_release_num']
bump_options:
type: string
default: '--no-tag --commit -m "Bump version: {current_version} → {new_version} [ci skip]"'
steps:
- restore_cache:
key: v1-bumpversion
- run:
name: Install/Upgrade bumpversion
command: |
python3 -m venv venv
. venv/bin/activate
pip3 install -U bump2version
- save_cache:
key: v1-bumpversion
paths:
- "venv"
- run:
name: Bumpversion
command: |
git config --global user.email "[email protected]"
git config --global user.name "Git Robot"
. venv/bin/activate
python3 setup.py --version
bumpversion << parameters.bump_options >> << parameters.version_part >>
python3 setup.py --version
git log -n 1
- run:
name: Push version bump
command: |
git push -u origin $CIRCLE_BRANCH
publish:
description: "Uses twine to publish packages to PyPI"
parameters:
verify_tag:
type: boolean
default: false
steps:
- restore_cache:
keys:
- v1-release-{{ .Branch }}-{{ checksum "requirements.txt" }}
- v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-py37
- run:
name: Install/Upgrade release requirements
command: |
python3 -m venv venv
. venv/bin/activate
pip3 install -U -r requirements.txt
pip3 install -U wheel
pip3 install -U twine
- save_cache:
key: v1-release-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
- "venv"
- when:
condition: << parameters.verify_tag >>
steps:
- run:
name: Verify git tag vs. package version
command: |
. venv/bin/activate
python setup.py verify
- run:
name: Publish to PyPI
command: |
. venv/bin/activate
python3 setup.py sdist
python3 setup.py bdist_wheel
twine upload dist/*
orbs:
python: circleci/[email protected]

jobs:

install_deps_py37:
unittest_py38:
docker:
- image: circleci/python:3.7
steps:
- checkout
- restore_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}
- run:
name: Install package dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip3 install -U -r requirements.txt
- save_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-py37
paths:
- "venv"

unittest_py37:
docker:
- image: circleci/python:3.7
- image: cimg/python:3.8
environment:
PYTEST_ADDOPTS: --cov-report=xml:test-reports/coverage.xml --junitxml=test-reports/junit.xml
steps:
- checkout
- restore_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-py37
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "poetry.lock" }}-py38
- python/install-packages:
pkg-manager: poetry
- run:
name: Fix arango-orm dependencies
command: |
poetry run pip install six
- run:
name: Run tests
command: |
. venv/bin/activate
python3 setup.py test
poetry run pytest -vv --cov=flask_arango_orm tests/
- save_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "poetry.lock" }}-py38
paths:
- "~/.cache/pypoetry"
- store_test_results:
path: test-reports
- store_artifacts:
path: test-reports
- run:
name: Smoke Test Install
command: |
. venv/bin/activate
python3 --version
python3 setup.py install
bump_publish_dev:
docker:
- image: circleci/python:3.7
environment:
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
steps:
- checkout
- publish
- bumpversion:
version_part: pre_release_num

bump_publish_release:
docker:
- image: circleci/python:3.7
steps:
- checkout
- publish
- bumpversion:
version_part: pre_release_num

publish_prod_tag:
docker:
- image: circleci/python:3.7
steps:
- checkout
- publish:
verify_tag: true

workflows:
version: 2

build_test_publish_py37:
build_test_publish_py38:
jobs:
- install_deps_py37:
filters:
tags:
only: /.*/
- unittest_py37:
requires:
- install_deps_py37
filters:
tags:
only: /.*/
- bump_publish_dev:
context: Test PyPI
requires:
- unittest_py37
filters:
branches:
only: develop
- bump_publish_release:
context: Prod PyPI
requires:
- unittest_py37
filters:
branches:
only: /^release\/.*/
- publish_prod_tag:
context: Prod PyPI
requires:
- unittest_py37
filters:
tags:
only: /^v[0-9]+(\.[0-9]+)+$/
branches:
ignore: /.*/
- unittest_py38
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

83 changes: 47 additions & 36 deletions flask_arango_orm/arango.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

from arango import ArangoClient
from arango_orm import ConnectionPool, Database
from flask import current_app, _app_ctx_stack
from flask import current_app, Flask

ARANGODB_CLUSTER = False
ARANGODB_HOST = ('http', '127.0.0.1', 8529)


class ArangoORM():
class ArangoORM:
"""Flask extension for integrating the arango_orm package"""

def __init__(self, app=None):
def __init__(self, app: Flask = None):
"""Constructor
If a flask app instance is passed as an argument,
Expand All @@ -25,7 +25,7 @@ def __init__(self, app=None):
if app is not None:
self.init_app(app)

def init_app(self, app):
def init_app(self, app: Flask):
"""Initializes ArangoORM for use with the passed app instance
Sets up the following defaults:
Expand All @@ -39,8 +39,10 @@ def init_app(self, app):
:type app: flask.Flask
:return:
"""
app.config.setdefault('ARANGODB_CLUSTER', ARANGODB_CLUSTER)
app.config.setdefault('ARANGODB_HOST', ARANGODB_HOST)
if self.app is None:
self.app = app
self.app.config.setdefault('ARANGODB_CLUSTER', ARANGODB_CLUSTER)
self.app.config.setdefault('ARANGODB_HOST', ARANGODB_HOST)

def connect(self):
"""Sets up the connection to the arangodb database
Expand All @@ -60,29 +62,40 @@ def connect(self):
:returns: Connection to arangodb
:rtype: arango_orm.Database
"""
db_name = current_app.config['ARANGODB_DATABASE']
username = current_app.config['ARANGODB_USER']
password = current_app.config['ARANGODB_PASSWORD']

if current_app.config['ARANGODB_CLUSTER'] == True:
hosts = []
host_pool = current_app.config['ARANGODB_HOST_POOL']
for protocol, host, port in host_pool:
hosts.append(ArangoClient(protocol=protocol,
host=host,
port=port))
return ConnectionPool(hosts,
dbname=db_name,
password=password,
username=username)
else:
protocol, host, port = current_app.config['ARANGODB_HOST']
client = ArangoClient(protocol=protocol,
host=host,
port=port)
return Database(client.db(name=db_name,
username=username,
password=password))
with current_app.app_context():
db_name = current_app.config['ARANGODB_DATABASE']
username = current_app.config['ARANGODB_USER']
password = current_app.config['ARANGODB_PASSWORD']

if current_app.config['ARANGODB_CLUSTER']:
hosts = []
host_pool = current_app.config['ARANGODB_HOST_POOL']
for protocol, host, port in host_pool:
hosts.append(
ArangoClient(
hosts="{protocol}://{host}:{port}".format(
protocol=protocol,
host=host,
port=port
)
)
)
return ConnectionPool(hosts,
dbname=db_name,
password=password,
username=username)
else:
protocol, host, port = current_app.config['ARANGODB_HOST']
client = ArangoClient(
hosts="{protocol}://{host}:{port}".format(
protocol=protocol,
host=host,
port=port
)
)
return Database(client.db(name=db_name,
username=username,
password=password))

@property
def connection(self):
Expand All @@ -93,12 +106,10 @@ def connection(self):
connection does not currently exist, :py:func:`connect` is
called.
:returns: ArangoDB connection
:returns: ArangoDB.connection
:rtype: arango_orm.Database
"""
ctx = _app_ctx_stack.top
if ctx is not None:
if not hasattr(ctx, 'arangodb'):
setattr(ctx, 'arangodb', self.connect())
# ctx.arangodb = self.connect()
return ctx.arangodb
with current_app.app_context():
if not hasattr(current_app, 'arangodb'):
setattr(current_app, 'arangodb', self.connect())
return current_app.arangodb
Loading

0 comments on commit 5f29095

Please sign in to comment.