Skip to content

'pip.commands' entry point for pip command plugins #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions pip/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
Package containing all pip commands
"""

from pkg_resources import iter_entry_points

from pip.commands.bundle import BundleCommand
from pip.commands.completion import CompletionCommand
@@ -47,6 +48,12 @@
HelpCommand,
]

# add plugin commands
for entry_point in iter_entry_points('pip.commands', name='command'):
project = entry_point.dist.project_name
commandClass = entry_point.load()
commandClass.summary = "(From %s) %s" % (project, commandClass.summary)
commands[commandClass.name] = commandClass

def get_summaries(ignore_hidden=True, ordered=True):
"""Yields sorted (command name, command summary) tuples."""
14 changes: 14 additions & 0 deletions tests/data/packages/plugin/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

from pip.basecommand import Command

class PluginCommand(Command):
"""
Do Plugin stuff
"""
name = 'plugin'
usage = """
%prog [options] """
summary = 'Do Plugin stuff'

def run(self, options, args):
pass
10 changes: 10 additions & 0 deletions tests/data/packages/plugin/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup, find_packages

setup(
name = "plugin",
version = '1.0',
packages=find_packages(),
entry_points = {'pip.commands': ['command = plugin:PluginCommand']}
)


14 changes: 14 additions & 0 deletions tests/functional/test_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from pip.basecommand import SUCCESS

def test_plugin_found(script, data):
"""
Test extending the 'pip.commands' entry point
"""
# the 'plugin' project provides the 'plugin' command
plugin_path = data.packages.join("plugin")
script.pip('install', plugin_path)
result = script.pip('plugin')
assert result.returncode == SUCCESS
result = script.pip('help')
assert '(From plugin) Do Plugin stuff' in result.stdout