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

skip version updates depending on a regex from the feedstock #1441

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
76 changes: 62 additions & 14 deletions conda_forge_tick/update_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,36 @@ class AbstractSource(abc.ABC):
name: str

@abc.abstractmethod
def get_version(self, url: str) -> Optional[str]:
def get_version(self, url: str, meta_yaml) -> Optional[str]:
pass

@abc.abstractmethod
def get_url(self, meta_yaml) -> Optional[str]:
pass

def get_bot_settings(self, meta_yaml):
if "conda-forge.yml" not in meta_yaml:
return {}
conda_forge_yml = meta_yaml["conda-forge.yml"]
# First check for the text for an early exit
# to avoid parsing yaml if possible
if "bot" not in conda_forge_yaml:
return {}
# Parse the yaml now
parsed_yml = yaml.safe_load(conda_forge_yml)
return parsed_yml.get("bot", {})

def skip_version(self, version, meta_yaml) -> bool:
if not version:
return True
bot_settings = self.get_bot_settings(meta_yaml)
if not bot_settings:
return False
if "version_regex" not in bot_settings:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put this under "version_updates" like the random fraction key.

return False
ver_regex = bot_settings["version_regex"]
return re.match(ver_regex, version) is None


class VersionFromFeed(AbstractSource):
name = "VersionFromFeed"
Expand All @@ -161,7 +184,7 @@ class VersionFromFeed(AbstractSource):
"git",
]

def get_version(self, url) -> Optional[str]:
def get_version(self, url, meta_yaml) -> Optional[str]:
data = feedparser.parse(url)
if data["bozo"] == 1:
return None
Expand All @@ -175,6 +198,8 @@ def get_version(self, url) -> Optional[str]:
continue
# Extract version number starting at the first digit.
ver = re.search(r"(\d+[^\s]*)", ver).group(0)
if self.skip_version(ver, meta_yaml):
continue
vers.append(ver)
if vers:
return max(vers, key=lambda x: VersionOrder(x.replace("-", ".")))
Expand All @@ -193,7 +218,7 @@ def get_url(self, meta_yaml) -> Optional[str]:
pkg = meta_yaml["url"].split("/")[6]
return f"https://pypi.org/pypi/{pkg}/json"

def get_version(self, url) -> Optional[str]:
def get_version(self, url, meta_yaml) -> Optional[str]:
r = requests.get(url)
# If it is a pre-release don't give back the pre-release version
most_recent_version = r.json()["info"]["version"].strip()
Expand All @@ -202,6 +227,10 @@ def get_version(self, url) -> Optional[str]:
if all(parse_version(v).is_prerelease for v in r.json()["releases"]):
return most_recent_version
return False
# FIXME: instead of skipping here, use the latest version that
# is not skipped.
if self.skip_version(most_recent_version, meta_yaml):
return False
return most_recent_version


Expand All @@ -215,13 +244,16 @@ def get_url(self, meta_yaml) -> Optional[str]:
pkg = meta_yaml["url"].split("/")[3:-2]
return f"https://registry.npmjs.org/{'/'.join(pkg)}"

def get_version(self, url: str) -> Optional[str]:
def get_version(self, url: str, meta_yaml) -> Optional[str]:
r = requests.get(url)
if not r.ok:
return False
latest = r.json()["dist-tags"].get("latest", "").strip()
# If it is a pre-release don't give back the pre-release version
if not len(latest) or parse_version(latest).is_prerelease:
if not len(latest) or parse_version(latest).is_prerelease or \
self.skip_version(latest, meta_yaml):
# FIXME: instead of skipping here, use the latest version that
# is not skipped.
return False

return latest
Expand Down Expand Up @@ -287,8 +319,15 @@ def get_url(self, meta_yaml) -> Optional[str]:
return None
return None

def get_version(self, url) -> Optional[str]:
return str(url[1]).replace("-", "_") if url[1] else None
def get_version(self, url, meta_yaml) -> Optional[str]:
if not url[1]:
return None
ver = str(url[1]).replace("-", "_")
# FIXME: instead of skipping here, use the latest version that
# is not skipped. This requires looking at the CRAN archive index
# which we do not currently look at.
if self.skip_version(ver, meta_yaml):
return None


ROS_DISTRO_INDEX: Optional[dict] = None
Expand Down Expand Up @@ -365,8 +404,14 @@ def get_url(self, meta_yaml: "MetaYamlTypedDict") -> Optional[str]:

return final_url

def get_version(self, url):
return self.version_url_cache[url]
def get_version(self, url, meta_yaml):
ver = self.version_url_cache[url]
# FIXME: instead of skipping here, use the latest version that
# is not skipped.
if self.skip_version(ver, meta_yaml):
return False
return ver



def get_sha256(url: str) -> Optional[str]:
Expand Down Expand Up @@ -452,8 +497,9 @@ def get_url(self, meta_yaml) -> Optional[str]:
orig_ver = current_ver
found = True
count = 0
max_count = 10
max_count = self.get_bot_settings(meta_yaml).get("version_update_max_check", 10)

found_ver = orig_ver
while found and count < max_count:
found = False
for next_ver in self.next_ver_func(current_ver):
Expand Down Expand Up @@ -524,15 +570,17 @@ def get_url(self, meta_yaml) -> Optional[str]:
return None
current_sha256 = new_sha256
logger.debug("version %s is ok for url %s", current_ver, url_to_use)
if not self.skip_version(current_ver, meta_yaml):
found_ver = current_ver
break

if current_ver != orig_ver:
logger.debug("using version %s", current_ver)
return current_ver
if found_ver != orig_ver:
logger.debug("using version %s", found_ver)
return found_ver

return None

def get_version(self, url: str) -> str:
def get_version(self, url: str, meta_yaml) -> str:
return url


Expand Down
2 changes: 1 addition & 1 deletion conda_forge_tick/update_upstream_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_latest_version(
logger.debug("url: %s", url)
if url is None:
continue
ver = source.get_version(url)
ver = source.get_version(url, meta_yaml)
logger.debug("ver: %s", ver)
if ver:
version_data["new_version"] = ver
Expand Down
Loading