Skip to content

Commit

Permalink
Latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Shapedsundew9 committed Sep 4, 2023
1 parent 5ff1cd0 commit 8a0a933
Show file tree
Hide file tree
Showing 19 changed files with 1,572 additions and 977 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ jobs:

# Run directly on runner VM
runs-on: ubuntu-latest
container:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
python-version: [3.11]
services:
postgres:
image: postgres:12
image: postgres:15
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -46,17 +45,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install black, pylint, pyright
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: python-isort
# https://github.com/marketplace/actions/python-isort
uses: isort/[email protected]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# The GitHub editor is 127 chars wide
flake8 . --count --max-complexity=13 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
Expand Down
8 changes: 4 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ exclude-too-few-public-methods=
ignored-parents=

# Maximum number of arguments for function / method.
max-args=5
max-args=8

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=15

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5
Expand All @@ -300,7 +300,7 @@ max-returns=6
max-statements=50

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
min-public-methods=1


[EXCEPTIONS]
Expand Down Expand Up @@ -446,7 +446,7 @@ notes-rgx=
[REFACTORING]

# Maximum number of nested blocks for function / method body
max-nested-blocks=5
max-nested-blocks=6

# Complete name of functions that never returns. When checking for
# inconsistent-return-statements if a never returning function is called then
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# pypgtable

A simple interface to Posgres database tables.

[![Python package](https://github.com/Shapedsundew9/pypgtable/actions/workflows/python-package.yml/badge.svg?branch=main)](https://github.com/Shapedsundew9/pypgtable/actions/workflows/python-package.yml)
[![codecov](https://codecov.io/gh/Shapedsundew9/pypgtable/branch/main/graph/badge.svg?token=Z9C9Z9B3T1)](https://codecov.io/gh/Shapedsundew9/pypgtable)

## Sunburst Code Coverage Chart

The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
![Sunburst](https://codecov.io/gh/Shapedsundew9/pypgtable/branch/main/graphs/sunburst.svg)

## Usage Examples

TBD

For more details see [design documentation](docs/pypgtable.md)
2 changes: 1 addition & 1 deletion pypgtable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .table import table
from .database import db_disconnect_all

__all__ = ['table', 'raw_table', 'default_config', 'obscure', 'db_disconnect_all']
__all__ = ["table", "raw_table", "default_config", "obscure", "db_disconnect_all"]
24 changes: 12 additions & 12 deletions pypgtable/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from random import random
from typing import Any, Callable, Generator

from .typing import DatabaseConfigNorm
from .pypgtable_typing import DatabaseConfigNorm


def backoff_generator(initial_delay=0.125, backoff_steps=13, fuzz=True) -> Generator[Any, None, None]:
def backoff_generator(initial_delay: float = 0.125, backoff_steps: int = 13, fuzz: bool = True) -> Generator[Any, None, None]:
"""Generate increasing connection retry attempt delays.
Increase delay by a factor of two each time until maximum delay is reached.
Expand All @@ -16,9 +16,9 @@ def backoff_generator(initial_delay=0.125, backoff_steps=13, fuzz=True) -> Gener
Args
----
initial_delay (float): 1st backoff delay in seconds.
backoff_steps (int): >=0 number of times to double delay before saturating.
fuzz (bool): If true +/-10% fuzz factor to each delay
initial_delay: 1st backoff delay in seconds.
backoff_steps: >=0 number of times to double delay before saturating.
fuzz: If true +/-10% fuzz factor to each delay
Returns
-------
Expand All @@ -44,11 +44,11 @@ def connection_str_from_config(db_config: DatabaseConfigNorm, with_password: boo
A postgresql connection string.
postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
"""
connection_str: str = 'postgresql://'
connection_str += db_config['user']
if with_password and db_config['password'] is not None:
connection_str += ':' + db_config['password']
connection_str += '@' + db_config['host']
connection_str += ':' + str(db_config['port'])
connection_str += '/' + db_config['dbname']
connection_str: str = "postgresql://"
connection_str += db_config["user"]
if with_password and db_config["password"] is not None:
connection_str += ":" + db_config["password"]
connection_str += "@" + db_config["host"]
connection_str += ":" + str(db_config["port"])
connection_str += "/" + db_config["dbname"]
return connection_str
Loading

0 comments on commit 8a0a933

Please sign in to comment.