Skip to content

Commit

Permalink
* Include bhtsne.py script (and tsne binaries) as part of the wheel.
Browse files Browse the repository at this point in the history
* Change package name to bh-tsne to avoid collision with existing pypi packages
  • Loading branch information
Daniel Rapp authored and Daniel Rapp committed Apr 4, 2017
1 parent b1aa277 commit 19563f2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
18 changes: 12 additions & 6 deletions bin/build-image
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
import argparse
import subprocess
import shlex
import os

def build(image):
return 'docker build -t tsne-{0} -f docker/{0}/Dockerfile .'.format(image)
def build(project, mode):
return 'docker build -t {project}-{mode} -f docker/{mode}/Dockerfile .'.format(project=project, mode=mode)

def clean(image):
return 'docker rmi tsne-{0}'.format(image)
def clean(project, mode):
return 'docker rmi {project}-{mode}'.format(project=project, mode=mode)

def get_default_project_name():
# return os.path.basename(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
return 'bh-tsne'

def image_operation(operation):
print('\n\n============================================================================')
Expand All @@ -27,7 +32,8 @@ def image_operation(operation):


if __name__ == '__main__':
image_types = ['prod', 'dev', 'jenkins']
docker_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'docker')
image_types = [x for x in os.listdir(docker_dir) if os.path.isdir(os.path.join(docker_dir, x))]
parser = argparse.ArgumentParser()
parser.add_argument("image", choices=['all', 'clean'] + image_types, help="image to build")
args = parser.parse_args()
Expand All @@ -43,4 +49,4 @@ if __name__ == '__main__':
images_to_build = [args.image]

for image in images_to_build:
image_operation(fn(image))
image_operation(fn(get_default_project_name(), image))
3 changes: 2 additions & 1 deletion bin/run-image
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def get_default_root():
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def get_default_project_name():
return os.path.basename(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
#return os.path.basename(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
return 'bh-tsne'

def run(mode, root=get_default_root(), project=get_default_project_name(), workdir='tsne', keep_container=False):
it = '-d' if keep_container else '-it'
Expand Down
4 changes: 3 additions & 1 deletion docker/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ RUN apt-get update && apt-get install -y \
WORKDIR /tsne

ADD dist .
#RUN pip install --no-index --find-links=/tsne tsne
RUN pip install --find-links=/tsne bh-tsne
VOLUME /data

42 changes: 23 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from setuptools import find_packages
from distutils.extension import Extension
from distutils.dir_util import copy_tree
from distutils.command.build_scripts import build_scripts

import versioneer
import numpy
Expand All @@ -24,17 +25,18 @@

class CmakeBuildMixin():
def cmake_build(self):
build_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), self.build_lib + '/cmake')
build_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), self.build_dir)
cmake_dir = os.path.join(build_dir, 'cmake')
source_dir = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tsne'), 'bh_sne_src')
if not os.path.exists(build_dir):
os.makedirs(build_dir)
if not os.path.exists(cmake_dir):
os.makedirs(cmake_dir)
else:
shutil.rmtree(build_dir)
os.makedirs(build_dir)
shutil.rmtree(cmake_dir)
os.makedirs(cmake_dir)

cwd = os.getcwd()
try:
os.chdir(build_dir)
os.chdir(cmake_dir)
return_val = os.system('cmake -DCMAKE_BUILD_TYPE=RELEASE ' + source_dir)

if return_val != 0:
Expand All @@ -43,24 +45,24 @@ def cmake_build(self):

os.system('make VERBOSE=1')
# delete any of the cmake generated files
shutil.rmtree(os.path.join(build_dir, 'CMakeFiles'))
os.remove(os.path.join(build_dir, 'CMakeCache.txt'))
os.remove(os.path.join(build_dir, 'Makefile'))
os.remove(os.path.join(build_dir, 'cmake_install.cmake'))
shutil.rmtree(os.path.join(cmake_dir, 'CMakeFiles'))
os.remove(os.path.join(cmake_dir, 'CMakeCache.txt'))
os.remove(os.path.join(cmake_dir, 'Makefile'))
os.remove(os.path.join(cmake_dir, 'cmake_install.cmake'))
# this leaves just the generated executables in the path.
# copy them into the tsne directory so that they will be picked
# copy them into base directory so that they will be picked
# up by the install_lib command during install, or bdist_wheel
dest_dir = os.path.join(os.path.dirname(build_dir), 'tsne')
copy_tree(build_dir, dest_dir)
copy_tree(cmake_dir, build_dir)
finally:
os.chdir(cwd)
shutil.rmtree(build_dir)
shutil.rmtree(cmake_dir)


class CmakeBuildExt(CmakeBuildMixin, build_ext):
class CmakeBuildScripts(CmakeBuildMixin, build_scripts):
def run(self):
build_ext.run(self)
self.cmake_build()
build_scripts.run(self)



if sys.platform == 'darwin':
Expand Down Expand Up @@ -107,9 +109,10 @@ def run(self):
ext_modules = cythonize(ext_modules)

cmdclass = versioneer.get_cmdclass()
cmdclass['build_ext'] = CmakeBuildExt # build_ext
cmdclass['build_ext'] = build_ext
cmdclass['build_scripts'] = CmakeBuildScripts

setup(name='tsne',
setup(name='bh-tsne',
version=versioneer.get_version(),
cmdclass=cmdclass,
author='Daniel Rapp',
Expand All @@ -124,8 +127,9 @@ def run(self):
license='Apache License Version 2.0, January 2004',
packages=find_packages(),
ext_modules=ext_modules,
scripts=['tsne/bh_sne_src/bhtsne.py'],
install_requires=[
'numpy',
'scipy'
]
]
)

0 comments on commit 19563f2

Please sign in to comment.