Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbanffy committed Aug 20, 2018
2 parents 35e9c5f + 0c126ce commit 09a6d0e
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -67,6 +67,8 @@ target/
.venv
.venv3
.env
env2

# Others
cache
.pytest_cache
3 changes: 0 additions & 3 deletions .travis.yml
Expand Up @@ -4,13 +4,10 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "nightly"
- "pypy"
- "pypy3"

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install tox-travis
Expand Down
5 changes: 5 additions & 0 deletions HISTORY.rst
Expand Up @@ -2,6 +2,11 @@
History
=======

0.1.8 (2018-08-20)
------------------

* Fixes, compatibility with Python 2.7, 3.6, 3.7

0.1.7 (2018-01-22)
------------------

Expand Down
10 changes: 4 additions & 6 deletions Makefile
Expand Up @@ -50,15 +50,13 @@ clean-test: ## remove test and coverage artifacts
lint: ## check style with flake8
flake8 pip_chill tests

# test: ## run tests quickly with the default Python
test: ## run tests quickly with the default Python
python setup.py test

# python setup.py test

# test-all: ## run tests on every Python version with tox
# tox
test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python

coverage run --source pip_chill setup.py test
coverage report -m
coverage html
Expand Down
2 changes: 1 addition & 1 deletion pip_chill/__init__.py
Expand Up @@ -4,6 +4,6 @@

__author__ = 'Ricardo Bánffy'
__email__ = 'rbanffy@gmail.com'
__version__ = '0.1.3'
__version__ = '0.1.8'

__all__ = [chill]
40 changes: 36 additions & 4 deletions pip_chill/pip_chill.py
@@ -1,23 +1,55 @@
# -*- coding: utf-8 -*-
"""Lists installed packages that are not dependencies of others"""

import pip
from pip._internal.utils.misc import get_installed_distributions

from utils import Distribution

# from pip_chill.utils import Distribution
class Distribution:
def __init__(self, name, version=None, required_by=None):
self.name = name
self.version = version
self.required_by = set(required_by) if required_by else set()

def get_name_without_version(self):
if self.required_by:
return '# {} # Installed as dependency for {}' \
.format(self.name, ', '.join(self.required_by))
return self.name

def __str__(self):
if self.required_by:
return '# {}=={} # Installed as dependency for {}' \
.format(self.name, self.version, ', '.join(self.required_by))
return '{}=={}'.format(self.name, self.version)

def __eq__(self, other):
if self is other:
return True
elif isinstance(other, Distribution):
return True if self.name == other.name else False
else:
return True if self.name == other else False

def __lt__(self, other):
return self.name < other.name

def __hash__(self):
return hash(self.name)


def chill(show_all=False):
if show_all:
ignored_packages = ()
else:
ignored_packages = {
'pip', 'pip-chill', 'wheel', 'setuptools', 'pkg-resources'}
'pip', 'wheel', 'setuptools', 'pkg-resources'}

# Gather all packages that are requirements and will be auto-installed.
distributions = {}
dependencies = {}

for distribution in pip.get_installed_distributions():
for distribution in get_installed_distributions():
if distribution.key in ignored_packages:
continue

Expand Down
33 changes: 0 additions & 33 deletions pip_chill/utils.py

This file was deleted.

3 changes: 2 additions & 1 deletion setup.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.7
current_version = 0.1.8
commit = True
tag = True

Expand All @@ -16,3 +16,4 @@ universal = 1

[flake8]
exclude = docs

5 changes: 3 additions & 2 deletions setup.py
Expand Up @@ -19,7 +19,7 @@

setup(
name='pip-chill',
version='0.1.7',
version='0.1.8',
description="Like `pip freeze` but lists only the packages that are not "
"dependencies of installed packages.",
long_description=readme + '\n\n' + history,
Expand Down Expand Up @@ -50,9 +50,10 @@
"Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
test_suite='tests',
tests_require=test_requirements
Expand Down
43 changes: 37 additions & 6 deletions tests/test_pip_chill.py
Expand Up @@ -13,21 +13,26 @@
import unittest
from click.testing import CliRunner

from pip_chill import pip_chill
from pip_chill import cli
from pip_chill import (
pip_chill,
cli,
)
from pip_chill.pip_chill import Distribution


class TestPip_chill(unittest.TestCase):

def setUp(self):
pass
self.distribution_1 = Distribution('pip-chill', '2.0.0', [])
self.distribution_2 = Distribution('pip', '10.0.0', [self.distribution_1])
self.distribution_3 = Distribution('pip', '11.0.0', [self.distribution_1])

def tearDown(self):
pass

def test_pip_ommitted(self):
packages, _ = pip_chill.chill()
hidden = {'pip-chill', 'wheel', 'setuptools', 'pip'}
hidden = {'wheel', 'setuptools', 'pip'}
for package in packages:
assert package.name not in hidden

Expand All @@ -37,6 +42,17 @@ def test_all(self):
for package in ['wheel', 'pip']:
assert package in package_names

def test_hashes(self):
packages, _ = pip_chill.chill()
for package in packages:
assert hash(package) == hash(package.name)

def test_equality(self):
assert self.distribution_1 != self.distribution_2
assert self.distribution_1 == self.distribution_1
assert self.distribution_2 == self.distribution_3
assert self.distribution_2 == self.distribution_2.name

def test_command_line_interface_help(self):
runner = CliRunner()
result = runner.invoke(cli.main, ['--help'])
Expand All @@ -52,12 +68,27 @@ def test_command_line_interface_no_version(self):
assert result.exit_code == 0
assert '==' not in result.output

def test_command_line_interface_verbose(self):
runner = CliRunner()
result = runner.invoke(cli.main, ['--verbose'])
assert result.exit_code == 0
assert '# Installed as dependency for' in result.output

def test_command_line_interface_verbose_no_version(self):
runner = CliRunner()
result = runner.invoke(cli.main, ['--verbose', '--no-version'])
assert result.exit_code == 0
assert '==' not in result.output
assert '# Installed as dependency for' in result.output

def test_command_line_interface_omits_ignored(self):
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
for package in ['pip-chill', 'wheel', 'setuptools', 'pip']:
assert package not in result.output
for package in ['wheel', 'setuptools', 'pip']:
assert not any(
[p.startswith(package + '==')
for p in result.output.split('\n')])

def test_command_line_interface_all(self):
runner = CliRunner()
Expand Down
8 changes: 2 additions & 6 deletions tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py36, flake8
envlist = py27, py34, py35, py36, py37, flake8

[testenv:flake8]
basepython=python
Expand All @@ -9,10 +9,6 @@ commands=flake8 pip_chill
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/pip_chill
deps = -rrequirements_dev.txt

commands = python setup.py test

; If you want to make tox run the tests with the same versions, create a
; requirements.txt with the pinned versions and uncomment the following lines:
; deps =
; -r{toxinidir}/requirements.txt

0 comments on commit 09a6d0e

Please sign in to comment.