diff --git a/jupyter_releaser/cli.py b/jupyter_releaser/cli.py index 912529c7..8e1628d7 100644 --- a/jupyter_releaser/cli.py +++ b/jupyter_releaser/cli.py @@ -188,7 +188,7 @@ def main(force): envvar="RH_PYTHON_PACKAGES", default=["."], multiple=True, - help='The list of strings of the form "path_to_package:name_of_package"', + help='A list of strings of the form "path_to_package:name_of_package:dep_0,dep_1,..."', ) ] @@ -313,7 +313,7 @@ def list_envvars(): @add_options(username_options) @add_options(git_url_options) def prep_git(ref, branch, repo, auth, username, git_url): - """Prep git and env variables and bump version""" + """Prep git""" lib.prep_git(ref, branch, repo, auth, username, git_url) @@ -324,12 +324,15 @@ def prep_git(ref, branch, repo, auth, username, git_url): @add_options(python_packages_options) @use_checkout_dir() def bump_version(version_spec, version_cmd, changelog_path, python_packages): - """Prep git and env variables and bump version""" + """Bump version""" prev_dir = os.getcwd() - for python_package in [p.split(":")[0] for p in python_packages]: - os.chdir(python_package) + python_packages = [p.split(":") for p in python_packages] + for i, python_package in enumerate(python_packages): + package_path = python_package[0] + os.chdir(package_path) lib.bump_version(version_spec, version_cmd, changelog_path) os.chdir(prev_dir) + lib.update_dependencies(python_package, python_packages[:i]) @main.command() diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index 187a3997..2217f651 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -24,9 +24,9 @@ def bump_version(version_spec, version_cmd, changelog_path): """Bump the version and verify new version""" - util.bump_version(version_spec, version_cmd=version_cmd, changelog_path=changelog_path) - - version = util.get_version() + version = util.bump_version( + version_spec, version_cmd=version_cmd, changelog_path=changelog_path + ) # A properly parsed version will have a "major" attribute parsed = parse_version(version) @@ -44,6 +44,42 @@ def bump_version(version_spec, version_cmd, changelog_path): return version +def update_dependencies(python_package, python_packages): + dep_names = [] if len(python_package) < 3 else python_package[2].split(",") + python_names = [p[1] for p in python_packages] + prev_dir = os.getcwd() + deps = {} + for dep_name in dep_names: + try: + i = python_names.index(dep_name) + except ValueError: + 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." + ) + dep_path = python_packages[i][0] + os.chdir(dep_path) + deps[dep_name] = util.get_version() + os.chdir(prev_dir) + if util.PYPROJECT.exists(): + os.chdir(python_package[0]) + text = util.PYPROJECT.read_text(encoding="utf-8") + data = toml.loads(text) + dependencies = data.get("project", {}).get("dependencies", []) + _update_dependencies(dependencies, deps) + for dependencies in data.get("project", {}).get("optional-dependencies", {}).values(): + _update_dependencies(dependencies, deps) + util.PYPROJECT.write_text(toml.dumps(data)) + os.chdir(prev_dir) + + +def _update_dependencies(dependencies, deps): + deps_no_pin = [d.split("<")[0].split("=")[0].split(">")[0] for d in dependencies] + for k, v in deps.items(): + if k in deps_no_pin: + i = deps_no_pin.index(k) + dependencies[i] = k + " ==" + v + + def check_links(ignore_glob, ignore_links, cache_file, links_expire): """Check URLs for HTML-containing files.""" cache_dir = osp.expanduser(cache_file).replace(os.sep, "/")