Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifecycle new option #499

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ jobs:
env:
B2_TEST_APPLICATION_KEY: ${{ secrets.B2_TEST_APPLICATION_KEY }}
B2_TEST_APPLICATION_KEY_ID: ${{ secrets.B2_TEST_APPLICATION_KEY_ID }}
NOX_EXTRAS: ${{ matrix.extras }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
extras: [ "" ]
exclude:
- os: "macos-latest"
python-version: "pypy3.10"
Expand All @@ -97,6 +99,9 @@ jobs:
- os: "macos-latest"
python-version: 3.9
include:
- python-version: "3.12"
extras: "full"
os: "ubuntu-latest"
# Workaround for https://github.com/actions/setup-python/issues/696
- os: "macos-13"
python-version: 3.7
Expand Down
6 changes: 4 additions & 2 deletions b2sdk/_internal/raw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .file_lock import BucketRetentionSetting, FileRetentionSetting, LegalHold
from .http_constants import FILE_INFO_HEADER_PREFIX
from .replication.setting import ReplicationConfiguration
from .types import NotRequired, PositiveInt, TypedDict
from .utils import b2_url_encode
from .utils.docs import ensure_b2sdk_doc_urls

Expand Down Expand Up @@ -103,8 +104,9 @@ class LifecycleRule(TypedDict):
.. _B2 Cloud Storage Lifecycle Rules: https://www.backblaze.com/docs/cloud-storage-lifecycle-rules
"""
fileNamePrefix: str
daysFromHidingToDeleting: NotRequired[int | None]
daysFromUploadingToHiding: NotRequired[int | None]
daysFromHidingToDeleting: NotRequired[PositiveInt | None]
daysFromUploadingToHiding: NotRequired[PositiveInt | None]
daysFromStartingToCancelingUnfinishedLargeFiles: NotRequired[PositiveInt | None]


class NameValueDict(TypedDict):
Expand Down
42 changes: 42 additions & 0 deletions b2sdk/_internal/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
######################################################################
#
# File: b2sdk/_internal/types.py
#
# Copyright 2024 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
"""
Types compatibility layer.

We use this module to support pydantic-less installs, as well as native typing module us on newer python versions.
"""
import sys

from annotated_types import Ge

try:
from typing_extensions import Annotated, NotRequired, TypedDict
except ImportError:
from typing import Annotated, NotRequired, TypedDict

__all__ = [ # prevents linter from removing "unused imports" which we want to export
"NotRequired",
"PositiveInt",
"TypedDict",
"pydantic",
]

try:
import pydantic

if getattr(pydantic, "__version__", "") < "2":
raise ImportError

if sys.version_info < (3, 10): # https://github.com/pydantic/pydantic/issues/7873
import eval_type_backport # noqa
except ImportError:
pydantic = None

PositiveInt = Annotated[int, Ge(0)]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `daysFromStartingToCancelingUnfinishedLargeFiles` option to `lifecycle_rules` type annotation.
1 change: 1 addition & 0 deletions changelog.d/+pydantics.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `annotated_types` dependency for type annotations that include basic value validation.
16 changes: 10 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

CI = os.environ.get('CI') is not None
NOX_PYTHONS = os.environ.get('NOX_PYTHONS')
_NOX_EXTRAS = os.environ.get('NOX_EXTRAS')
NOX_EXTRAS = [[]] if _NOX_EXTRAS is None else list(filter(None, [_NOX_EXTRAS.split(',')]))

PYTHON_VERSIONS = [
'pypy3.9',
Expand Down Expand Up @@ -77,7 +79,7 @@ def skip_coverage(python_version: str | None) -> bool:
@nox.session(name='format', python=PYTHON_DEFAULT_VERSION)
def format_(session):
"""Lint the code and apply fixes in-place whenever possible."""
pdm_install(session, 'format')
pdm_install(session, 'lint')
# TODO: incremental mode for yapf
session.run('yapf', '--in-place', '--parallel', '--recursive', *PY_PATHS)
session.run('ruff', 'check', '--fix', *PY_PATHS)
Expand All @@ -95,7 +97,7 @@ def format_(session):
def lint(session):
"""Run linters in readonly mode."""
# We need to install 'doc' group because liccheck needs to inspect it.
pdm_install(session, 'doc', 'lint')
pdm_install(session, 'doc', 'lint', 'full')
session.run('yapf', '--diff', '--parallel', '--recursive', *PY_PATHS)
session.run('ruff', 'check', *PY_PATHS)
# session.run(
Expand All @@ -115,9 +117,10 @@ def lint(session):


@nox.session(python=PYTHON_VERSIONS)
def unit(session):
@nox.parametrize("extras", NOX_EXTRAS)
def unit(session, extras):
"""Run unit tests."""
pdm_install(session, 'test')
pdm_install(session, 'test', *extras)
args = ['--doctest-modules', '-n', 'auto']
if not skip_coverage(session.python):
args += ['--cov=b2sdk', '--cov-branch', '--cov-report=xml']
Expand All @@ -134,9 +137,10 @@ def unit(session):


@nox.session(python=PYTHON_VERSIONS)
def integration(session):
@nox.parametrize("extras", NOX_EXTRAS)
def integration(session, extras):
"""Run integration tests."""
pdm_install(session, 'test')
pdm_install(session, 'test', *extras)
session.run('pytest', '-s', *session.posargs, 'test/integration')


Expand Down
Loading