Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support package release dependencies in multi-Python packages #372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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 @@ -329,7 +329,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 @@ -340,12 +340,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].strip() for d in dependencies]
for k, v in deps.items():
if k in deps_no_pin:
i = deps_no_pin.index(k)
dependencies[i] = f"{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