Skip to content

Commit

Permalink
Simplify/fix setup.py
Browse files Browse the repository at this point in the history
Fixes #613

Fixes #637
  • Loading branch information
akx committed Mar 17, 2020
1 parent f772f77 commit e1332ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 116 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include hyperopt *
118 changes: 2 additions & 116 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,122 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" distribute- and pip-enabled setup.py """

import logging
import os
import setuptools

# ----- overrides -----

# set these to anything but None to override the automatic defaults
packages = None
package_name = None
package_data = None
scripts = None
# ---------------------


# ----- control flags -----

# fallback to setuptools if distribute isn't found
setup_tools_fallback = True

# don't include subdir named 'tests' in package_data
skip_tests = False

# print some extra debugging info
debug = True

# -------------------------

if debug:
logging.basicConfig(level=logging.DEBUG)


def find_scripts():
return [
s for s in setuptools.findall("scripts/") if os.path.splitext(s)[1] != ".pyc"
]


def package_to_path(package):
"""
Convert a package (as found by setuptools.find_packages)
e.g. "foo.bar" to usable path
e.g. "foo/bar"
No idea if this works on windows
"""
return package.replace(".", "/")


def find_subdirectories(package):
"""
Get the subdirectories within a package
This will include resources (non-submodules) and submodules
"""
try:
subdirectories = next(os.walk(package_to_path(package)))[1]
except StopIteration:
subdirectories = []
return subdirectories


def subdir_findall(dir, subdir):
"""
Find all files in a subdirectory and return paths relative to dir
This is similar to (and uses) setuptools.findall
However, the paths returned are in the form needed for package_data
"""
strip_n = len(dir.split("/"))
path = "/".join((dir, subdir))
return ["/".join(s.split("/")[strip_n:]) for s in setuptools.findall(path)]


def find_package_data(packages):
"""
For a list of packages, find the package_data
This function scans the subdirectories of a package and considers all
non-submodule subdirectories as resources, including them in
the package_data
Returns a dictionary suitable for setup(package_data=<result>)
"""
package_data = {}
for package in packages:
package_data[package] = []
for subdir in find_subdirectories(package):
if ".".join((package, subdir)) in packages: # skip submodules
logging.debug("skipping submodule %s/%s" % (package, subdir))
continue
if skip_tests and (subdir == "tests"): # skip tests
logging.debug("skipping tests %s/%s" % (package, subdir))
continue
package_data[package] += subdir_findall(package_to_path(package), subdir)
return package_data


# ----------- Override defaults here ----------------
if packages is None:
packages = setuptools.find_packages()

if len(packages) == 0:
raise Exception("No valid packages found")

if package_name is None:
package_name = packages[0]

if package_data is None:
package_data = find_package_data(packages)


setuptools.setup(
name=package_name,
name="hyperopt",
version="0.2.3",
packages=packages,
packages=setuptools.find_packages(include=["hyperopt*"]),
entry_points={"console_scripts": ["hyperopt-mongo-worker=hyperopt.mongoexp:main"]},
url="http://hyperopt.github.com/hyperopt/",
author="James Bergstra",
Expand All @@ -143,7 +30,6 @@ def find_package_data(packages):
platforms=["Linux", "OS-X", "Windows"],
license="BSD",
keywords="Bayesian optimization hyperparameter model selection",
package_data=package_data,
include_package_data=True,
install_requires=[
"numpy",
Expand Down

0 comments on commit e1332ea

Please sign in to comment.