Skip to content

Commit 668d942

Browse files
committed
Make the server optional to reduce main dependencies
1 parent 368f291 commit 668d942

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

MANIFEST.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
include requirements.txt whatportis/ports.json README.rst LICENSE.txt test_whatportis.py
1+
include README.rst LICENSE.txt tox.ini
2+
3+
graft tests

requirements.txt

-6
This file was deleted.

setup.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
'whatportis=whatportis.cli:run',
66
]
77
}
8-
requirements = open('requirements.txt').read()
98
readme = open('README.rst').read()
109

1110
setup(
@@ -18,11 +17,20 @@
1817
long_description=readme,
1918
packages=['whatportis'],
2019
include_package_data=True,
21-
install_requires=requirements,
20+
install_requires=[
21+
"simplejson",
22+
"tinydb",
23+
"requests",
24+
"prettytable",
25+
"click"
26+
],
2227
extras_require={
2328
"dev": [
2429
"pytest",
2530
"tox"
31+
],
32+
"server": [
33+
"flask"
2634
]
2735
},
2836
entry_points=entry_points,

tox.ini

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ envlist = py{27,33,34,35,36,37}
44
[testenv]
55
deps=
66
pytest
7-
-rrequirements.txt
7+
8+
simplejson
9+
tinydb
10+
requests
11+
prettytable
12+
click
13+
814
commands = pytest

whatportis/cli.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from tinydb import TinyDB
1010

1111
from whatportis.db import get_database, get_ports
12-
from whatportis.server import app
1312
from whatportis.utils import as_table
1413

1514

@@ -54,15 +53,24 @@ def update_db(ctx, param, value):
5453
ctx.exit()
5554

5655

56+
# Change the server help if flask is installed
57+
server_help = "Start a RESTful server"
58+
try:
59+
import flask
60+
server_help += " (format <host> <port>)."
61+
except ImportError:
62+
server_help += " (requires Flask)."
63+
64+
5765
@click.command()
5866
@click.version_option()
5967
@click.argument('PORT', required=False)
6068
@click.option('--like', is_flag=True, default=False,
6169
help='Search ports containing the pattern.')
6270
@click.option('--json', "use_json", is_flag=True, default=False,
6371
help='Format the output result as JSON.')
64-
@click.option("--server", type=(str, int), default=(None, None),
65-
help="Start a RESTful server (Format <host> <port>).")
72+
@click.option("--server", default=[None] * 2, type=click.Tuple([str, int]),
73+
help=server_help)
6674
@click.option("--update", is_flag=True, callback=update_db,
6775
expose_value=False, is_eager=True)
6876
def run(port, like, use_json, server):
@@ -71,7 +79,11 @@ def run(port, like, use_json, server):
7179
raise click.UsageError("Please specify a port")
7280

7381
if server[0]:
74-
app.run(host=server[0], port=server[1])
82+
try:
83+
from whatportis.server import app
84+
app.run(host=server[0], port=server[1])
85+
except ImportError:
86+
click.echo("Dependencies are missing, please use `pip install whatportis[server]`.")
7587
return
7688

7789
ports = get_ports(port, like)

0 commit comments

Comments
 (0)