Skip to content

Commit

Permalink
Merge pull request #1 from pythomec/requirements
Browse files Browse the repository at this point in the history
Enable requirements file
  • Loading branch information
coobas committed May 21, 2019
2 parents 2e95bed + 333f92d commit 2acbf54
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
25 changes: 23 additions & 2 deletions scurvysin/__init__.py
Expand Up @@ -10,10 +10,10 @@
import os
import subprocess
import sys
from typing import Dict
from typing import Dict, List


__version__ = "0.1.1"
__version__ = "0.1.2"


class CondaFlags:
Expand Down Expand Up @@ -82,7 +82,28 @@ def get_pip_requirements(req: str) -> Dict[str, str]:
exit(1)


def parse_requirements_file(path: str) -> List[str]:
reqs = []
with open(path, "r") as infile:
for line in infile:
line = line.strip()
if line.startswith("-"):
raise NotImplementedError("Pip flags in requirements files are not understood.")
elif line.startswith("#"):
continue
else:
reqs.append(line)
return list(sorted(reqs))


def try_install(req: str, opts: dict, coflags: CondaFlags, pipflags: PipFlags) -> None:
if opts.pop("requirement", False):
print(f"Reading requirements file {req}")
requirements = parse_requirements_file(req)
print(f"Dependencies from {req}: {requirements}.")
for requirement in requirements:
try_install(requirement, opts, coflags, pipflags)
return
print(f"Checking {req} in conda...")
if available_in_conda(req):
print(f"Package {req} found in conda.")
Expand Down
7 changes: 6 additions & 1 deletion scurvysin/cli.py
Expand Up @@ -6,7 +6,10 @@


def extopts(args: argparse.Namespace):
return {"show_only" : args.show_only}
return {
"show_only": args.show_only,
"requirement": args.requirement,
}


def main():
Expand All @@ -15,6 +18,8 @@ def main():
help="don't let conda/pip perform installation")
parser.add_argument('--show-only', action='store_true',
help="only show what would be done")
parser.add_argument('--requirement', '-r', action='store_true',
help="use requirements file")
parser.add_argument('req', help="distribution to install")
args = parser.parse_args()

Expand Down

0 comments on commit 2acbf54

Please sign in to comment.