Skip to content

Commit 89499ad

Browse files
committed
Support package release dependencies in multi-Python packages
1 parent 693d096 commit 89499ad

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

jupyter_releaser/cli.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def main(force):
188188
envvar="RH_PYTHON_PACKAGES",
189189
default=["."],
190190
multiple=True,
191-
help='The list of strings of the form "path_to_package:name_of_package"',
191+
help='A list of strings of the form "path_to_package:name_of_package:dep_0,dep_1,..."',
192192
)
193193
]
194194

@@ -313,7 +313,7 @@ def list_envvars():
313313
@add_options(username_options)
314314
@add_options(git_url_options)
315315
def prep_git(ref, branch, repo, auth, username, git_url):
316-
"""Prep git and env variables and bump version"""
316+
"""Prep git"""
317317
lib.prep_git(ref, branch, repo, auth, username, git_url)
318318

319319

@@ -324,12 +324,15 @@ def prep_git(ref, branch, repo, auth, username, git_url):
324324
@add_options(python_packages_options)
325325
@use_checkout_dir()
326326
def bump_version(version_spec, version_cmd, changelog_path, python_packages):
327-
"""Prep git and env variables and bump version"""
327+
"""Bump version"""
328328
prev_dir = os.getcwd()
329-
for python_package in [p.split(":")[0] for p in python_packages]:
330-
os.chdir(python_package)
329+
python_packages = [p.split(":") for p in python_packages]
330+
for i, python_package in enumerate(python_packages):
331+
package_path = python_package[0]
332+
os.chdir(package_path)
331333
lib.bump_version(version_spec, version_cmd, changelog_path)
332334
os.chdir(prev_dir)
335+
lib.update_dependencies(python_package, python_packages[:i])
333336

334337

335338
@main.command()

jupyter_releaser/lib.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
def bump_version(version_spec, version_cmd, changelog_path):
2626
"""Bump the version and verify new version"""
27-
util.bump_version(version_spec, version_cmd=version_cmd, changelog_path=changelog_path)
28-
29-
version = util.get_version()
27+
version = util.bump_version(
28+
version_spec, version_cmd=version_cmd, changelog_path=changelog_path
29+
)
3030

3131
# A properly parsed version will have a "major" attribute
3232
parsed = parse_version(version)
@@ -44,6 +44,42 @@ def bump_version(version_spec, version_cmd, changelog_path):
4444
return version
4545

4646

47+
def update_dependencies(python_package, python_packages):
48+
dep_names = [] if len(python_package) < 3 else python_package[2].split(",")
49+
python_names = [p[1] for p in python_packages]
50+
prev_dir = os.getcwd()
51+
deps = {}
52+
for dep_name in dep_names:
53+
try:
54+
i = python_names.index(dep_name)
55+
except ValueError:
56+
raise RuntimeError(
57+
f"Package {python_package[1]} depends on {dep_name}, which has not been released yet. Please put the dependency before this package in the python_packages list."
58+
)
59+
dep_path = python_packages[i][0]
60+
os.chdir(dep_path)
61+
deps[dep_name] = util.get_version()
62+
os.chdir(prev_dir)
63+
if util.PYPROJECT.exists():
64+
os.chdir(python_package[0])
65+
text = util.PYPROJECT.read_text(encoding="utf-8")
66+
data = toml.loads(text)
67+
dependencies = data.get("project", {}).get("dependencies", [])
68+
_update_dependencies(dependencies, deps)
69+
for dependencies in data.get("project", {}).get("optional-dependencies", {}).values():
70+
_update_dependencies(dependencies, deps)
71+
util.PYPROJECT.write_text(toml.dumps(data))
72+
os.chdir(prev_dir)
73+
74+
75+
def _update_dependencies(dependencies, deps):
76+
deps_no_pin = [d.split("<")[0].split("=")[0].split(">")[0] for d in dependencies]
77+
for k, v in deps.items():
78+
if k in deps_no_pin:
79+
i = deps_no_pin.index(k)
80+
dependencies[i] = k + " ==" + v
81+
82+
4783
def check_links(ignore_glob, ignore_links, cache_file, links_expire):
4884
"""Check URLs for HTML-containing files."""
4985
cache_dir = osp.expanduser(cache_file).replace(os.sep, "/")

0 commit comments

Comments
 (0)