Skip to content

Commit

Permalink
Ensure safety checks the installed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Aug 21, 2021
1 parent 8adecc4 commit 1cd6b2d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions .github/static/get_dic2owl_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
# Retrieve dependencies
Retrieve dependencies from a `requirements.txt`-style file.
"""
import argparse
from pathlib import Path
import re
from typing import Set


def main(argv: list = None) -> Set[str]:
"""Retrieve dependencies"""
parser = argparse.ArgumentParser(
description=main.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"requirements_files",
metavar="FILE",
type=Path,
nargs="+",
help="The path(s) to one or several requirements.txt-style file(s).",
)
args = parser.parse_args(argv)

requirements_regex = re.compile(r"^(?P<name>[A-Za-z0-9_-]+)(~=|>=|==).*\n$")
dependencies = set()
for file in args.requirements_files:
if not file.exists():
raise FileNotFoundError(f"Could not find {file} !")
with open(file.resolve(), "r") as handle:
for line in handle.readlines():
match = requirements_regex.fullmatch(line)
if match is None:
raise ValueError(
f"Couldn't determine package name from line:\n\n {line}"
)
dependencies.add(match.group("name"))
return dependencies


if __name__ == "__main__":
from sys import argv

dependencies = main(argv[1:])
grep_extended_regex = f"({'|'.join(dependencies)})"
print(grep_extended_regex)
4 changes: 2 additions & 2 deletions .github/workflows/dic2owl_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:

- name: Run safety
run: |
safety check -r dic2owl/requirements.txt --bare
safety check -r dic2owl/requirements_dev.txt --bare
DEPENDENCIES=$( python .github/static/get_dic2owl_deps.py dic2owl/requirements.txt dic2owl/requirements_dev.txt )
pip freeze | grep -E "${DEPENDENCIES}" | safety check --stdin
- name: Lint with MyPy
run: mypy --ignore-missing-imports --scripts-are-modules dic2owl/dic2owl
Expand Down

0 comments on commit 1cd6b2d

Please sign in to comment.