Skip to content

Commit

Permalink
better installation instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
gywn committed Nov 29, 2017
1 parent 4892c3e commit c78711c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ A Python3 library with CLI that generates the optimal discernible color palette

## Installation and Usage

git clone https://github.com/gywn/perception.git
cd perception && python3 setup.py install
pip3 install https://github.com/gywn/perception/archive/v0.0.2.tar.gz

Generate demo page

Expand Down
35 changes: 24 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
# -*- coding: utf-8 -*-

from distutils.version import LooseVersion
from functools import reduce
from glob import glob
from multiprocessing import cpu_count
from platform import system
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import glob
import multiprocessing
import os
import platform
import re
import subprocess
import sys


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])
def __init__(self, name, sourcedir='', **kwargs):
Extension.__init__(self, name, **kwargs)
self.sourcedir = os.path.abspath(sourcedir)


Expand All @@ -28,7 +29,7 @@ def run(self):
"CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))

if platform.system() == "Windows":
if system() == "Windows":
cmake_version = LooseVersion(
re.search(r'version\s*([\d.]+)', out.decode()).group(1))
if cmake_version < '3.1.0':
Expand All @@ -48,7 +49,7 @@ def build_extension(self, ext):
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]

if platform.system() == "Windows":
if system() == "Windows":
cmake_args += [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
cfg.upper(), extdir)
Expand All @@ -58,7 +59,7 @@ def build_extension(self, ext):
build_args += ['--', '/m']
else:
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
build_args += ['--', '-j{0}'.format(multiprocessing.cpu_count())]
build_args += ['--', '-j{0}'.format(cpu_count())]

if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
Expand All @@ -81,14 +82,26 @@ def build_extension(self, ext):
install_requires=['pystache'],
packages=['perception'],
package_dir={'perception': 'python'},
ext_modules=[CMakeExtension('perception.native')],
ext_modules=[
CMakeExtension(
'perception.native',
sources=[
f
for f in
reduce(lambda l, d: l + glob(f'{d}/**', recursive=True),
['cmake', 'include', 'src'], ['CMakeLists.txt'])
if os.path.isfile(f)
])
],
package_data={
'perception': [
os.path.relpath(p, 'python')
for p in glob.glob('python/data/**', recursive=True)
for p in glob('python/data/**', recursive=True)
]
},
entry_points={'console_scripts': [
'perception = perception.cli:main',
]},
cmdclass=dict(build_ext=CMakeBuild))
cmdclass=dict(build_ext=CMakeBuild),
url='https://github.com/gywn/perception',
download_url='https://github.com/gywn/perception/archive/v0.0.2.tar.gz')

0 comments on commit c78711c

Please sign in to comment.