Skip to content

Commit e0493e9

Browse files
committed
RDBC-790 Fixed pip install, adjusted the process startup, fixed bugs
1 parent 036fc59 commit e0493e9

File tree

8 files changed

+68
-55
lines changed

8 files changed

+68
-55
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/test.py
33
/dist
44
/ravendb-embedded.egg-info
5-
/ravendb_embedded/ravendb_server
5+
/ravendb_embedded/target
66
*.pyc
77
*.log
88
*.raven-topology

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include ravendb_embedded/ravendb_server/server.zip
1+
graft ravendb_embedded/target/nuget
22
include README.rst

ravendb_embedded/embedded_server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def start_server(self, options_param: ServerOptions = None) -> None:
6060

6161
start_server = Lazy(lambda: self._run_server(options))
6262

63-
if self.server_task and self.server_task != start_server:
63+
if self.server_task and self.server_task.created and self.server_task != start_server:
6464
raise RuntimeError("The server was already started")
6565

6666
self.server_task = start_server
@@ -106,9 +106,9 @@ def get_document_store_from_options(self, options: DatabaseOptions) -> DocumentS
106106
def _try_create_database(self, options: DatabaseOptions, store: DocumentStore) -> None:
107107
try:
108108
store.maintenance.server.send(CreateDatabaseOperation(options.database_record))
109-
except RuntimeError as e:
109+
except Exception as e:
110110
# Expected behavior when the database already exists
111-
if "Already exists" in e.args[0]: # todo: test
111+
if "conflict" in e.args[0]: # todo: change exc type when python client will implement conflict handling
112112
self._log_debug(f"{options.database_record.database_name} already exists.")
113113
else:
114114
raise e
@@ -289,10 +289,11 @@ def close(self):
289289
self._shutdown_server_process(process)
290290

291291
for key, value in self.document_stores.items():
292-
if value.is_value_created():
292+
if value.created:
293293
value.get_value().close()
294294

295295
self.document_stores.clear()
296+
self.server_task = None
296297

297298

298299
class Lazy(Generic[_T]):

ravendb_embedded/options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DatabaseOptions:
1515
def __init__(self, database_record: DatabaseRecord):
1616
self.database_record = database_record
1717
self.skip_creating_database: Optional[bool] = False
18-
self.conventions: Optional[DocumentConventions] = None
18+
self.conventions: DocumentConventions = DocumentConventions()
1919

2020
@classmethod
2121
def from_database_name(cls, database_name: str) -> DatabaseOptions:
@@ -38,8 +38,8 @@ class ServerOptions:
3838

3939
def __init__(self):
4040
self.framework_version: str = "7.0.15+"
41-
self.logs_path: str = self.BASE_DIRECTORY + "RavenDB/Logs"
42-
self.data_directory: str = self.BASE_DIRECTORY + "RavenDB"
41+
self.logs_path: str = self.BASE_DIRECTORY + "/RavenDB/Logs"
42+
self.data_directory: str = self.BASE_DIRECTORY + "/RavenDB"
4343
self.provider: ProvideRavenDBServer = ExtractFromPkgResourceServerProvider()
4444
self.target_server_location: str = self.DEFAULT_SERVER_LOCATION
4545
self.dot_net_path: str = "dotnet"

ravendb_embedded/provide.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, server_files: str):
1818
self.server_files = server_files
1919

2020
def provide(self, target_directory: str) -> None: # todo: test
21-
shutil.copytree(self.server_files, target_directory)
21+
shutil.copytree(self.server_files, target_directory, dirs_exist_ok=True)
2222

2323

2424
class CopyServerFromNugetProvider(CopyServerProvider):
@@ -31,7 +31,7 @@ def provide(self, target_directory: str) -> None:
3131
if not os.path.exists("target"):
3232
raise RuntimeError(
3333
f"Unable to find 'target' directory in the current working directory ({os.path.abspath('.')}). "
34-
f"Please make sure you execute the test in the root project directory with the pom.xml file."
34+
f"Please make sure you execute the test in the ravendb_embedded directory with the provide.py file."
3535
)
3636

3737
super().provide(target_directory)

ravendb_embedded/raven_server_runner.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,16 @@ def run(options: ServerOptions) -> subprocess.Popen:
8989
else:
9090
options.server_url = options.server_url or "http://127.0.0.1:0"
9191

92-
command_line_args.extend(
93-
[f"--ServerUrl={options.server_url}", CommandLineArgumentEscaper.escape_single_arg(server_dll_path)]
94-
)
95-
96-
if options.framework_version:
97-
framework_version = RuntimeFrameworkVersionMatcher.match(options)
98-
command_line_args[:0] = ["--fx-version", framework_version]
92+
command_line_args.extend([f"--ServerUrl={options.server_url}"])
9993

10094
command_line_args[:0] = options.command_line_args
95+
command_line_args.insert(0, server_dll_path)
96+
command_line_args.insert(0, options.dot_net_path)
10197

102-
command_line_args[:0] = [options.dot_net_path]
98+
if options.framework_version:
99+
framework_version = RuntimeFrameworkVersionMatcher.match(options)
100+
command_line_args.insert(1, framework_version)
101+
command_line_args.insert(1, "--fx-version")
103102

104103
process_builder = subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
105104
process = process_builder

ravendb_embedded/runtime_framework_version_matcher.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,42 +55,37 @@ def get_framework_versions(options: ServerOptions):
5555
raise RuntimeError("Dotnet path is not provided.")
5656

5757
process_command = [options.dot_net_path, "--info"]
58-
process = None
58+
runtimes = []
5959

6060
try:
61-
process = subprocess.Popen(process_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
62-
63-
inside_runtimes = False
64-
runtime_lines = []
65-
66-
for line in process.stdout:
67-
line = line.strip()
68-
69-
if line.startswith(".NET runtimes installed:") or line.startswith(".NET Core runtimes installed:"):
70-
inside_runtimes = True
71-
continue
72-
73-
if inside_runtimes and line.startswith("Microsoft.NETCore.App"):
74-
runtime_lines.append(line)
75-
76-
runtimes = []
77-
for runtime_line in runtime_lines:
78-
values = runtime_line.split(" ")
79-
if len(values) < 2:
80-
raise RuntimeError(
81-
f"Invalid runtime line. Expected 'Microsoft.NETCore.App x.x.x', but was '{runtime_line}'"
82-
)
83-
84-
runtimes.append(RuntimeFrameworkVersion(values[1]))
85-
86-
return runtimes
61+
with subprocess.Popen(
62+
process_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
63+
) as process:
64+
inside_runtimes = False
65+
runtime_lines = []
66+
67+
for line in process.stdout:
68+
line = line.strip()
69+
if line.startswith(".NET runtimes installed:") or line.startswith(".NET Core runtimes installed:"):
70+
inside_runtimes = True
71+
continue
72+
if inside_runtimes and line.startswith("Microsoft.NETCore.App"):
73+
runtime_lines.append(line)
74+
75+
for runtime_line in runtime_lines:
76+
values = runtime_line.split(" ")
77+
if len(values) < 2:
78+
raise RuntimeError(
79+
f"Invalid runtime line. Expected 'Microsoft.NETCore.App x.x.x', but was '{runtime_line}'"
80+
)
81+
runtimes.append(RuntimeFrameworkVersion(values[1]))
8782

8883
except Exception as e:
8984
raise RuntimeError("Unable to execute dotnet to retrieve list of installed runtimes") from e
90-
9185
finally:
9286
if process:
9387
process.kill()
88+
return runtimes
9489

9590

9691
class RuntimeFrameworkVersion:

setup.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
from setuptools import setup, find_packages, find_namespace_packages
1+
import zipfile
2+
3+
from setuptools import setup
24
from setuptools.command.install import install
35
from setuptools.command.develop import develop
46
import os
57
import urllib.request
8+
9+
from setuptools.command.sdist import sdist
610
from tqdm import tqdm
711

812
# Modify the RavenDB version and download URL accordingly
9-
RAVENDB_VERSION = "6.0.0"
13+
RAVENDB_VERSION = "6.0.2"
1014
RAVENDB_DOWNLOAD_URL = f"https://www.nuget.org/api/v2/package/RavenDB.Embedded/{RAVENDB_VERSION}"
11-
RAVENDB_DOWNLOAD_FOLDER = "ravendb_embedded/ravendb_server"
15+
RAVENDB_DOWNLOAD_FOLDER = "ravendb_embedded/target/nuget"
1216
RAVENDB_FULL_DOWNLOAD_PATH = os.path.join(RAVENDB_DOWNLOAD_FOLDER, "server.zip")
1317

1418

@@ -17,11 +21,11 @@ def download_ravendb_with_progress():
1721
os.makedirs(RAVENDB_DOWNLOAD_FOLDER, exist_ok=True)
1822

1923
response = urllib.request.urlopen(RAVENDB_DOWNLOAD_URL)
20-
total_size = int(response.headers.get('content-length', 0))
24+
total_size = int(response.headers.get("content-length", 0))
2125
block_size = 1024 # Adjust the block size as needed
22-
progress_bar = tqdm(total=total_size, unit='B', unit_scale=True)
26+
progress_bar = tqdm(total=total_size, unit="B", unit_scale=True)
2327

24-
with open(RAVENDB_FULL_DOWNLOAD_PATH, 'wb') as file, progress_bar:
28+
with open(RAVENDB_FULL_DOWNLOAD_PATH, "wb") as file, progress_bar:
2529
while True:
2630
buffer = response.read(block_size)
2731
if not buffer:
@@ -30,6 +34,13 @@ def download_ravendb_with_progress():
3034
file.write(buffer)
3135
progress_bar.update(len(buffer))
3236

37+
# Unzip the downloaded file
38+
with zipfile.ZipFile(RAVENDB_FULL_DOWNLOAD_PATH, "r") as zip_ref:
39+
zip_ref.extractall(RAVENDB_DOWNLOAD_FOLDER)
40+
41+
# Remove the server.zip file
42+
os.remove(RAVENDB_FULL_DOWNLOAD_PATH)
43+
3344

3445
# Custom installation command to download RavenDB before installation
3546
class CustomInstall(install):
@@ -45,13 +56,20 @@ def run(self):
4556
super().run()
4657

4758

59+
# Custom source distribution command to ensure server.zip is included
60+
class CustomSDist(sdist):
61+
def run(self):
62+
download_ravendb_with_progress()
63+
super().run()
64+
65+
4866
# Setup configuration
4967
setup(
50-
cmdclass={"install": CustomInstall, "develop": CustomDevelop},
68+
cmdclass={"install": CustomInstall, "develop": CustomDevelop, "sdist": CustomSDist},
5169
name="ravendb-embedded",
5270
packages=["ravendb-embedded"],
5371
package_dir={"ravendb-embedded": "ravendb_embedded"},
54-
package_data={"ravendb-embedded.data" : ["ravendb_embedded/server.zip"]},
72+
package_data={"ravendb-embedded.data": ["ravendb_embedded/target/nuget/*"]},
5573
include_package_data=True,
5674
long_description=open("README.rst").read(),
5775
version=RAVENDB_VERSION,

0 commit comments

Comments
 (0)