Skip to content

Commit

Permalink
Add a migration to add a version pin to pytest
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
mdellweg committed Jan 30, 2024
1 parent 59cd732 commit 3685c90
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import yaml
from pathlib import Path

from jinja2 import Environment, FileSystemLoader
from packaging.requirements import Requirement


DEFAULT_SETTINGS = {
Expand Down Expand Up @@ -329,11 +330,44 @@ def main():
file_path = os.path.join(plugin_root_dir, "template_config.yml")
print("\nAn updated plugin template config written to {path}.\n".format(path=file_path))

if "github" in sections:
migrate_pytest_pin(plugin_root_dir)

if plugin_root_dir:
print("\nDeprecation check:")
check_for_deprecated_files(plugin_root_dir, sections)


def migrate_pytest_pin(plugin_root_dir):
for item in ["func", "unit"]:
with open(f"{plugin_root_dir}/{item}test_requirements.txt", "r") as fp:
lines = fp.readlines()
modified = False
found = False
result = []
for line in lines:
try:
req = Requirement(line)
except ValueError:
result.append(line)
continue
if req.name == "pytest":
found = True
if not req.specifier:
req.specifier = "<8"
result.append(str(req) + "\n")
modified = True
continue
result.append(line)
if not found:
result.append("pytest<8\n")
modified = True

if modified:
with open(f"{plugin_root_dir}/{item}test_requirements.txt", "w") as fp:
fp.writelines(result)


def to_nice_yaml(data):
"""Implement a filter for Jinja 2 templates to render human readable YAML."""
return yaml.dump(data, indent=2, allow_unicode=True, default_flow_style=False)
Expand Down

0 comments on commit 3685c90

Please sign in to comment.