Skip to content
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
16 changes: 11 additions & 5 deletions scurvysin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def expfl(self) -> list:
return ['install']


class NotFoundError(RuntimeError):
pass


def already_satisfied(req: str) -> bool:
requirement = Requirement(req)
environment = Environment()
Expand Down Expand Up @@ -95,13 +99,11 @@ def get_pip_requirements(req: str) -> Dict[str, str]:
# print(r.stdout)
data = json.loads(r.stdout)
if "error" in data:
print(f"Error: {data['error']}")
exit(1)
raise NotFoundError(f"Error: {data['error']}")
else:
return data["requirements"]
except json.decoder.JSONDecodeError as err:
print("Invalid JSON")
exit(1)
raise NotFoundError(f"Invalid JSON: {r.stdout[:100]}...")


def parse_requirements_file(path: str) -> List[str]:
Expand Down Expand Up @@ -144,7 +146,11 @@ def try_install(req: str, opts: dict, coflags: CondaFlags, pipflags: PipFlags) -
install_using_conda(req, coflags)
else:
print(f"Checking dependencies for {req} using pip...")
requirements = get_pip_requirements(req)
try:
requirements = get_pip_requirements(req)
except RuntimeError as exc:
print(exc)
sys.exit(1)
print(f"Dependencies for {req}: {list(requirements.values())}.")
for requirement in requirements.values():
try_install(requirement, opts, coflags, pipflags)
Expand Down
9 changes: 5 additions & 4 deletions scurvysin/get_pip_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def get_dependencies(r: str) -> List[InstallRequirement]:
class FakeDownloadCommand(DownloadCommand):
@with_cleanup
def run(self, options: Values, args: List[str]) -> int:
print(options)

options.ignore_installed = True
# editable doesn't really make sense for `pip download`, but the bowels
# of the RequirementSet code require that property.
Expand Down Expand Up @@ -141,9 +139,12 @@ def run(self, options: Values, args: List[str]) -> int:
command.main([r])
requirements.sort(key=lambda l: l.name)

errors = sys.stderr.getvalue()
if "Could not find a version" in errors:
raise RuntimeError("Not found.")

# The set contains the package itself, so we need to remove it.
return [l for l in requirements if str(l.req) != r]

return [l for l in requirements if str(l.req) != r]
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
Expand Down
24 changes: 24 additions & 0 deletions tests/test_scurvysin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import subprocess
import unittest

from scurvysin import get_pip_requirements, NotFoundError


class TestGetPipDeps(unittest.TestCase):
def setUp(self) -> None:
# TODO: Forbid all custom pypi indices.
os.environ["PIP_INDEX_URL"] = "https://pypi.python.org/simple"

def test_non_existent(self):
def invoke():
get_pip_requirements("non-existent-package-please-do-not-create-it-qqqqq")
self.assertRaises(NotFoundError, invoke)

def test_existent(self):
# TODO: Implement
fail


if __name__ == '__main__':
unittest.main()