Skip to content

Commit

Permalink
Support package release dependencies in multi-Python packages
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 12, 2022
1 parent 2cd3e74 commit 2651a46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
13 changes: 8 additions & 5 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,..."',
)
]

Expand Down Expand Up @@ -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)


Expand All @@ -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()
Expand Down
42 changes: 39 additions & 3 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, "/")
Expand Down

0 comments on commit 2651a46

Please sign in to comment.