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 skipping noarch selector lints #2090

Merged
merged 2 commits into from
Oct 11, 2024
Merged
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
58 changes: 52 additions & 6 deletions conda_smithy/data/conda-forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,27 @@
"title": "Upload Packages"
},
"settings_linux": {
"$ref": "#/$defs/AzureRunnerSettings",
"allOf": [
{
"$ref": "#/$defs/AzureRunnerSettings"
}
],
"description": "Linux-specific settings for runners"
},
"settings_osx": {
"$ref": "#/$defs/AzureRunnerSettings",
"allOf": [
{
"$ref": "#/$defs/AzureRunnerSettings"
}
],
"description": "OSX-specific settings for runners"
},
"settings_win": {
"$ref": "#/$defs/AzureRunnerSettings",
"allOf": [
{
"$ref": "#/$defs/AzureRunnerSettings"
}
],
"description": "Windows-specific settings for runners"
},
"user_or_org": {
Expand Down Expand Up @@ -781,12 +793,35 @@
"title": "GithubConfig",
"type": "object"
},
"LinterConfig": {
"properties": {
"skip": {
"anyOf": [
{
"items": {
"$ref": "#/$defs/Lints"
},
"type": "array"
},
{
"type": "null"
}
],
"description": "List of lints to skip",
"title": "Skip"
}
},
"title": "LinterConfig",
"type": "object"
},
"Lints": {
"const": "lint_noarch_selectors",
"title": "Lints",
"type": "string"
},
"Nullable": {
"const": null,
"description": "Created to avoid issue with schema validation of null values in lists or dicts.",
"enum": [
null
],
"title": "Nullable"
},
"Platforms": {
Expand Down Expand Up @@ -1696,6 +1731,17 @@
],
"description": "Settings in this block are used to control how `conda build`\nruns and produces artifacts. An example of the such configuration is:\n\n```yaml\nconda_build:\n pkg_format: 2\n zstd_compression_level: 16\n error_overlinking: False\n```"
},
"linter": {
"anyOf": [
{
"$ref": "#/$defs/LinterConfig"
},
{
"type": "null"
}
],
"description": "Settings in this block are used to control how `conda smithy` lints\nAn example of the such configuration is:\n\n```yaml\nlinter:\n skip:\n - lint_noarch_selectors\n```"
},
"conda_build_tool": {
"anyOf": [
{
Expand Down
2 changes: 2 additions & 0 deletions conda_smithy/data/conda-forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github_actions:
triggers: []
upload_packages: true
idle_timeout_minutes: null
linter:
skip: []
max_py_ver: '37'
max_r_ver: '34'
min_py_ver: '27'
Expand Down
45 changes: 27 additions & 18 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
NEEDED_FAMILIES = ["gpl", "bsd", "mit", "apache", "psf"]


def lintify_forge_yaml(recipe_dir: Optional[str] = None) -> (list, list):
def _get_forge_yaml(recipe_dir: Optional[str] = None) -> dict:
if recipe_dir:
forge_yaml_filename = (
glob(os.path.join(recipe_dir, "..", "conda-forge.yml"))
Expand All @@ -94,6 +94,11 @@ def lintify_forge_yaml(recipe_dir: Optional[str] = None) -> (list, list):
else:
forge_yaml = {}

return forge_yaml


def lintify_forge_yaml(recipe_dir: Optional[str] = None) -> (list, list):
forge_yaml = _get_forge_yaml(recipe_dir)
# This is where we validate against the jsonschema and execute our custom validators.
return validate_json_schema(forge_yaml)

Expand All @@ -107,6 +112,9 @@ def lintify_meta_yaml(
lints = []
hints = []
major_sections = list(meta.keys())
lints_to_skip = (
_get_forge_yaml(recipe_dir).get("linter", {}).get("skip", [])
)

# If the recipe_dir exists (no guarantee within this function) , we can
# find the meta.yaml within it.
Expand Down Expand Up @@ -265,23 +273,24 @@ def lintify_meta_yaml(

# 18: noarch doesn't work with selectors for runtime dependencies
noarch_platforms = len(forge_yaml.get("noarch_platforms", [])) > 1
if recipe_version == 1:
raw_requirements_section = meta.get("requirements", {})
lint_recipe_v1_noarch_and_runtime_dependencies(
noarch_value,
raw_requirements_section,
build_section,
noarch_platforms,
lints,
)
else:
lint_noarch_and_runtime_dependencies(
noarch_value,
recipe_fname,
forge_yaml,
conda_build_config_keys,
lints,
)
if "lint_noarch_selectors" not in lints_to_skip:
if recipe_version == 1:
raw_requirements_section = meta.get("requirements", {})
lint_recipe_v1_noarch_and_runtime_dependencies(
noarch_value,
raw_requirements_section,
build_section,
noarch_platforms,
lints,
)
else:
lint_noarch_and_runtime_dependencies(
noarch_value,
recipe_fname,
forge_yaml,
conda_build_config_keys,
lints,
)

# 19: check version
if recipe_version == 1:
Expand Down
28 changes: 28 additions & 0 deletions conda_smithy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class BotConfigVersionUpdatesSourcesChoice(StrEnum):
ROS_DISTRO = "rosdistro"


class Lints(StrEnum):
LINT_NOARCH_SELECTORS = "lint_noarch_selectors"


##############################################
########## Model definitions #################
##############################################
Expand Down Expand Up @@ -446,6 +450,14 @@ class CondaBuildConfig(BaseModel):
)


class LinterConfig(BaseModel):

skip: Optional[List[Lints]] = Field(
default_factory=list,
description="List of lints to skip",
)


class CondaForgeDocker(BaseModel):
model_config: ConfigDict = ConfigDict(extra="forbid")

Expand Down Expand Up @@ -575,6 +587,22 @@ class ConfigModel(BaseModel):
),
)

linter: Optional[LinterConfig] = Field(
default_factory=LinterConfig,
description=cleandoc(
"""
Settings in this block are used to control how `conda smithy` lints
An example of the such configuration is:

```yaml
linter:
skip:
- lint_noarch_selectors
```
"""
),
)

conda_build_tool: Optional[conda_build_tools] = Field(
default="conda-build",
description=cleandoc(
Expand Down
49 changes: 47 additions & 2 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,24 @@ def test_noarch_selectors(self):

with tmp_directory() as recipe_dir:

def assert_noarch_selector(meta_string, is_good=False):
def assert_noarch_selector(meta_string, is_good=False, skip=False):
with open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(meta_string)
if skip:
with open(
os.path.join(recipe_dir, "conda-forge.yml"), "w"
) as fh:
fh.write(
"""
linter:
skip:
- lint_noarch_selectors
"""
)
lints = linter.main(recipe_dir)
if skip:
os.remove(os.path.join(recipe_dir, "conda-forge.yml"))

if is_good:
message = (
"Found lints when there shouldn't have "
Expand Down Expand Up @@ -1053,6 +1067,15 @@ def assert_noarch_selector(meta_string, is_good=False):
skip: true # [win]
"""
)
assert_noarch_selector(
"""
build:
noarch: generic
skip: true # [win]
""",
is_good=True,
skip=True,
)
assert_noarch_selector(
"""
build:
Expand Down Expand Up @@ -1169,7 +1192,10 @@ def test_recipe_v1_noarch_selectors(self):
with tmp_directory() as recipe_dir:

def assert_noarch_selector(
meta_string, is_good=False, has_noarch=False
meta_string,
is_good=False,
has_noarch=False,
skip=False,
):
with open(os.path.join(recipe_dir, "recipe.yaml"), "w") as fh:
fh.write(meta_string)
Expand All @@ -1184,10 +1210,19 @@ def assert_noarch_selector(
noarch_platforms:
- win_64
- linux_64
"""
)
if skip:
fh.write(
"""
linter:
skip:
- lint_noarch_selectors
"""
)

lints = linter.main(recipe_dir, feedstock_dir=recipe_dir)
os.remove(os.path.join(recipe_dir, "conda-forge.yml"))
if is_good:
message = (
"Found lints when there shouldn't have "
Expand All @@ -1212,6 +1247,16 @@ def assert_noarch_selector(
- win
"""
)
assert_noarch_selector(
"""
build:
noarch: python
skip:
- win
""",
is_good=True,
skip=True,
)
assert_noarch_selector(
"""
build:
Expand Down
Loading