Skip to content

Commit 6d6a87a

Browse files
authored
fix: Simplify version handling and dependencies (#136)
Simplify Deephaven version handling and improve dependency management - Remove hardcoded `DH_VERSION_DEFAULT` and make Deephaven version optional, defaulting to latest from PyPI - Add `get_latest_version()` helper function to fetch latest package versions from PyPI - Remove `DH_VERSION` environment variable requirement from `setup.py` and make `deephaven-server` dependency version-agnostic - Fix dependency parsing regex in `pkg_dependencies()` to handle complex version specifiers - Update README
1 parent bfbb464 commit 6d6a87a

File tree

3 files changed

+59
-50
lines changed

3 files changed

+59
-50
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ you can use the `--use_venv false` option to [./dhib_env.py](./dhib_env.py).
201201

202202
Install the dependencies needed to run the script into this installer virtual environment:
203203
```bash
204+
pip --upgrade pip
204205
pip install -r requirements_dhib_env.txt
205206
```
206207

@@ -211,17 +212,17 @@ you can use the `--use_venv false` option to [./dhib_env.py](./dhib_env.py).
211212
python ./dhib_env.py --help
212213
```
213214

214-
To install the latest production release version of [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) from PyPi plus the release-specified `ibapi` and `deephaven` versions:
215+
To install the latest production release version of [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) from PyPI. This command will automatically install the latest `deephaven-server` from PyPI and extract the required `ibapi` version from the deephaven-ib package dependencies:
215216
```bash
216217
python ./dhib_env.py release
217218
```
218219

219-
To install the latest development version of [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) from source plus the default `ibapi` and `deephaven` versions:
220+
To install the latest development version of [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) from source. This command will automatically install the latest `deephaven-server` and `ibapi` versions from PyPI:
220221
```bash
221222
python ./dhib_env.py dev
222223
```
223224

224-
To create a venv for developing [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) in PyCharm: (This will not install `deephaven-ib`, but it will install the default `ibapi` and `deephaven` versions.)
225+
To create a venv for developing [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) in PyCharm: (This will not install `deephaven-ib`, but it will install the latest `deephaven-server` and `ibapi` versions from PyPI.)
225226
```bash
226227
python ./dhib_env.py dev --install_dhib false
227228
```

dhib_env.py

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
""" A script to build a virtual environment for Deephaven-IB development or release."""
44

5+
import sys
6+
7+
if sys.version_info < (3, 10):
8+
raise RuntimeError(f"This script requires Python 3.10 or higher. You are using Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
9+
510
import atexit
611
import logging
712
import os
@@ -15,7 +20,6 @@
1520
import requests
1621

1722
IB_VERSION_DEFAULT="10.19.04"
18-
DH_VERSION_DEFAULT="0.36.1"
1923
MIN_PY_VERSION="3.10.0"
2024

2125
########################################################################################################################
@@ -126,6 +130,23 @@ def delete_file():
126130
atexit.register(delete_file)
127131

128132

133+
def get_latest_version(package: str) -> str:
134+
"""Get the latest version of a package from PyPI.
135+
136+
Args:
137+
package: The name of the package.
138+
139+
Returns:
140+
The latest version string.
141+
"""
142+
logging.warning(f"Determining latest version of package: {package}")
143+
response = requests.get(f"https://pypi.org/pypi/{package}/json")
144+
response.raise_for_status()
145+
version = response.json()["info"]["version"]
146+
logging.warning(f"Latest {package} version: {version}")
147+
return version
148+
149+
129150
def download_wheel(python: str, package: str, version: Optional[str], delete_on_exit: bool = True) -> Path:
130151
"""Download a wheel file for a package with a specific version.
131152
@@ -144,10 +165,7 @@ def download_wheel(python: str, package: str, version: Optional[str], delete_on_
144165
logging.warning(f"Downloading wheel for package: {package}, version: {version}, delete_on_exit: {delete_on_exit}")
145166

146167
if not version:
147-
logging.warning(f"Determining latest version of package: {package}")
148-
response = requests.get(f"https://pypi.org/pypi/{package}/json")
149-
response.raise_for_status()
150-
version = response.json()["info"]["version"]
168+
version = get_latest_version(package)
151169

152170
ver = f"=={version}" if version else ""
153171
shell_exec(f"{python} -m pip download {package}{ver} --no-deps")
@@ -180,15 +198,13 @@ def pkg_dependencies(path_or_module: Union[str, Path, ModuleType]) -> Dict[str,
180198
rst = {}
181199

182200
for req in meta.requires_dist:
183-
s = req.split(" ")
184-
name = s[0]
185-
186-
if len(s) > 1:
187-
version = s[1].strip("()")
201+
match = re.match(r'^([a-zA-Z0-9_-]+)(.*)$', req.strip())
202+
if match:
203+
name = match.group(1)
204+
version_spec = match.group(2).strip()
205+
rst[name] = version_spec if version_spec else None
188206
else:
189-
version = None
190-
191-
rst[name] = version
207+
rst[req] = None
192208

193209
return rst
194210

@@ -475,12 +491,12 @@ def ib_wheel(
475491

476492
@click.command()
477493
@click.option('--python', default="python3", help='The path to the Python executable to use.')
478-
@click.option('--dh_version', default=DH_VERSION_DEFAULT, help='The version of Deephaven.')
494+
@click.option('--dh_version', default=None, help='The version of Deephaven. If not specified, uses the latest version from PyPI.')
479495
@click.option('--ib_version', default=IB_VERSION_DEFAULT, help='The version of ibapi.')
480496
@click.option('--dh_ib_version', default=None, help='The version of deephaven-ib.')
481497
def dhib_wheel(
482498
python: str,
483-
dh_version: str,
499+
dh_version: Optional[str],
484500
ib_version: str,
485501
dh_ib_version: Optional[str],
486502
):
@@ -489,9 +505,11 @@ def dhib_wheel(
489505

490506
if dh_ib_version is None:
491507
dh_ib_version = "0.0.0.dev0"
508+
509+
if not dh_version:
510+
dh_version = get_latest_version("deephaven-server")
492511

493512
version_assert_format(ib_version)
494-
version_assert_format(dh_version)
495513
version_assert_format(dh_ib_version)
496514

497515
python = Path(python).absolute() if python.startswith("./") else python
@@ -510,8 +528,7 @@ def dhib_wheel(
510528

511529
@click.command()
512530
@click.option('--python', default="python3", help='The path to the Python executable to use.')
513-
@click.option('--dh_version', default=DH_VERSION_DEFAULT, help='The version of Deephaven.')
514-
@click.option('--dh_version_exact', default=None, help='The exact version of Deephaven.')
531+
@click.option('--dh_version', default=None, help='The version of Deephaven. If not specified, uses the latest version from PyPI.')
515532
@click.option('--ib_version', default=IB_VERSION_DEFAULT, help='The version of ibapi.')
516533
@click.option('--dh_ib_version', default=None, help='The version of deephaven-ib.')
517534
@click.option('--use_venv', default=True, help='Whether to use a python virtual environment or system python.')
@@ -521,8 +538,7 @@ def dhib_wheel(
521538
@click.option('--install_dhib', default=True, help='Whether to install deephaven-ib. If set to false, the resulting venv can be used to develop deephaven-ib in PyCharm or other development environments.')
522539
def dev(
523540
python: str,
524-
dh_version: str,
525-
dh_version_exact: str,
541+
dh_version: Optional[str],
526542
ib_version: str,
527543
dh_ib_version: Optional[str],
528544
use_venv: bool,
@@ -532,26 +548,19 @@ def dev(
532548
install_dhib: bool
533549
):
534550
"""Create a development environment."""
535-
logging.warning(f"Creating development environment: python={python} dh_version={dh_version}, dh_version_exact={dh_version_exact}, ib_version={ib_version}, dh_ib_version={dh_ib_version}, delete_vm_if_exists={delete_venv}")
551+
logging.warning(f"Creating development environment: python={python} dh_version={dh_version}, ib_version={ib_version}, dh_ib_version={dh_ib_version}, delete_vm_if_exists={delete_venv}")
536552

537553
python = Path(python).absolute() if python.startswith("./") else python
538554
assert_python_version(python)
539555

540-
if dh_version_exact:
541-
if dh_version != DH_VERSION_DEFAULT:
542-
raise ValueError(f"Cannot specify both dh_version={dh_version} and dh_version_exact={dh_version_exact}")
543-
544-
dh_version = dh_version_exact
545-
dh_version_pip = f"=={dh_version}"
546-
else:
547-
dh_version_pip = f"~={dh_version}"
556+
if not dh_version:
557+
dh_version = get_latest_version("deephaven-server")
548558

549559
use_dev = dh_ib_version is None
550560

551561
if dh_ib_version is None:
552562
dh_ib_version = "0.0.0.dev0"
553563

554-
version_assert_format(dh_version)
555564
version_assert_format(ib_version)
556565
version_assert_format(dh_ib_version)
557566

@@ -573,7 +582,8 @@ def dev(
573582
ib_wheel.build(pyenv)
574583
ib_wheel.install(pyenv)
575584

576-
pyenv.pip_install("deephaven-server", dh_version_pip)
585+
logging.warning(f"Installing deephaven-server: {dh_version}")
586+
pyenv.pip_install("deephaven-server", f"~={dh_version}")
577587

578588
if install_dhib:
579589
if use_dev:
@@ -591,13 +601,15 @@ def dev(
591601

592602
@click.command()
593603
@click.option('--python', default="python3", help='The path to the Python executable to use.')
604+
@click.option('--dh_version', default=None, help='The version of Deephaven. If not specified, uses the latest version from PyPI.')
594605
@click.option('--dh_ib_version', default=None, help='The version of deephaven-ib.')
595606
@click.option('--use_venv', default=True, help='Whether to use a python virtual environment or system python.')
596607
@click.option('--path_venv', default=None, help='The path to the virtual environment.')
597608
@click.option('--create_venv', default=True, help='Whether to create the virtual environment if it does not already exist.')
598609
@click.option('--delete_venv', default=False, help='Whether to delete the virtual environment if it already exists.')
599610
def release(
600611
python: str,
612+
dh_version: Optional[str],
601613
dh_ib_version: Optional[str],
602614
use_venv: bool,
603615
path_venv: Optional[str],
@@ -610,19 +622,18 @@ def release(
610622
python = Path(python).absolute() if python.startswith("./") else python
611623
assert_python_version(python)
612624

625+
if not dh_ib_version:
626+
dh_ib_version = get_latest_version("deephaven_ib")
627+
613628
wheel = download_wheel(python, "deephaven_ib", dh_ib_version)
614629
deps = pkg_dependencies(wheel)
615630
ib_version = deps["ibapi"].replace("==", "")
616-
dh_version = deps["deephaven-server"].replace("==", "").replace("~=", "").replace(">=", "")
631+
632+
if not dh_version:
633+
dh_version = get_latest_version("deephaven-server")
617634

618-
version_assert_format(dh_version)
619635
version_assert_format(ib_version)
620-
621-
if dh_ib_version:
622-
version_assert_format(dh_ib_version)
623-
dh_ib_version_pip = f"=={dh_ib_version}"
624-
else:
625-
dh_ib_version_pip = ""
636+
version_assert_format(dh_ib_version)
626637

627638
if use_venv:
628639
if path_venv:
@@ -642,8 +653,11 @@ def release(
642653
ib_wheel.build(pyenv)
643654
ib_wheel.install(pyenv)
644655

656+
logging.warning(f"Installing deephaven-server: {dh_version}")
657+
pyenv.pip_install("deephaven-server", f"~={dh_version}")
658+
645659
logging.warning(f"Installing deephaven-ib from PyPI: {dh_ib_version}")
646-
pyenv.pip_install("deephaven-ib", dh_ib_version_pip)
660+
pyenv.pip_install("deephaven-ib", f"=={dh_ib_version}")
647661
success(pyenv)
648662

649663

setup.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
if not dh_ib_version:
1212
raise Exception("deephaven-ib version must be set via the DH_IB_VERSION environment variable.")
1313

14-
dh_version = os.getenv("DH_VERSION")
15-
16-
if not dh_version:
17-
raise Exception("deephaven version must be set via the DH_VERSION environment variable.")
18-
1914
ib_version = os.getenv("IB_VERSION")
2015

2116
if not ib_version:
@@ -59,7 +54,6 @@ def version_assert_format(version: str, allow_zero_prefix: bool=False) -> None:
5954

6055

6156
version_assert_format(dh_ib_version)
62-
version_assert_format(dh_version)
6357
version_assert_format(ib_version, allow_zero_prefix=True)
6458

6559
setuptools.setup(
@@ -91,7 +85,7 @@ def version_assert_format(version: str, allow_zero_prefix: bool=False) -> None:
9185
packages=setuptools.find_packages(where="src"),
9286
python_requires=">=3.10",
9387
install_requires=[
94-
f"deephaven-server>={dh_version}",
88+
"deephaven-server",
9589
"pandas",
9690
f"ibapi=={ib_version}",
9791
"lxml",

0 commit comments

Comments
 (0)