|
1 | 1 | from setuptools import setup, find_packages
|
| 2 | +from setuptools.command.install import install |
| 3 | +from setuptools.command.develop import develop |
| 4 | +import os |
| 5 | +import urllib.request |
| 6 | +from tqdm import tqdm |
2 | 7 |
|
| 8 | +# Modify the RavenDB version and download URL accordingly |
| 9 | +RAVENDB_VERSION = "6.0.0" |
| 10 | +RAVENDB_DOWNLOAD_URL = f"https://www.nuget.org/api/v2/package/RavenDB.Embedded/{RAVENDB_VERSION}" |
| 11 | +RAVENDB_DOWNLOAD_FOLDER = "downloaded_ravendb" |
| 12 | +RAVENDB_FULL_DOWNLOAD_PATH = os.path.join(RAVENDB_DOWNLOAD_FOLDER, "ravendb-server") |
| 13 | + |
| 14 | + |
| 15 | +# Function to download RavenDB with progress bar |
| 16 | +def download_ravendb_with_progress(): |
| 17 | + os.makedirs(RAVENDB_DOWNLOAD_FOLDER, exist_ok=True) |
| 18 | + |
| 19 | + response = urllib.request.urlopen(RAVENDB_DOWNLOAD_URL) |
| 20 | + total_size = int(response.headers.get("content-length", 0)) |
| 21 | + block_size = 1024 # Adjust the block size as needed |
| 22 | + progress_bar = tqdm(total=total_size, unit="B", unit_scale=True) |
| 23 | + |
| 24 | + with open(RAVENDB_FULL_DOWNLOAD_PATH, "wb") as file, progress_bar: |
| 25 | + while True: |
| 26 | + buffer = response.read(block_size) |
| 27 | + if not buffer: |
| 28 | + break |
| 29 | + |
| 30 | + file.write(buffer) |
| 31 | + progress_bar.update(len(buffer)) |
| 32 | + |
| 33 | + |
| 34 | +# Custom installation command to download RavenDB before installation |
| 35 | +class CustomInstall(install): |
| 36 | + def run(self): |
| 37 | + download_ravendb_with_progress() |
| 38 | + super().run() |
| 39 | + |
| 40 | + |
| 41 | +# Custom develop command to download RavenDB before development |
| 42 | +class CustomDevelop(develop): |
| 43 | + def run(self): |
| 44 | + download_ravendb_with_progress() |
| 45 | + super().run() |
| 46 | + |
| 47 | + |
| 48 | +# Setup configuration |
3 | 49 | setup(
|
4 | 50 | name="ravendb-embedded",
|
5 | 51 | packages=find_packages(),
|
6 | 52 | long_description=open("README.rst").read(),
|
7 |
| - version="6.0.0", |
8 |
| - description="RavenDB Embedded library to run ravendb in embedded way", |
| 53 | + version=RAVENDB_VERSION, |
| 54 | + description="RavenDB Embedded library to run RavenDB in an embedded way", |
9 | 55 | author="RavenDB",
|
10 | 56 |
|
11 | 57 | url="https://github.com/ravendb/ravendb-python-embedded",
|
|
14 | 60 | install_requires=[],
|
15 | 61 | include_package_data=True,
|
16 | 62 | zip_safe=False,
|
| 63 | + package_data={"": ["ravendb-server/*"]}, |
| 64 | + cmdclass={"install": CustomInstall, "develop": CustomDevelop}, |
17 | 65 | )
|
0 commit comments