Skip to content

Commit

Permalink
Merge pull request #97 from anaconda-distribution/v0.1.5
Browse files Browse the repository at this point in the history
v0.1.5, adds new function
  • Loading branch information
schuylermartin45 authored Dec 19, 2023
2 parents 5f33626 + b691135 commit 2502a06
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
Note: version releases in the 0.x.y range may introduce breaking changes.

## 0.1.5
- Adds `get_read_only_parser()` function.
- Fixes some comments.

## 0.1.4
- Adds 4 new functions to the `percy` parser
- 2 of these make it easier to work with dependencies
Expand Down
5 changes: 2 additions & 3 deletions percy/parser/recipe_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,8 @@ def _scan_requirements(path_prefix: str = "") -> None:
for i in range(len(dependencies)):
paths.append(f"{section_path}/{i}")

# Scan for both multi-output and non-multi-output recipes. We won't scan empty defaulted lists, making scanning
# for both about as computationally complex as running `is_multi_output()` while also covering a theoretical
# recipe format that has both sections, even if it shouldn't exist.
# Scan for both multi-output and non-multi-output recipes. Here is an example of a recipe that has both:
# https://github.com/AnacondaRecipes/curl-feedstock/blob/master/recipe/meta.yaml
outputs = cast(list[JsonType], self.get_value("/outputs", []))
for i in range(len(outputs)):
_scan_requirements(f"/outputs/{i}")
Expand Down
35 changes: 25 additions & 10 deletions percy/render/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,14 @@ def contains(self, path: str, value: str, default: Any = KeyError) -> bool:

def patch_with_parser(self, callback: Callable[[RecipeParser], None]) -> bool:
"""
By providing a callback, this function allows calling code to utilize
the new parse-tree/percy recipe parser in a way that is backwards
compatible with the `Recipe` class.
By providing a callback, this function allows calling code to utilize the new parse-tree/percy recipe parser
in a way that is backwards compatible with the `Recipe` class.
NOTE: Expect this function to be eventually deprecated. It is provided
as a stop-gap as we experiment and potentially transition to
primarily use the `RecipeParser`/parse tree implementation.
NOTE: Expect this function to be eventually deprecated. It is provided as a stop-gap as we experiment and
potentially transition to primarily use the `RecipeParser`/parse tree implementation.
In general, prefer using the `patch()` function in the `PARSE_TREE`
operating mode for most recipe-patching needs. This mechanism is
provided to allow callers access to some of the newest features and
capabilities.
In general, prefer using the `patch()` function in the `PARSE_TREE` operating mode for most recipe-patching
needs. This mechanism is provided to allow callers access to some of the newest features and capabilities.
:param callback: Callback that provides a `RecipeParser` instance that can make modifications that will be
reflected in the `Recipe` class.
Expand All @@ -659,6 +655,25 @@ def patch_with_parser(self, callback: Callable[[RecipeParser], None]) -> bool:
self.render()
return parser.is_modified()

def get_read_only_parser(self) -> RecipeParser:
"""
This function returns a read-only parser that is incapable of committing changes to the original recipe file.
To put another way, any writes to this parser will only cause changes in memory AND NOT to the underlying recipe
file.
It is incredibly important to understand the implications of calling this function from a security and thread
safety perspective. This function exists so that we can use the the `RecipeParser` class in the `check_*()`
functions in `anaconda-linter`
NOTE: Expect this function to be eventually deprecated. It is provided as a stop-gap as we experiment and
potentially transition to primarily use the `RecipeParser`/parse tree implementation.
:returns: An instance of the `RecipeParser` class containing the state of the recipe file at time of call.
"""
# TODO Future: Consider constructing this with an optional flag that disables writes further or throws when
# a write is attempted(?)
return RecipeParser("\n".join(self.meta_yaml))

def patch(
self,
operations: list[JsonPatchType],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespaces = false

[project]
name = "percy"
version = "0.1.4"
version = "0.1.5"
authors = [
{ name="Anaconda, Inc.", email="distribution_team@anaconda.com" },
]
Expand Down

0 comments on commit 2502a06

Please sign in to comment.