Skip to content

Commit

Permalink
Remove cryptography from default requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
AliRn76 committed Jan 4, 2024
1 parent 51ae75c commit 871faa2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout source
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PantherDB is a <b>Simple</b>, <b>FileBase</b> and <b>Document Oriented</b> datab
```

- #### Create an encrypted database:
Required `cyptography` install it with `pip install pantherdb[full]`
```python
from cryptography.fernet import Fernet
key = Fernet.generate_key() # Should be static (You should not generate new key on every run)
Expand Down
2 changes: 1 addition & 1 deletion pantherdb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pantherdb.pantherdb import * # noqa: F403

__version__ = '1.3.4'
__version__ = '1.3.5'


__all__ = ('__version__', 'PantherDB', 'PantherCollection', 'PantherDocument', 'PantherDBException')
18 changes: 13 additions & 5 deletions pantherdb/pantherdb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import typing
from pathlib import Path
from typing import ClassVar, Iterator

import orjson as json
from cryptography.fernet import Fernet, InvalidToken


class PantherDBException(Exception):
Expand All @@ -15,7 +15,7 @@ class PantherDB:
_instances: ClassVar[dict] = {}
db_name: str = 'database.pdb'
__secret_key: bytes | None
__fernet: Fernet | None
__fernet: typing.Any # type[cryptography.fernet.Fernet | None]
__return_dict: bool
__content: dict

Expand All @@ -30,7 +30,10 @@ def __new__(cls, *args, **kwargs):
else:
db_name = cls.db_name

db_name = db_name.removesuffix('.pdb')
# Replace with .removesuffix('.pdb') after python3.8 compatible support
if db_name.endswith('.pdb'):
db_name = db_name[:-4]

if db_name not in cls._instances:
cls._instances[db_name] = super().__new__(cls)
return cls._instances[db_name]
Expand All @@ -44,8 +47,13 @@ def __init__(
):
self.__return_dict = return_dict
self.__secret_key = secret_key
self.__fernet = Fernet(self.__secret_key) if self.__secret_key else None
self.__content = {}
if self.__secret_key:
from cryptography.fernet import Fernet

self.__fernet = Fernet(self.__secret_key)
else:
self.__fernet = None

if db_name:
if not db_name.endswith('pdb'):
Expand Down Expand Up @@ -95,7 +103,7 @@ def _refresh(self) -> None:
try:
decrypted_data: bytes = self.__fernet.decrypt(data)
self.__content = json.loads(decrypted_data)
except InvalidToken:
except Exception: # type[cryptography.fernet.InvalidToken]
error = '"secret_key" Is Not Valid'
raise PantherDBException(error)

Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def pantherdb_version() -> str:
with open('README.md') as file:
DESCRIPTION = file.read()

EXTRAS_REQUIRE = {
'full': [
'cryptography~=41.0',
],
}


setup(
name='pantherdb',
version=VERSION,
Expand All @@ -32,9 +39,10 @@ def pantherdb_version() -> str:
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
],
install_requires=[
'orjson~=3.9.5',
'cryptography~=41.0',
],
extras_require=EXTRAS_REQUIRE,
)

0 comments on commit 871faa2

Please sign in to comment.