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
@@ -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()
@@ -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')
This conversation was marked as resolved by kmax12

This comment has been minimized.

Copy link
@gsheni

gsheni Apr 16, 2019

Author Contributor

Replace the underscore with a dash to be more consistent with other CLI tools.
pallets/click#1123 (comment)

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())
@@ -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()
@@ -0,0 +1,9 @@
import subprocess


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


def test_list_primitives():
subprocess.check_output(['featuretools', 'list-primitives'])
@@ -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,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
@@ -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():
This conversation was marked as resolved by gsheni

This comment has been minimized.

Copy link
@kmax12

kmax12 Apr 16, 2019

Member

can we add a test case that calls get_installed_packages and get_sys_info even if it doesn’t check the outputs? that would at least catch any runtime errors

This comment has been minimized.

Copy link
@gsheni

gsheni Apr 16, 2019

Author Contributor

Fixed.

"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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.