Skip to content

Commit

Permalink
Merge 977b98a into bf04c05
Browse files Browse the repository at this point in the history
  • Loading branch information
shawalli committed Jul 20, 2020
2 parents bf04c05 + 977b98a commit 92225e7
Show file tree
Hide file tree
Showing 20 changed files with 563 additions and 343 deletions.
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ common_steps: &common_steps
working_directory: ~/repo
steps:
- checkout
- restore_cache:
key: v1-deps-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }}-{{ checksum "requirements.txt" }}
- run:
name: Install Dependencies
command: pip install --user tox coveralls
Expand Down
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 120
max-complexity = 10
exclude =
psycopg2_pgevents/__init__.py,
tests
142 changes: 142 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Build, Lint, Test

on:
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize

jobs:
lint:
name: ️⚒️ & 👕

strategy:
matrix:
python-version: [3.7, 3.8]

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
uses: dschep/install-poetry-action@v1.3
with:
create_virtualenvs: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
- name: Set Poetry config
run: |
poetry config virtualenvs.in-project false
poetry config virtualenvs.path ~/.virtualenvs
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install

- name: Run pre-commit
if: github.event_name == 'pull_request'
run: |
git fetch origin master:master
poetry run pre-commit run --from-ref master --to-ref HEAD
test:
name: 🧪
needs: lint

strategy:
matrix:
python-version: [3.7, 3.8]

runs-on: ubuntu-latest

services:
postgres:
image: postgres:10-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
uses: dschep/install-poetry-action@v1.3
with:
create_virtualenvs: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
- name: Set Poetry config
run: |
poetry config virtualenvs.in-project false
poetry config virtualenvs.path ~/.virtualenvs
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install

- name: Unit Test
env:
TEST_DATABASE_BASE_URL: postgresql://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}
run: poetry run python -m pytest --cov=psycopg2_pgevents --cov-branch tests/

- name: Submit Code Coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: py-${{ matrix.python-version }}
COVERALLS_PARALLEL: true
run: poetry run coveralls

test-finish:
name: 🚪
needs: test

runs-on: ubuntu-latest
container: python:3-slim

steps:
- name: Finished
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip3 install coveralls
coveralls --finish
73 changes: 73 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Package, Ship

on:
push:
branches:
- master

jobs:
package:
name: 📦 & 🚢

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: '0'

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Get next package version
id: bumpversion
uses: anothrNick/github-tag-action@1.23.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
DRY_RUN: true

- name: Install poetry
uses: dschep/install-poetry-action@v1.3
with:
create_virtualenvs: true

- name: Bump release version
run: poetry version ${{ steps.bumpversion.outputs.new_tag }}

- name: Build package
run: poetry build

- name: Publish package (Test PyPI)
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_PASSWORD }}
poetry publish -r testpypi
- name: Publish package (PyPI)
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_PASSWORD }}
poetry publish
- name: Generate release message
id: release_message
run: |
# Get (squashed) commit summaries since last tag, convert to list,
# escape multi-lines into a format GitHub Actions respect, and set as output
export NOTES=`git log --pretty=format:'%s' $(git describe --tags --abbrev=0 HEAD^)..HEAD | tr '\n' '\0' | xargs -0 -I{} echo '- {}'`
export NOTES_ENCODED_NEWLINES="${NOTES//$'\n'/'%0A'}"
echo "::set-output name=message::$NOTES_ENCODED_NEWLINES"
- name: Create release
uses: actions/create-release@v1.1.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.bumpversion.outputs.new_tag }}
release_name: ${{ steps.bumpversion.outputs.new_tag }}
body: ${{ steps.release_message.outputs.message}}
draft: false
prerelease: false
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
known_third_party = psycopg2,pytest,testfixtures
multi_line_output=3
include_trailing_comma=True
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
repos:
- repo: https://gitlab.com/smop/pre-commit-hooks
rev: v1.0.0
hooks:
- id: check-poetry
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.0.9
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit
rev: v2.6.0
hooks:
- id: validate_manifest
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
12 changes: 0 additions & 12 deletions psycopg2_pgevents/__about__.py

This file was deleted.

19 changes: 13 additions & 6 deletions psycopg2_pgevents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
"""This package provides the ability to listen for PostGreSQL table events at the database level."""
from psycopg2_pgevents.__about__ import __author__, __copyright__, __email__, __license__, __summary__, \
__title__, __uri__, __version__


from psycopg2_pgevents.debug import log, set_debug
from psycopg2_pgevents.event import poll, register_event_channel, unregister_event_channel
from psycopg2_pgevents.event import (
poll,
register_event_channel,
unregister_event_channel,
)
from psycopg2_pgevents.sql import execute
from psycopg2_pgevents.trigger import install_trigger, install_trigger_function, trigger_function_installed, \
trigger_installed, uninstall_trigger, uninstall_trigger_function
from psycopg2_pgevents.trigger import (
install_trigger,
install_trigger_function,
trigger_function_installed,
trigger_installed,
uninstall_trigger,
uninstall_trigger_function,
)
16 changes: 8 additions & 8 deletions psycopg2_pgevents/debug.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""This module provides functionality for debug logging within the package."""
__all__ = ['log', 'set_debug']
__all__ = ["log", "set_debug"]

from contextlib import contextmanager
from typing import Generator
import logging
import sys
from contextlib import contextmanager
from typing import Generator

_DEBUG_ENABLED = False

_LOGGER_NAME = 'pgevents.debug'
_LOGGER_NAME = "pgevents.debug"


def set_debug(enabled: bool):
Expand All @@ -23,11 +23,11 @@ def set_debug(enabled: bool):
global _DEBUG_ENABLED

if not enabled:
log('Disabling debug output...', logger_name=_LOGGER_NAME)
log("Disabling debug output...", logger_name=_LOGGER_NAME)
_DEBUG_ENABLED = False
else:
_DEBUG_ENABLED = True
log('Enabling debug output...', logger_name=_LOGGER_NAME)
log("Enabling debug output...", logger_name=_LOGGER_NAME)


@contextmanager
Expand All @@ -54,7 +54,7 @@ def _create_logger(name: str, level: int) -> Generator[logging.Logger, None, Non

# Setup handler and add to logger
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s %(levelname)-5s [%(name)s]: %(message)s')
formatter = logging.Formatter("%(asctime)s %(levelname)-5s [%(name)s]: %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)

Expand All @@ -68,7 +68,7 @@ def _create_logger(name: str, level: int) -> Generator[logging.Logger, None, Non
handler.close()


def log(message: str, *args: str, category: str='info', logger_name: str='pgevents'):
def log(message: str, *args: str, category: str = "info", logger_name: str = "pgevents"):
"""Log a message to the given logger.
If debug has not been enabled, this method will not log a message.
Expand Down

0 comments on commit 92225e7

Please sign in to comment.