-
Notifications
You must be signed in to change notification settings - Fork 429
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
Fix MetaData.get_section
handling for "source" & "outputs"
#5112
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
39ee6d8
Correct variant handling in MetaData.fromstring
kenodegard ef0cc05
Correct typing
kenodegard 93e98dd
Ensure get_section returns list for source and outputs
kenodegard 409f7e3
Add MetaData tests
kenodegard 725051c
Touchup
kenodegard 0e75945
Revert recipe change
kenodegard 2d640b7
Add news
kenodegard 80b5ade
Revert removing assertions
kenodegard 826472e
Update news/5112-fix-multiple-sources
kenodegard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
from collections import OrderedDict | ||
from functools import lru_cache | ||
from os.path import isfile, join | ||
from typing import Literal | ||
from typing import Literal, overload | ||
|
||
from bs4 import UnicodeDammit | ||
|
||
|
@@ -622,6 +622,7 @@ def parse(data, config, path=None): | |
"prelink_message": None, | ||
"readme": None, | ||
}, | ||
"extra": {}, | ||
} | ||
|
||
# Fields that may either be a dictionary or a list of dictionaries. | ||
|
@@ -1316,9 +1317,11 @@ def parse_until_resolved( | |
@classmethod | ||
def fromstring(cls, metadata, config=None, variant=None): | ||
m = super().__new__(cls) | ||
if not config: | ||
config = Config() | ||
m.meta = parse(metadata, config=config, path="", variant=variant) | ||
m.path = "" | ||
m._meta_path = "" | ||
m.requirements_path = "" | ||
Comment on lines
+1320
to
+1322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. initialization missing that was discovered by the newly added unit test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh! |
||
config = config or Config(variant=variant) | ||
m.meta = parse(metadata, config=config, path="") | ||
m.config = config | ||
m.parse_again(permit_undefined_jinja=True) | ||
return m | ||
|
@@ -1333,18 +1336,45 @@ def fromdict(cls, metadata, config=None, variant=None): | |
m._meta_path = "" | ||
m.requirements_path = "" | ||
m.meta = sanitize(metadata) | ||
|
||
if not config: | ||
config = Config(variant=variant) | ||
|
||
m.config = config | ||
m.config = config or Config(variant=variant) | ||
m.undefined_jinja_vars = [] | ||
m.final = False | ||
|
||
return m | ||
|
||
def get_section(self, section): | ||
return self.meta.get(section, {}) | ||
@overload | ||
def get_section(self, section: Literal["source", "outputs"]) -> list[dict]: | ||
... | ||
|
||
@overload | ||
def get_section( | ||
self, | ||
section: Literal[ | ||
"package", | ||
"build", | ||
"requirements", | ||
"app", | ||
"test", | ||
"about", | ||
"extra", | ||
], | ||
) -> dict: | ||
... | ||
|
||
def get_section(self, name): | ||
section = self.meta.get(name) | ||
if name in OPTIONALLY_ITERABLE_FIELDS: | ||
if not section: | ||
return [] | ||
elif isinstance(section, dict): | ||
return [section] | ||
elif not isinstance(section, list): | ||
raise ValueError(f"Expected {name} to be a list") | ||
else: | ||
if not section: | ||
return {} | ||
elif not isinstance(section, dict): | ||
raise ValueError(f"Expected {name} to be a dict") | ||
return section | ||
|
||
def get_value(self, name, default=None, autotype=True): | ||
""" | ||
|
@@ -1364,7 +1394,9 @@ def get_value(self, name, default=None, autotype=True): | |
index = None | ||
elif len(names) == 3: | ||
section, index, key = names | ||
assert section == "source", "Section is not a list: " + section | ||
assert section in OPTIONALLY_ITERABLE_FIELDS, ( | ||
"Section is not a list: " + section | ||
) | ||
index = int(index) | ||
|
||
# get correct default | ||
|
@@ -1386,7 +1418,7 @@ def get_value(self, name, default=None, autotype=True): | |
) | ||
index = 0 | ||
|
||
if len(section_data) == 0: | ||
if not section_data: | ||
section_data = {} | ||
else: | ||
section_data = section_data[index] | ||
|
@@ -1475,7 +1507,7 @@ def get_depends_top_and_out(self, typ): | |
if not self.is_output: | ||
matching_output = [ | ||
out | ||
for out in self.meta.get("outputs", []) | ||
for out in self.get_section("outputs") | ||
if out.get("name") == self.name() | ||
] | ||
if matching_output: | ||
|
@@ -2014,7 +2046,7 @@ def uses_jinja(self): | |
return len(matches) > 0 | ||
|
||
@property | ||
def uses_vcs_in_meta(self) -> Literal["git" | "svn" | "mercurial"] | None: | ||
def uses_vcs_in_meta(self) -> Literal["git", "svn", "mercurial"] | None: | ||
"""returns name of vcs used if recipe contains metadata associated with version control systems. | ||
If this metadata is present, a download/copy will be forced in parse_or_try_download. | ||
""" | ||
|
@@ -2034,7 +2066,7 @@ def uses_vcs_in_meta(self) -> Literal["git" | "svn" | "mercurial"] | None: | |
return vcs | ||
|
||
@property | ||
def uses_vcs_in_build(self) -> Literal["git" | "svn" | "mercurial"] | None: | ||
def uses_vcs_in_build(self) -> Literal["git", "svn", "mercurial"] | None: | ||
# TODO :: Re-work this. Is it even useful? We can declare any vcs in our build deps. | ||
build_script = "bld.bat" if on_win else "build.sh" | ||
build_script = os.path.join(self.path, build_script) | ||
|
@@ -2271,9 +2303,8 @@ def pin_depends(self): | |
|
||
@property | ||
def source_provided(self): | ||
return not bool(self.meta.get("source")) or ( | ||
os.path.isdir(self.config.work_dir) | ||
and len(os.listdir(self.config.work_dir)) > 0 | ||
return not self.get_section("source") or ( | ||
os.path.isdir(self.config.work_dir) and os.listdir(self.config.work_dir) | ||
) | ||
|
||
def reconcile_metadata_with_output_dict(self, output_metadata, output_dict): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
### Enhancements | ||
|
||
* Update `conda_build.metadata.MetaData.get_section` to always return lists for "source" and "outputs". (#5112) | ||
|
||
### Bug fixes | ||
|
||
* Fix finalizing recipes with multiple sources. (#5111 via #5112) | ||
|
||
### Deprecations | ||
|
||
* <news item> | ||
|
||
### Docs | ||
|
||
* <news item> | ||
|
||
### Other | ||
|
||
* <news item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra
could be anything else (scalar or sequence, not just mapping) acc. to https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#extra-section .This broke an assumption in
conda-smithy
at least: conda-forge/conda-smithy#1816 .So, technically a breaking change; but I'd be okay with requiring a mapping here.
This needs an update to the docs, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened gh-5125 to track this.