Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from WardPearce/Development
Browse files Browse the repository at this point in the history
0.0.8
  • Loading branch information
WardPearce committed Jun 14, 2021
2 parents f1d7010 + 1de00a6 commit dd02157
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: Python application
name: Base Development workflow

on: [push]
on:
push:
branches:
- Development

jobs:
build:
base-production:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/checkout@v2.3.2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -22,4 +25,9 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
# exit-zero treats all errors as warnings
flake8 . --count --max-line-length=80 --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
flake8 . --count --max-line-length=80 --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
- name: Run unit tests
env:
KEY_ID: ${{ secrets.KEY_ID }}
KEY: ${{ secrets.KEY }}
run: python run_tests.py --key_id $KEY_ID --key $KEY
42 changes: 42 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Base master workflow

on:
push:
branches:
- master

jobs:
base-production:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
# exit-zero treats all errors as warnings
flake8 . --count --max-line-length=80 --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
- name: Run unit tests
env:
KEY_ID: ${{ secrets.KEY_ID }}
KEY: ${{ secrets.KEY }}
run: python run_tests.py --key_id $KEY_ID --key $KEY
- name: Pack to pypi
env:
PYPI_USER: ${{ secrets.PYPI_USER }}
PYPI_PASS: ${{ secrets.PYPI_PASS }}
run: |
python -m pip install --upgrade build
python -m pip install --user --upgrade twine
python -m build
python -m twine upload --username $PYPI_USER --password $PYPI_PASS --repository pypi dist/*
23 changes: 13 additions & 10 deletions backblaze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import asyncio
import threading
import time
import typing

from httpx import AsyncClient, Client
from typing import Any, Generator, AsyncGenerator, Tuple
from random import randint

from .base import Base
Expand Down Expand Up @@ -90,7 +90,7 @@ async def download_by_name(self, bucket_name: str, file_name: str,

@authorize_required
async def create_key(self, settings: KeySettings
) -> typing.Tuple[KeyModel, AwaitingKey]:
) -> Tuple[KeyModel, AwaitingKey]:
"""Used to create a key.
Parameters
Expand All @@ -115,7 +115,7 @@ async def create_key(self, settings: KeySettings
@authorize_required
async def keys(self, limit: int = 100,
start_key_id: str = None
) -> typing.AsyncGenerator[typing.Any, None]:
) -> AsyncGenerator[Any, None]:
"""Used to list keys.
Parameters
Expand All @@ -140,8 +140,11 @@ async def keys(self, limit: int = 100,
)

for key in data["keys"]:
yield KeyModel(key), self.key(key["applicationKeyId"]), \
yield (
KeyModel(key),
self.key(key["applicationKeyId"]),
data["nextApplicationKeyId"]
)

def key(self, key_id: str) -> AwaitingKey:
"""Used to interact with key.
Expand All @@ -160,7 +163,7 @@ def key(self, key_id: str) -> AwaitingKey:

@authorize_required
async def create_bucket(self, settings: BucketSettings
) -> typing.Tuple[BucketModel, AwaitingBucket]:
) -> Tuple[BucketModel, AwaitingBucket]:
"""Used to create a bucket.
Parameters
Expand All @@ -185,7 +188,7 @@ async def create_bucket(self, settings: BucketSettings

@authorize_required
async def buckets(self, types: list = ["all"]
) -> typing.AsyncGenerator[BucketModel, AwaitingBucket]:
) -> AsyncGenerator[BucketModel, AwaitingBucket]:
"""Lists buckets.
Parameters
Expand Down Expand Up @@ -324,7 +327,7 @@ def download_by_name(self, bucket_name: str, file_name: str,

@authorize_required
def create_key(self, settings: KeySettings
) -> typing.Tuple[KeyModel, BlockingKey]:
) -> Tuple[KeyModel, BlockingKey]:
"""Used to create a key.
Parameters
Expand All @@ -349,7 +352,7 @@ def create_key(self, settings: KeySettings
@authorize_required
def keys(self, limit: int = 100,
start_key_id: str = None
) -> typing.Generator[KeyModel, AwaitingKey, None]:
) -> Generator[KeyModel, AwaitingKey, None]:
"""Used to list keys.
Parameters
Expand Down Expand Up @@ -391,7 +394,7 @@ def key(self, key_id: str) -> BlockingKey:

@authorize_required
def create_bucket(self, settings: BucketSettings
) -> typing.Tuple[BucketModel, BlockingBucket]:
) -> Tuple[BucketModel, BlockingBucket]:
"""Used to create a bucket.
Parameters
Expand All @@ -416,7 +419,7 @@ def create_bucket(self, settings: BucketSettings

@authorize_required
def buckets(self, types: list = ["all"]
) -> typing.Generator[BucketModel, BlockingBucket, None]:
) -> Generator[BucketModel, BlockingBucket, None]:
"""Lists buckets.
Parameters
Expand Down
5 changes: 3 additions & 2 deletions backblaze/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .cache import Cache


__version__ = "0.0.7"
__version__ = "0.0.8"
__url__ = "https://backblaze.readthedocs.io/en/latest/"
__description__ = "Wrapper for Backblaze's B2."
__author__ = "WardPearce"
Expand Down Expand Up @@ -79,10 +79,11 @@ def __init__(self, key_id: str, key: str, timeout: int = 30,
max_connections=None,
max_keepalive_connections=None
)
self._user_agent = \
self._user_agent = (
"backblaze/{0}+python/{1.major}.{1.minor}.{1.micro}".format(
__version__, version_info
)
)
self.chunk_size = chunk_size

self._routes = Routes()
Expand Down
25 changes: 16 additions & 9 deletions backblaze/bucket/awaiting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typing
import os
import aiofiles

from hashlib import sha1
from typing import Any, AsyncGenerator, Tuple

from ..base import BaseBucket

Expand Down Expand Up @@ -46,7 +46,7 @@ async def update(self, settings: BucketUpdateSettings) -> BucketModel:

@authorize_required
async def create_part(self, settings: PartSettings
) -> typing.Tuple[FileModel, AwaitingFile]:
) -> Tuple[FileModel, AwaitingFile]:
"""Used to create a part.
Parameters
Expand All @@ -69,7 +69,7 @@ async def create_part(self, settings: PartSettings

@authorize_required
async def file_versions(self, settings: FileSettings = None
) -> typing.AsyncGenerator[typing.Any, None]:
) -> AsyncGenerator[Any, None]:
"""Used to list file by version.
Parameters
Expand Down Expand Up @@ -105,12 +105,16 @@ async def file_versions(self, settings: FileSettings = None
)

for file in data["files"]:
yield FileModel(file), self.file(file["fileId"]), \
file["nextFileName"], file["nextFileId"]
yield (
FileModel(file),
self.file(file["fileId"]),
file["nextFileName"],
file["nextFileId"]
)

@authorize_required
async def file_names(self, settings: FileSettings = None
) -> typing.AsyncGenerator[typing.Any, None]:
) -> AsyncGenerator[Any, None]:
"""Used to list file by name.
Parameters
Expand Down Expand Up @@ -144,12 +148,15 @@ async def file_names(self, settings: FileSettings = None
)

for file in data["files"]:
yield FileModel(file), self.file(file["fileId"]), \
yield (
FileModel(file),
self.file(file["fileId"]),
file["nextFileName"]
)

async def upload_file(self, settings: UploadSettings, pathway: str,
allow_parts: bool = True
) -> typing.Tuple[FileModel, AwaitingFile]:
) -> Tuple[FileModel, AwaitingFile]:
"""Used to upload a file to the bucket.
Parameters
Expand Down Expand Up @@ -191,7 +198,7 @@ async def upload_file(self, settings: UploadSettings, pathway: str,

@authorize_required
async def upload(self, settings: UploadSettings, data: bytes
) -> typing.Tuple[FileModel, AwaitingFile]:
) -> Tuple[FileModel, AwaitingFile]:
"""Used to upload a file to b2.
Parameters
Expand Down
17 changes: 11 additions & 6 deletions backblaze/bucket/awaiting/file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing
import aiofiles

from typing import Any, AsyncGenerator

from ..base import BaseFile

from .part import AwaitingParts
Expand Down Expand Up @@ -40,7 +41,7 @@ def parts(self, part_number: int = 0) -> AwaitingParts:
)

@authorize_required
async def copy(self, settings: CopyFileSettings) -> typing.Any:
async def copy(self, settings: CopyFileSettings) -> Any:
"""Used copy a file.
Parameters
Expand Down Expand Up @@ -101,20 +102,24 @@ async def get(self) -> FileModel:
)

@authorize_required
async def delete(self, name: str) -> FileDeleteModel:
async def delete(self, name: str = None) -> FileDeleteModel:
"""Deletes give file.
Parameters
----------
name : str
Name of file.
name : str, optional
Name of file, if not given calls self.get,
by default None.
Returns
-------
FileDeleteModel
Holds details on delete file.
"""

if not name:
name = (await self.get()).file_name

return FileDeleteModel(
await self.context._post(
url=self.context._routes.file.delete,
Expand Down Expand Up @@ -183,7 +188,7 @@ async def download(self, settings: DownloadSettings = None) -> bytes:

@authorize_required
async def download_iterate(self, settings: DownloadSettings = None
) -> typing.AsyncGenerator[bytes, None]:
) -> AsyncGenerator[bytes, None]:
"""Used to iterate over the download.
Parameters
Expand Down

0 comments on commit dd02157

Please sign in to comment.