Skip to content

Commit e8498df

Browse files
committed
Support package release dependencies in multi-Python packages
1 parent 2cd3e74 commit e8498df

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-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: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
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(version_spec, version_cmd=version_cmd, changelog_path=changelog_path)
3028

3129
# A properly parsed version will have a "major" attribute
3230
parsed = parse_version(version)
@@ -44,6 +42,40 @@ def bump_version(version_spec, version_cmd, changelog_path):
4442
return version
4543

4644

45+
def update_dependencies(python_package, python_packages):
46+
dep_names = [] if len(python_package) < 3 else python_package[2].split(",")
47+
python_names = [p[1] for p in python_packages]
48+
prev_dir = os.getcwd()
49+
deps = {}
50+
for dep_name in dep_names:
51+
try:
52+
i = python_names.index(dep_name)
53+
except ValueError:
54+
raise RuntimeError(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.")
55+
dep_path = python_packages[i][0]
56+
os.chdir(dep_path)
57+
deps[dep_name] = util.get_version()
58+
os.chdir(prev_dir)
59+
os.chdir(python_package[0])
60+
text = util.PYPROJECT.read_text(encoding="utf-8")
61+
data = toml.loads(text)
62+
dependencies = data.get("project", {}).get("dependencies", [])
63+
_update_dependencies(dependencies, deps)
64+
for dependencies in data.get("project", {}).get("optional-dependencies", {}).values():
65+
_update_dependencies(dependencies, deps)
66+
util.PYPROJECT.write_text(toml.dumps(data))
67+
os.chdir(prev_dir)
68+
69+
70+
def _update_dependencies(dependencies, deps):
71+
deps_no_pin = [d.split("<")[0].split("=")[0].split(">")[0] for d in dependencies]
72+
for k, v in deps.items():
73+
if k in deps_no_pin:
74+
i = deps_no_pin.index(k)
75+
dependencies[i] = k + " ==" + v
76+
77+
78+
4779
def check_links(ignore_glob, ignore_links, cache_file, links_expire):
4880
"""Check URLs for HTML-containing files."""
4981
cache_dir = osp.expanduser(cache_file).replace(os.sep, "/")

0 commit comments

Comments
 (0)