Skip to content

Commit

Permalink
Adds ability to process Pipfile's
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdottom committed Jun 27, 2018
1 parent 5681a15 commit 0e3aeb9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'termcolor>=1',
'setuptools>=',
'requests>=2',
'toml'
]

setup_requirements = [
Expand Down
37 changes: 34 additions & 3 deletions tests/test_thanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import sys
from textwrap import dedent
import unittest
from click.testing import CliRunner

Expand Down Expand Up @@ -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
17 changes: 8 additions & 9 deletions thanks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -28,19 +28,18 @@
@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
thanks = Thanks(debug=debug)
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())

Expand Down
13 changes: 10 additions & 3 deletions thanks/thanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import requirements
import requests
import termcolor
import toml
from termcolor import colored, cprint

from . import package_tools
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0e3aeb9

Please sign in to comment.