Skip to content

Commit

Permalink
feat: add include only packages (#23)
Browse files Browse the repository at this point in the history
* feat: add include only packages

* fix: ruff it up

* feat: enable newlines and add tests

* test: better tests

* fix: ruff it up
  • Loading branch information
beckermr authored Aug 31, 2024
1 parent 8db9717 commit d074c61
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ concurrency:
cancel-in-progress: false

jobs:
tests:
name: test code
runs-on: "ubuntu-latest"
if: github.event.pull_request.title != 'relock w/ conda-lock'
steps:
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.11
channels: conda-forge
channel-priority: strict
show-channel-urls: true
miniforge-version: latest

- name: install deps
shell: bash -leo pipefail {0}
run: |
conda install --yes \
click \
ruamel.yaml \
conda \
conda-lock \
pytest
- name: run tests
shell: bash -leo pipefail {0}
run: |
pytest -vvs test_relock.py
tests-lock:
name: test updates
runs-on: "ubuntu-latest"
Expand Down
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ inputs:
required: true
default: 'conda-lock.yml'
ignored-packages:
description: 'comma-separated list of packages whose version changes are ignored when relocking'
description: 'comma- or newline-separated list of packages whose version changes are ignored when relocking'
required: true
default: ''
include-only-packages:
description: >
comma-or newline-separated list of packages to exclusively include when relocking, all others will be ignored,
ignored-packages is applied to this list
required: true
default: ''
relock-all-packages:
Expand Down Expand Up @@ -94,6 +100,7 @@ runs:
--lock-file=${{ inputs.lock-file }} \
--ignored-packages=${{ inputs.ignored-packages }} \
--relock-all-packages=${{ inputs.relock-all-packages }} \
--include-only-packages=${{ inputs.include-only-packages }} \
> ${{ github.action_path }}/summary.txt
{
echo 'summary<<EOF'
Expand Down
23 changes: 21 additions & 2 deletions relock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
yaml.default_flow_style = False


def _split_package_list(package_list):
packages = []
for line in package_list.split("\n"):
for pkg in line.split(","):
_pkg = pkg.strip()
if _pkg:
packages.append(_pkg)
return packages


def _lock_to_ver(lock, platform):
pkg_to_ver = {}
for pkg in lock["package"]:
Expand Down Expand Up @@ -44,11 +54,18 @@ def _reformat_lockfile(lockfile):
@click.option("--lock-file", required=True, type=click.Path())
@click.option("--ignored-packages", required=True, type=str)
@click.option("--relock-all-packages", required=True, type=str)
def main(environment_file, lock_file, ignored_packages, relock_all_packages):
@click.option("--include-only-packages", required=True, type=str)
def main(
environment_file,
lock_file,
ignored_packages,
relock_all_packages,
include_only_packages,
):
relocked = False
with tempfile.TemporaryDirectory() as tmpdir:
try:
ignored_packages = [pkg.strip() for pkg in ignored_packages.split(",")]
ignored_packages = _split_package_list(ignored_packages)
relock_all_packages = relock_all_packages.lower() == "true"

have_existing_lock_file = os.path.exists(lock_file)
Expand Down Expand Up @@ -101,6 +118,8 @@ def main(environment_file, lock_file, ignored_packages, relock_all_packages):
for platform in envyml["platforms"]:
for pkg in new_platform_pkg_to_ver[platform]:
deps_to_relock.add(pkg)
elif include_only_packages:
deps_to_relock = set(_split_package_list(include_only_packages))
else:
deps_to_relock = set()
for _spec in envyml["dependencies"]:
Expand Down
19 changes: 19 additions & 0 deletions test_relock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from relock import _split_package_list

import pytest


@pytest.mark.parametrize(
"input,output",
[
("", []),
("\n,\n\n", []),
(",", []),
("\n", []),
("conda", ["conda"]),
("conda,python", ["conda", "python"]),
("\nconda, python\nblah,blah\n,\n\n", ["conda", "python", "blah", "blah"]),
],
)
def test_split_package_list(input, output):
assert _split_package_list(input) == output

0 comments on commit d074c61

Please sign in to comment.