dynamodb-local 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: dynamodb-local
3
+ Version: 1.0.0
4
+ Summary: DynamoDB local downloader
5
+ Author-email: Tim Heiko <175552092+timheiko@users.noreply.github.com>
6
+ License: Apache-2.0 AND MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/x-rst
9
+
10
+ =========================
11
+ DynamoDB local downloader
12
+ =========================
13
+
14
+ Getting Started
15
+ ---------------
16
+
17
+ 1. Install the library
18
+
19
+ .. code-block:: bash
20
+
21
+ % python3 -m pip install dynamodb_local
22
+
23
+ 2. Usage
24
+
25
+ Non-async
26
+
27
+ .. code-block:: python
28
+
29
+ from dynamodb_local import download_dynamodb
30
+ ...
31
+ dynamodb_local_jar_path = download_dynamodb()
32
+
33
+ Async
34
+
35
+ .. code-block:: python
36
+
37
+ from dynamodb_local import download_dynamodb_async
38
+ ...
39
+ dynamodb_local_jar_path = await download_dynamodb_async()
40
+
41
+ Features
42
+ --------
43
+ * Downloads `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ archive and unpacks it to a given parent directory.
44
+ * Prevents redundant downloading of `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ on every run by verifying the downloaded local version against its `sha256 digest <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz.sha256>`_.
45
+ * No external dependencies.
46
+
47
+ Notes
48
+ -----
49
+ * This library does not Starting the `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ it downloaded and unpacked.
50
+ * Starting the actual DynamoDB lolal process requieres a JRE or JDK.
51
+
52
+
53
+ Credits
54
+ -------
55
+ * `DynamoDBLocal Deploying DynamoDB locally on your computer <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html#DynamoDBLocal.DownloadingAndRunning.title>`_.
@@ -0,0 +1,46 @@
1
+ =========================
2
+ DynamoDB local downloader
3
+ =========================
4
+
5
+ Getting Started
6
+ ---------------
7
+
8
+ 1. Install the library
9
+
10
+ .. code-block:: bash
11
+
12
+ % python3 -m pip install dynamodb_local
13
+
14
+ 2. Usage
15
+
16
+ Non-async
17
+
18
+ .. code-block:: python
19
+
20
+ from dynamodb_local import download_dynamodb
21
+ ...
22
+ dynamodb_local_jar_path = download_dynamodb()
23
+
24
+ Async
25
+
26
+ .. code-block:: python
27
+
28
+ from dynamodb_local import download_dynamodb_async
29
+ ...
30
+ dynamodb_local_jar_path = await download_dynamodb_async()
31
+
32
+ Features
33
+ --------
34
+ * Downloads `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ archive and unpacks it to a given parent directory.
35
+ * Prevents redundant downloading of `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ on every run by verifying the downloaded local version against its `sha256 digest <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz.sha256>`_.
36
+ * No external dependencies.
37
+
38
+ Notes
39
+ -----
40
+ * This library does not Starting the `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ it downloaded and unpacked.
41
+ * Starting the actual DynamoDB lolal process requieres a JRE or JDK.
42
+
43
+
44
+ Credits
45
+ -------
46
+ * `DynamoDBLocal Deploying DynamoDB locally on your computer <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html#DynamoDBLocal.DownloadingAndRunning.title>`_.
@@ -0,0 +1,15 @@
1
+ [project]
2
+ description = "DynamoDB local downloader"
3
+ name = "dynamodb-local"
4
+ license = {text = "Apache-2.0 AND MIT"}
5
+ authors = [
6
+ {name = "Tim Heiko", email = "175552092+timheiko@users.noreply.github.com"},
7
+ ]
8
+ requires-python = ">= 3.10"
9
+ readme = "README.rst"
10
+ dynamic = [
11
+ "version",
12
+ ]
13
+
14
+ [tool.setuptools.dynamic]
15
+ version = {attr = "dynamodb_local.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import asyncio
4
+ from urllib import request
5
+ import shutil
6
+ from pathlib import Path
7
+ from os import makedirs, path
8
+ from hashlib import sha256
9
+
10
+ from logging import getLogger
11
+
12
+ __version__ = "1.0.0"
13
+
14
+ # https://pypi.org/project/pytest-dynamodb/
15
+ DYNAMODB_LOCAL_DIR = Path("tmp/dynamodb")
16
+
17
+ logger = getLogger(__name__)
18
+
19
+
20
+ def download_dynamodb(parent_dir: Path = DYNAMODB_LOCAL_DIR) -> None:
21
+ tar_gz_url = (
22
+ "https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz"
23
+ )
24
+ sha256_url = (
25
+ "https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz.sha256"
26
+ )
27
+ tar_gz_filepath = parent_dir / "dynamodb.tar.gz"
28
+ sha256_filepath = parent_dir / "dynamodb_local_latest.tar.gz.sha256"
29
+ jar_file_name = "DynamoDBLocal.jar"
30
+
31
+ if not check_sha26(
32
+ tar_gz_filepath=tar_gz_filepath, sha256_filepath=sha256_filepath
33
+ ):
34
+ if path.exists(parent_dir):
35
+ logger.debug(f"Cleaning up {parent_dir}")
36
+ shutil.rmtree(parent_dir)
37
+
38
+ logger.debug(f"Creating {parent_dir}")
39
+ makedirs(parent_dir)
40
+
41
+ logger.debug(f"Downloading DynamodDB to {parent_dir}")
42
+ request.urlretrieve(tar_gz_url, tar_gz_filepath)
43
+ shutil.unpack_archive(tar_gz_filepath, parent_dir)
44
+ request.urlretrieve(sha256_url, sha256_filepath)
45
+
46
+ return parent_dir / jar_file_name
47
+
48
+
49
+ def check_sha26(tar_gz_filepath: Path, sha256_filepath: Path) -> bool:
50
+ if path.exists(tar_gz_filepath) and path.exists(sha256_filepath):
51
+ logger.debug(
52
+ f"Checking SHA256 of DynamoDB local archive: {sha256_filepath} {tar_gz_filepath}"
53
+ )
54
+ sha256_hash = sha256()
55
+ with open(file=tar_gz_filepath, mode="rb") as file:
56
+ for block in iter(lambda: file.read(4_096), b""):
57
+ sha256_hash.update(block)
58
+
59
+ sha256_digest = sha256_hash.hexdigest()
60
+
61
+ with open(file=sha256_filepath, mode="r") as file:
62
+ expected_sha256_digest = file.readline().strip().split()[0]
63
+ return sha256_digest == expected_sha256_digest
64
+
65
+ return False
66
+
67
+
68
+ async def download_dynamodb_async(
69
+ parent_dir: Path = DYNAMODB_LOCAL_DIR,
70
+ event_loop: "asyncio.EventLoop" = None,
71
+ ):
72
+ event_loop = event_loop or asyncio.get_running_loop()
73
+ return await event_loop.run_in_executor(None, download_dynamodb, parent_dir)
74
+
75
+
76
+ if __name__ == "__main__":
77
+ download_dynamodb_local()
@@ -0,0 +1,54 @@
1
+ import pytest
2
+ from dynamodb_local import download_dynamodb, download_dynamodb_async
3
+ from tempfile import TemporaryDirectory, mkdtemp
4
+ from pathlib import Path
5
+ from time import perf_counter
6
+
7
+
8
+ @pytest.fixture
9
+ def temp_directory() -> Path:
10
+ tmpdirectory = TemporaryDirectory(prefix="dynamodb_local_")
11
+
12
+ yield Path(tmpdirectory.name)
13
+
14
+ return tmpdirectory.cleanup()
15
+
16
+
17
+ def test_download_dynamodb_fresh(temp_directory: Path):
18
+ assert (
19
+ download_dynamodb(parent_dir=temp_directory)
20
+ == temp_directory / "DynamoDBLocal.jar"
21
+ )
22
+
23
+
24
+ def test_download_dynamodb_cached(temp_directory: Path):
25
+ download_dynamodb(parent_dir=temp_directory)
26
+
27
+ t0 = perf_counter()
28
+ assert (
29
+ download_dynamodb(parent_dir=temp_directory)
30
+ == temp_directory / "DynamoDBLocal.jar"
31
+ )
32
+ t1 = perf_counter()
33
+ assert t1 - t0 < 1.0
34
+
35
+
36
+ @pytest.mark.asyncio
37
+ async def test_download_dynamodb_async_fresh(temp_directory: Path):
38
+ assert (
39
+ await download_dynamodb_async(parent_dir=temp_directory)
40
+ == temp_directory / "DynamoDBLocal.jar"
41
+ )
42
+
43
+
44
+ @pytest.mark.asyncio
45
+ async def test_download_dynamodb_async_cached(temp_directory: Path):
46
+ await download_dynamodb_async(parent_dir=temp_directory)
47
+
48
+ t0 = perf_counter()
49
+ assert (
50
+ await download_dynamodb_async(parent_dir=temp_directory)
51
+ == temp_directory / "DynamoDBLocal.jar"
52
+ )
53
+ t1 = perf_counter()
54
+ assert t1 - t0 < 1.0
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: dynamodb-local
3
+ Version: 1.0.0
4
+ Summary: DynamoDB local downloader
5
+ Author-email: Tim Heiko <175552092+timheiko@users.noreply.github.com>
6
+ License: Apache-2.0 AND MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/x-rst
9
+
10
+ =========================
11
+ DynamoDB local downloader
12
+ =========================
13
+
14
+ Getting Started
15
+ ---------------
16
+
17
+ 1. Install the library
18
+
19
+ .. code-block:: bash
20
+
21
+ % python3 -m pip install dynamodb_local
22
+
23
+ 2. Usage
24
+
25
+ Non-async
26
+
27
+ .. code-block:: python
28
+
29
+ from dynamodb_local import download_dynamodb
30
+ ...
31
+ dynamodb_local_jar_path = download_dynamodb()
32
+
33
+ Async
34
+
35
+ .. code-block:: python
36
+
37
+ from dynamodb_local import download_dynamodb_async
38
+ ...
39
+ dynamodb_local_jar_path = await download_dynamodb_async()
40
+
41
+ Features
42
+ --------
43
+ * Downloads `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ archive and unpacks it to a given parent directory.
44
+ * Prevents redundant downloading of `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ on every run by verifying the downloaded local version against its `sha256 digest <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz.sha256>`_.
45
+ * No external dependencies.
46
+
47
+ Notes
48
+ -----
49
+ * This library does not Starting the `DynamoDB local <https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz>`_ it downloaded and unpacked.
50
+ * Starting the actual DynamoDB lolal process requieres a JRE or JDK.
51
+
52
+
53
+ Credits
54
+ -------
55
+ * `DynamoDBLocal Deploying DynamoDB locally on your computer <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html#DynamoDBLocal.DownloadingAndRunning.title>`_.
@@ -0,0 +1,9 @@
1
+ README.rst
2
+ pyproject.toml
3
+ src/dynamodb_local/__init__.py
4
+ src/dynamodb_local.egg-info/PKG-INFO
5
+ src/dynamodb_local.egg-info/SOURCES.txt
6
+ src/dynamodb_local.egg-info/dependency_links.txt
7
+ src/dynamodb_local.egg-info/top_level.txt
8
+ src/dynamodb_local/tests/__init__.py
9
+ src/dynamodb_local/tests/test_dynamodb_local.py
@@ -0,0 +1 @@
1
+ dynamodb_local