Skip to content

Commit

Permalink
Adds support for no_git_on_windows auto-fix
Browse files Browse the repository at this point in the history
Adds support for auto fixing the `no-git-on-windows` rule using the new parse
tree tooling in `percy`.

NOTE: This requires changes found in [this percy PR](anaconda/percy#63)
so DO NOT MERGE, until

This PR is being put up as a proof of concept, to show that the new parse
tree work can be integrated into Anaconda Linter.

`percy` will need a new version bump AND the linter will need to pin to that
new version of `percy` prior to accepting this PR.

Tested this manually. I can add a unit test in a subsequent commit. Again, this
is mostly going out prematurely as a POC.
  • Loading branch information
schuylermartin45 committed Oct 18, 2023
1 parent 7180004 commit 43ae76e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion anaconda_linter/lint/check_build_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
from pathlib import Path
from typing import Any
from percy.render.recipe_parser import RecipeParser, SelectorConflictMode

from .. import utils as _utils
from . import INFO, WARNING, LintCheck
Expand Down Expand Up @@ -982,7 +983,20 @@ def check_deps(self, deps):
if self.recipe.selector_dict.get("win", 0) == 1 and "git" in deps:
for path in deps["git"]["paths"]:
output = -1 if not path.startswith("outputs") else int(path.split("/")[1])
self.message(section=path, output=output)
self.message(section=path, output=output, data=path)

def fix(self, _message, _data) -> bool:
# NOTE: The path found in `check_deps()` is a post-selector-rendering
# path to the dependency. So in order to change the recipe file, we need
# to relocate `git`, relative to the raw file.
def _add_git_selector(parser: RecipeParser) -> None:
paths = parser.find_value("git")
for path in paths:
# Attempt to filter-out false-positives
if not path.startswith("/requirements/"):
continue
parser.add_selector(path, "[not win]", SelectorConflictMode.AND)
return self.recipe.patch_with_parser(_add_git_selector)


class gui_app(LintCheck):
Expand Down

0 comments on commit 43ae76e

Please sign in to comment.