From 0e3aeb9449162992285ee96901ae71c224bd77b7 Mon Sep 17 00:00:00 2001 From: Tom Marks Date: Tue, 26 Jun 2018 22:50:58 -0400 Subject: [PATCH] Adds ability to process Pipfile's --- setup.py | 1 + tests/test_thanks.py | 37 ++++++++++++++++++++++++++++++++++--- thanks/cli.py | 17 ++++++++--------- thanks/thanks.py | 13 ++++++++++--- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 9cf96e5..a347a1d 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ 'termcolor>=1', 'setuptools>=', 'requests>=2', + 'toml' ] setup_requirements = [ diff --git a/tests/test_thanks.py b/tests/test_thanks.py index 4e76122..e60f4c7 100644 --- a/tests/test_thanks.py +++ b/tests/test_thanks.py @@ -5,6 +5,7 @@ import os import sys +from textwrap import dedent import unittest from click.testing import CliRunner @@ -45,9 +46,39 @@ def test_thanks_package(self): def test_thanks_requirements_list(self): thanks = Thanks() - thanks.requirements_list(["crunchy-frog"]) + thanks.requirements_list(dedent(""" + crunchy-frog + mosw + """)) output = thanks.rocks(colored_output=False) - assert "You depend on 1 authors" in output - assert "crunchy-frog Kenneth Reitz" in output + assert "You depend on 2 authors" in output + assert "crunchy-frog Kenneth Reitz" in output + assert "mosw http://ministry-of-silly-walks.python/fundme Tom Marks" in output + + def test_thanks_pipfile(self): + pipfile_contents = dedent(""" + [[source]] + url = "https://pypi.python.org/simple" + verify_ssl = true + name = "pypi" + + [packages] + crunchy-frog = "==0.2" + + [dev-packages] + mosw = "*" + + [requires] + python_version = "3.6" + """) + thanks = Thanks() + + thanks.pipfile(pipfile_contents) + + output = thanks.rocks(colored_output=False) + + assert "You depend on 2 authors" in output + assert "crunchy-frog Kenneth Reitz" in output + assert "mosw http://ministry-of-silly-walks.python/fundme Tom Marks" in output diff --git a/thanks/cli.py b/thanks/cli.py index 8fa2477..3393243 100644 --- a/thanks/cli.py +++ b/thanks/cli.py @@ -16,9 +16,9 @@ @click.option("--requirements", "-r", multiple=True, type=click.File("r")) -# @click.option("--pipfile", "-p", -# multiple=True, -# type=click.File("r")) +@click.option("--pipfile", "-p", + multiple=True, + type=click.File("r")) # @click.option("--setuppy", "-s", # multiple=True, # type=click.File("r")) @@ -28,8 +28,8 @@ @click.option("--outfile", "-o", type=click.File("w"), default="-", help='Save output to file') -def main(package_name, requirements, - # pipfile, setuppy, +def main(package_name, requirements, pipfile, + # setuppy, debug, outfile): if debug: logger.level = logging.DEBUG @@ -37,10 +37,9 @@ def main(package_name, requirements, for p in package_name: thanks.package(p) for r in requirements: - requirements_list = r.read().splitlines() - thanks.requirements_list(requirements_list) - # for p in pipfile: - # thanks.pipfile(p) + thanks.requirements_list(r.read()) + for p in pipfile: + thanks.pipfile(p.read()) outfile.write(thanks.rocks()) diff --git a/thanks/thanks.py b/thanks/thanks.py index e67ae6f..1b7b3a0 100644 --- a/thanks/thanks.py +++ b/thanks/thanks.py @@ -9,6 +9,7 @@ import requirements import requests import termcolor +import toml from termcolor import colored, cprint from . import package_tools @@ -37,13 +38,19 @@ def requirements_list(self, requirements_list): print('Scanning your {} file...'.format(colored('requirements', 'red'))) reqs = [ next(requirements.parse(r)) - for r in requirements_list + for r in requirements_list.splitlines() + if r != "" ] for req in reqs: self.package(req.name) - # def pipfile(self, pipfile): - # pass + def pipfile(self, pipfile): + project_data = toml.loads(pipfile) + reqs = [] + reqs += list(project_data.get("packages", {}).keys()) + reqs += list(project_data.get("dev-packages", {}).keys()) + for req in reqs: + self.package(req) def _get_local_data(self, project_name): try: