Skip to content

Commit

Permalink
Merge pull request #5 from rwanyoike/prep-v0.7.0
Browse files Browse the repository at this point in the history
feat: bump version 0.6.x -> 0.7.0
  • Loading branch information
rwanyoike authored Oct 5, 2024
2 parents 55643ef + 56b4f0b commit 4307bd3
Show file tree
Hide file tree
Showing 16 changed files with 792 additions and 1,070 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
end_of_line = lf

[*.py]
indent_size = 4
36 changes: 36 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Python package

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Install poetry using pipx
run: |
pipx install poetry==1.8.3
poetry config virtualenvs.in-project true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Install dependencies
run: poetry install
- name: Run Ruff checks
run: |
poetry run ruff check --select I
poetry run ruff format --check
- name: Test with pytest
run: poetry run pytest --cov=time2relax
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__pycache__/
.mypy_cache/
.pytest_cache/
*.egg-info/
.ruff_cache/
.venv/
dist/
htmlcov/

Expand Down
7 changes: 0 additions & 7 deletions .isort.cfg

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# time2relax: Python CouchDB Driver

[![Travis (.org)](https://img.shields.io/travis/rwanyoike/time2relax.svg)](https://travis-ci.org/rwanyoike/time2relax)
[![Codecov](https://img.shields.io/codecov/c/gh/rwanyoike/time2relax.svg)](https://codecov.io/gh/rwanyoike/time2relax)
[![GitHub](https://img.shields.io/github/license/rwanyoike/time2relax)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/time2relax.svg)](https://pypi.python.org/pypi/time2relax)
[![Code Style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/rwanyoike/time2relax-python-driver/python-package.yml?branch=main)
](https://github.com/rwanyoike/time2relax-python-driver/actions/workflows/python-package.yml?query=branch%3Amain)
[![GitHub License](https://img.shields.io/github/license/rwanyoike/time2relax-python-driver)
](LICENSE.txt)
[![PyPI - Version](https://img.shields.io/pypi/v/time2relax)
](https://pypi.org/project/time2relax)

> A CouchDB driver for Python.
Expand Down
1,079 changes: 325 additions & 754 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions prospector.yml

This file was deleted.

28 changes: 14 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[tool.poetry]
name = "time2relax"
version = "0.6.0"
version = "0.7.0"
description = "A CouchDB driver for Python."
license = "MIT"
authors = ["Raymond Wanyoike <[email protected]>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/rwanyoike/time2relax"
repository = "https://github.com/rwanyoike/time2relax-python-driver"
documentation = "https://github.com/rwanyoike/time2relax-python-driver/tree/main/docs"
packages = [{ include = "time2relax", from = "src" }]
include = ["HISTORY.md"]

[tool.poetry.dependencies]
python = "^3.6"
requests = "^2.22"
python = "^3.8"
requests = "^2.32.3"

[tool.poetry.dev-dependencies]
black = "^19.10b0"
isort = "^4.3.21"
prospector = "^1.2.0"
pytest = "^5.3.4"
pytest-cov = "^2.8.1"
pytest-mock = "^1.11"
[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
pytest-cov = "^5.0.0"
pytest-mock = "^3.14.0"
ruff = "^0.6.9"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions time2relax/models.py → src/time2relax/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, url, create_db=True):

def __repr__(self):
"""Return repr(self)."""
return "<{} [{}]>".format(self.__class__.__name__, self.url)
return f"<{self.__class__.__name__} [{self.url}]>"

@utils.relax(time2relax.all_docs)
def all_docs(self, **kwargs):
Expand Down Expand Up @@ -127,5 +127,4 @@ def request(self, method, path, _init=True, **kwargs):
self.request("PUT", "", _init=False)
self._created = True

r = time2relax.request(self.session, self.url, method, path, **kwargs)
return r
return time2relax.request(self.session, self.url, method, path, **kwargs)
12 changes: 3 additions & 9 deletions time2relax/time2relax.py → src/time2relax/time2relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ def ddoc_list(ddoc_id, func_id, view_id, other_id=None, **kwargs):
:param kwargs: (optional) Arguments that :meth:`requests.Session.request` takes.
:rtype: (str, str, dict)
"""
if other_id:
path = urljoin(utils.encode_document_id(other_id), view_id)
else:
path = view_id
path = urljoin(utils.encode_document_id(other_id), view_id) if other_id else view_id

return _ddoc("GET", ddoc_id, _LIST, func_id, path, **kwargs)

Expand Down Expand Up @@ -311,11 +308,8 @@ def request(session, base_path, method, path, **kwargs):
params[key] = json.dumps(val)
kwargs["params"] = params

if compat.urlparse(path).scheme:
# Support absolute URLs
url = path
else:
url = urljoin(base_path, path).strip("/")
# Support absolute URLs
url = path if compat.urlparse(path).scheme else urljoin(base_path, path).strip("/")

r = session.request(method, url, **kwargs)
# Raise exception on a bad status code
Expand Down
19 changes: 8 additions & 11 deletions time2relax/utils.py → src/time2relax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)


def encode_uri_component(string):
def encode_uri_component(part: str) -> str:
"""Return an encoded URI component.
https://stackoverflow.com/a/6618858
Expand All @@ -38,10 +38,10 @@ def encode_uri_component(string):
>>> encode_uri_component('escaped%2F1')
'escaped%252F1'
:param str string: The URI component.
:param str part: The URI component.
:rtype: str
"""
return compat.quote(string, "~()*!.'")
return compat.quote(part, "~()*!.'")


def encode_attachment_id(_id):
Expand Down Expand Up @@ -72,11 +72,11 @@ def encode_document_id(_id):
"""
if _id.startswith("_design"):
uri = encode_uri_component(_id[8:])
return "_design/{0}".format(uri)
return f"_design/{uri}"

if _id.startswith("_local"):
uri = encode_uri_component(_id[7:])
return "_local/{0}".format(uri)
return f"_local/{uri}"

return encode_uri_component(_id)

Expand Down Expand Up @@ -165,10 +165,7 @@ def raise_http_exception(response):
except ValueError:
message = None

if response.status_code in HTTP_EXCEPTIONS:
ex = HTTP_EXCEPTIONS[response.status_code]
else:
ex = exceptions.HTTPError
ex = HTTP_EXCEPTIONS.get(response.status_code, exceptions.HTTPError)

raise ex(message, response)

Expand All @@ -182,9 +179,9 @@ def relax(f):

def decorator(func):
@functools.wraps(func)
def inner(*args, **k):
def inner(*args, **kwargs):
# Hack-y alternative to copy-pasting
m, p, k = f(*args[1:], **k)
m, p, k = f(*args[1:], **kwargs)
c = args[0]
return c.request(m, p, **k)

Expand Down
16 changes: 8 additions & 8 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@


def test_couchdb():
db = CouchDB('https://u:[email protected]/a/b/index.html?e=f', create_db=False)
assert db.host == 'https://u:[email protected]'
assert db.name == 'index.html'
assert db.url == 'https://u:[email protected]/index.html'
db = CouchDB("https://u:[email protected]/a/b/index.html?e=f", create_db=False)
assert db.host == "https://u:[email protected]"
assert db.name == "index.html"
assert db.url == "https://u:[email protected]/index.html"
assert db.create_db is False
assert db.session.headers['Accept'] == 'application/json'
assert db.session.headers["Accept"] == "application/json"

# Test default create_db value and __repr__
db = CouchDB('http://couchdb:5984/foobar')
db = CouchDB("http://couchdb:5984/foobar")
assert db.create_db is True
assert repr(db) == '<CouchDB [{}]>'.format(db.url)
assert repr(db) == f"<CouchDB [{db.url}]>"


def test_couchdb_raise_exception():
for url in ['', 'http://', 'http://user:pass']:
for url in ["", "http://", "http://user:pass"]:
with pytest.raises(RequestException):
CouchDB(url)
Loading

0 comments on commit 4307bd3

Please sign in to comment.