Skip to content

Commit

Permalink
168 [Remaining portion]: Change the references of the old version to …
Browse files Browse the repository at this point in the history
…the new version (#248)

* Adds check to bump-recipe that ensures version is provided when needed

* Fixes/updates some of the bump-recipe unit tests

* Fixes remaining bump-recipe unit tests from version option fall-out

* Moves test_bump_recipe.py to use read-only parser when editing commands are not used in assert statements

* test_bump_recipe.py now uses more consistent names across tests.

* Starts work on version update capability

* Temp workaround for linting error

* Starts work on _updates_version()

* Finishes first-pass of update version logic, re-enable unit test

* Cleans-up TODOs and logic in _update_version()
  • Loading branch information
schuylermartin45 authored Nov 20, 2024
1 parent b1b9a78 commit 9ee0939
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
21 changes: 18 additions & 3 deletions conda_recipe_manager/commands/bump_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import sys
from pathlib import Path
from typing import Optional, cast
from typing import Final, Optional, cast

import click

Expand Down Expand Up @@ -68,14 +68,29 @@ def _update_build_num(recipe_parser: RecipeParser, increment_build_num: bool) ->
_exit_on_failed_patch(recipe_parser, cast(JsonPatchType, {"op": "add", "path": "/build/number", "value": 0}))


def _update_version(recipe_parser: RecipeParser, target_version: str) -> None: # pylint: disable=unused-argument
def _update_version(recipe_parser: RecipeParser, target_version: str) -> None:
"""
Attempts to update the `/package/version` field and/or the commonly used `version` JINJA variable.
:param recipe_parser: Recipe file to update.
:param target_version: Target version to update to.
"""
# TODO branch on `/package/version` being specified without a `version` variable
# TODO Add V0 multi-output version support for some recipes (version field is duplicated in cctools-ld64 but not in
# most multi-output recipes)

# If the `version` variable is found, patch that. This is an artifact/pattern from Grayskull.
old_variable = recipe_parser.get_variable("version", None)
if old_variable is not None:
recipe_parser.set_variable("version", target_version)
# Generate a warning if `version` is not being used in the `/package/version` field. NOTE: This is a linear
# search on a small list.
if "/package/version" not in recipe_parser.get_variable_references("version"):
# TODO log a warning
pass
return

op: Final[str] = "replace" if recipe_parser.contains_value("/package/version") else "add"
_exit_on_failed_patch(recipe_parser, {"op": op, "path": "/package/version", "value": target_version})


def _update_sha256(recipe_parser: RecipeParser) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/test_bump_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def test_usage() -> None:
@pytest.mark.parametrize(
"recipe_file,version,expected_recipe_file",
[
# NOTE: The SHA-256 hashes will be of the mocked archive files, not of the actual source code being referenced.
("types-toml.yaml", None, "bump_recipe/types-toml_build_num_1.yaml"),
# TODO: Re-enable test when version bumping is supported.
# ("types-toml.yaml", "0.10.8.20240310", "bump_recipe/types-toml_version_bump.yaml"),
("types-toml.yaml", "0.10.8.20240310", "bump_recipe/types-toml_version_bump.yaml"),
# NOTE: These have no source section, therefore all SHA-256 update attempts (and associated network requests)
# should be skipped.
("bump_recipe/build_num_1.yaml", None, "bump_recipe/build_num_2.yaml"),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_aux_files/bump_recipe/types-toml_version_bump.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% set name = "types-toml" %}
{% set version = "0.10.8.6" %}
{% set version = "0.10.8.20240310" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/types-toml-{{ version }}.tar.gz
sha256: 6d3ac79e36c9ee593c5d4fb33a50cca0e3adceb6ef5cff8b8e5aef67b4c4aaf2
sha256: e594f5bc141acabe4b0298d05234e80195116667edad3d6a9cd610cab36bc4e1

build:
number: 0
Expand Down

0 comments on commit 9ee0939

Please sign in to comment.