Skip to content
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

Add CLI entrypoint #493

Merged
merged 12 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
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
39 changes: 38 additions & 1 deletion featuretools/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import click
import pandas as pd
import pkg_resources

import featuretools
from featuretools.primitives.utils import get_featuretools_root
from featuretools.utils import get_installed_packages, get_sys_info


@click.group()
Expand All @@ -14,9 +16,36 @@ def cli():
def info():
print("Featuretools version: %s" % featuretools.__version__)
print("Featuretools installation directory: %s" % get_featuretools_root())
print("\nSYSTEM INFO")
print("-----------")
sys_info = get_sys_info()
for k, stat in sys_info:
print("{k}: {stat}".format(k=k, stat=stat))

print("\nINSTALLED VERSIONS")
print("------------------")
installed_packages = get_installed_packages()
deps = [
("numpy", installed_packages['numpy']),
("pandas", installed_packages['pandas']),
("tqdm", installed_packages['tqdm']),
("toolz", installed_packages['toolz']),
("PyYAML", installed_packages['PyYAML']),
("cloudpickle", installed_packages['cloudpickle']),
("future", installed_packages['future']),
("dask", installed_packages['dask']),
("distributed", installed_packages['distributed']),
("psutil", installed_packages['psutil']),
("Click", installed_packages['Click']),
("scikit-learn", installed_packages['scikit-learn']),
("pip", installed_packages['pip']),
("setuptools", installed_packages['setuptools']),
]
for k, stat in deps:
print("{k}: {stat}".format(k=k, stat=stat))

@click.command()

@click.command(name='list-primitives')
def list_primitives():
with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'display.max_colwidth', -1, 'display.width', 1000):
print(featuretools.list_primitives())
Expand All @@ -25,6 +54,14 @@ def list_primitives():
cli.add_command(list_primitives)
cli.add_command(info)

for entry_point in pkg_resources.iter_entry_points('featuretools_cli'):
try:
loaded = entry_point.load()
if hasattr(loaded, 'commands'):
for name, cmd in loaded.commands.items():
cli.add_command(cmd=cmd, name=name)
except Exception:
pass

if __name__ == "__main__":
cli()
9 changes: 9 additions & 0 deletions featuretools/tests/cli_tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import subprocess


def test_info():
subprocess.check_output(['featuretools', 'info'])


def test_list_primitives():
subprocess.check_output(['featuretools', 'list-primitives'])
19 changes: 19 additions & 0 deletions featuretools/tests/utils_tests/test_cli_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from featuretools.utils import get_installed_packages, get_sys_info


def test_sys_info():
sys_info = get_sys_info()
info_keys = ["python", "python-bits", "OS",
"OS-release", "machine", "processor",
"byteorder", "LC_ALL", "LANG", "LOCALE"]
found_keys = [k for k, _ in sys_info]
assert set(info_keys).issubset(found_keys)


def test_installed_packages():
installed_packages = get_installed_packages()
requirements = ["pandas", "numpy", "tqdm", "toolz",
"PyYAML", "cloudpickle", "future",
"dask", "distributed", "psutil",
"Click", "scikit-learn"]
assert set(requirements).issubset(installed_packages.keys())
1 change: 1 addition & 0 deletions featuretools/utils/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: noqa
from .cli_utils import get_installed_packages, get_sys_info
from .entry_point import entry_point
from .gen_utils import is_string, make_tqdm_iterator
from .pickle_utils import load_features, save_features
Expand Down
42 changes: 42 additions & 0 deletions featuretools/utils/cli_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import locale
import os
import platform
import struct
import sys

import pkg_resources


# Modified from here
# https://github.com/pandas-dev/pandas/blob/d9a037ec4ad0aab0f5bf2ad18a30554c38299e57/pandas/util/_print_versions.py#L11
def get_sys_info():
"Returns system information as a dict"

blob = []

try:
(sysname, nodename, release,
version, machine, processor) = platform.uname()
blob.extend([
("python", '.'.join(map(str, sys.version_info))),
("python-bits", struct.calcsize("P") * 8),
("OS", "{sysname}".format(sysname=sysname)),
("OS-release", "{release}".format(release=release)),
("machine", "{machine}".format(machine=machine)),
("processor", "{processor}".format(processor=processor)),
("byteorder", "{byteorder}".format(byteorder=sys.byteorder)),
("LC_ALL", "{lc}".format(lc=os.environ.get('LC_ALL', "None"))),
("LANG", "{lang}".format(lang=os.environ.get('LANG', "None"))),
("LOCALE", '.'.join(map(str, locale.getlocale()))),
])
except (KeyError, ValueError):
pass

return blob


def get_installed_packages():
installed_packages = {}
for d in pkg_resources.working_set:
installed_packages[d.project_name] = d.version
return installed_packages