Skip to content

Commit

Permalink
feat: Refactor base HTTP client to enable request limits to work (#67)
Browse files Browse the repository at this point in the history
* feat: Refactor base HTTP client to enable request limits to work

Fix CI/CD pipelines.
  • Loading branch information
akalex authored Jan 17, 2024
1 parent 5df05bd commit cea753c
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 164 deletions.
48 changes: 26 additions & 22 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
POETRY_VERSION: 1.5.1

jobs:
create-virtualenv:
runs-on: ubuntu-latest
Expand All @@ -20,29 +23,26 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4

- name: virtualenv cache
uses: syphar/[email protected]
id: cache-virtualenv
- name: Install Poetry
uses: snok/install-poetry@v1
with:
custom_cache_key_element: v1.2
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: pip cache
uses: syphar/restore-pip-download-cache@v1
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Python dependencies
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
env:
POETRY_VERSION: 1.6.1
run: |
pip install pip==23.2.1 setuptools==68.2.2
curl -sSL https://install.python-poetry.org | python3 -
export VENV="$(poetry env info -p)"
source ${VENV}/bin/activate
poetry install --no-interaction
- name: Install Dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction -vv

- name: Log currently installed packages and versions
run: pip list
run: poetry show

release:
needs: create-virtualenv
Expand All @@ -56,15 +56,19 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
uses: actions/setup-python@v4

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: Release to PyPI
if: startsWith(github.ref, 'refs/tags/')
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
POETRY_VERSION: 1.6.1
POETRY_VERSION: ${{ env.POETRY_VERSION }}
run: |
pip install pip==23.2.1 setuptools==68.2.2
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
poetry build
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish
117 changes: 79 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
POETRY_VERSION: 1.5.1

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
create-virtualenv:
Expand All @@ -30,35 +33,31 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v3

- name: Set up Python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: virtualenv cache
uses: syphar/[email protected]
id: cache-virtualenv
- name: Install Poetry
uses: snok/install-poetry@v1
with:
custom_cache_key_element: v1.2
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: pip cache
uses: syphar/restore-pip-download-cache@v1
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Python dependencies
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
env:
POETRY_VERSION: 1.6.1
run: |
pip install pip==23.2.1 setuptools==68.2.2
curl -sSL https://install.python-poetry.org | python3 -
export VENV="$(poetry env info -p)"
source ${VENV}/bin/activate
poetry install --no-interaction -vv
- name: Install Dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction -vv

- name: Log currently installed packages and versions
run: pip list
run: poetry show

linters-black:
needs: create-virtualenv
Expand All @@ -68,16 +67,30 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: virtualenv cache
uses: syphar/[email protected]
id: cache-virtualenv
- name: Install Poetry
uses: snok/install-poetry@v1
with:
custom_cache_key_element: v1.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Check code style
run: black --check --line-length=120 --diff async_firebase
run: poetry run black --check --line-length=120 --diff async_firebase

linters-mypy:
needs: create-virtualenv
Expand All @@ -87,16 +100,32 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: virtualenv cache
uses: syphar/[email protected]
id: cache-virtualenv
- name: Install Poetry
uses: snok/install-poetry@v1
with:
custom_cache_key_element: v1.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Static type checker
run: mypy --no-error-summary --hide-error-codes --follow-imports=skip async_firebase
run: |
python -m pip install types-setuptools
poetry run mypy --install-types --no-error-summary --hide-error-codes --follow-imports=skip async_firebase
test:
needs: [ linters-black, linters-mypy ]
Expand All @@ -109,18 +138,30 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: virtualenv cache
uses: syphar/[email protected]
id: cache-virtualenv
- name: Install Poetry
uses: snok/install-poetry@v1
with:
custom_cache_key_element: v1.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Run pytest
run: pytest tests/
run: poetry run pytest tests/

- name: Submit coverage report
if: github.ref == 'refs/heads/master'
Expand Down
12 changes: 0 additions & 12 deletions .isort.cfg

This file was deleted.

9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ repos:
- id: check-yaml

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.1.0
hooks:
- id: black
language_version: python3.8
args: [--line-length=120, --skip-string-normalization]

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.11.5
hooks:
- id: isort
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.1.1
hooks:
- id: mypy
args: [--no-error-summary, --hide-error-codes, --follow-imports=skip]
files: ^async_firebase/
additional_dependencies: [types-setuptools]
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

## 3.4.0
* Refactored ``async_firebase.base.AsyncClientBase`` to take advantage of connection pool. So the HTTP client will be created once during class ``async_firebase.client.AsyncFirebaseClient`` instantiation.

## 3.3.0
* async_firebase now works with python 3.12
* `async_firebase` now works with python 3.12

## 3.2.0
* ``AsyncFirebaseClient`` empower with advanced features to configure request behaviour such as timeout, or connection pooling.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ help:
install:
@echo "$(BOLD)Installing package$(RESET)"
@poetry config virtualenvs.create false
@poetry install --only main --no-root
@poetry install --only main
@echo "$(BOLD)Done!$(RESET)"

.PHONY: update
Expand Down
1 change: 1 addition & 0 deletions async_firebase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .client import AsyncFirebaseClient # noqa


root_logger = logging.getLogger("async_firebase")
if root_logger.level == logging.NOTSET:
root_logger.setLevel(logging.WARN)
Loading

0 comments on commit cea753c

Please sign in to comment.