Skip to content

Commit 7ead0ec

Browse files
author
Eugene Scherba
committed
Merge pull request #1 from escherba/install_fix
drop cython install req
2 parents e9f8b94 + bdc4428 commit 7ead0ec

8 files changed

Lines changed: 4811 additions & 62 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ __pycache__/
44

55
# C extensions
66
*.so
7-
8-
# Cython intermediate
9-
src/metrohash.cpp
7+
*.zip
108

119
# Misc artifacts
1210
.DS_Store

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
include LICENSE
22
include README.rst
33
include include/*.h
4+
include src/*.cc
5+
include src/*.cpp
6+
include src/*.pyx
47
include *requirements.txt

README.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,30 @@ A Python wrapper around `MetroHash <https://github.com/jandrewrogers/MetroHash>`
1515
:target: https://circleci.com/gh/escherba/python-metrohash
1616
:alt: Tests Status
1717

18-
Installation
19-
------------
18+
Getting Started
19+
---------------
2020

21-
To get started, clone this repo and run ``make env`` or, alternatively,
22-
install it into your environment of choice (below). Note that you
23-
will need to have Cython installed before you install this package.
21+
To use this package in your program, simply enter
2422

2523
.. code-block:: bash
2624
27-
pip install -U cython
2825
pip install metrohash
2926
3027
28+
After that, you should be able to import the module and do things with it (see
29+
Example Usage below).
30+
31+
If you want to contribute to this package by developing, the included Makefile
32+
provides some useful commands to help you with that task:
33+
34+
.. code-block:: bash
35+
36+
git clone https://github.com/escherba/python-metrohash.git
37+
cd python-metrohash
38+
make env # creates a Python virtualenv
39+
make test # builds and runs C++ and Python tests
40+
41+
3142
Example Usage
3243
-------------
3344

python.mk

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ package: env build_ext
1919
release: env build_ext
2020
$(PYTHON) setup.py $(DISTRIBUTE) upload -r $(PYPI_HOST)
2121

22+
shell: extras build_ext
23+
$(PYENV) $(ENV_EXTRA) ipython
24+
2225
build_ext: $(EXTENSION)
2326
@echo "done building '$(EXTENSION)' extension"
2427

@@ -30,12 +33,13 @@ test: extras build_ext | test_cpp
3033
$(PYENV) py.test README.rst
3134

3235
nuke: clean
36+
rm -f $(EXTENSION_INTERMEDIATE)
3337
rm -rf *.egg *.egg-info env
3438

3539
clean: | clean_cpp
3640
python setup.py clean
3741
rm -rf dist build
38-
rm -f $(EXTENSION) $(EXTENSION_INTERMEDIATE)
42+
rm -f $(EXTENSION)
3943
find . -path ./env -prune -o -type f -name "*.pyc" -exec rm {} \;
4044

4145
develop:
@@ -49,10 +53,17 @@ env/make.extras: $(EXTRAS_REQS) | env
4953
$(PYENV) for req in $?; do pip install -r $$req; done
5054
touch $@
5155

56+
ifeq ($(PIP_SYSTEM_SITE_PACKAGES),1)
57+
VENV_OPTS="--system-site-packages"
58+
else
59+
VENV_OPTS="--no-site-packages"
60+
endif
61+
5262
env virtualenv: env/bin/activate
5363
env/bin/activate: setup.py
54-
test -f $@ || virtualenv --no-site-packages env
64+
test -f $@ || virtualenv $(VENV_OPTS) env
5565
$(PYENV) easy_install -U pip
56-
$(PIP) install -U wheel cython
66+
$(PYENV) curl https://bootstrap.pypa.io/ez_setup.py | python
67+
$(PIP) install -U setuptools distribute wheel cython
5768
$(PIP) install -e .
5869
touch $@

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
virtualenv
2+
setuptools
3+
distribute
4+
wheel
5+
cython

setup.py

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
from setuptools import setup, Extension
1+
from setuptools import setup
2+
from setuptools.extension import Extension
23
from setuptools.dist import Distribution
34
from pkg_resources import resource_string
4-
from Cython.Distutils import build_ext
5+
6+
7+
try:
8+
from Cython.Distutils import build_ext
9+
except ImportError:
10+
USE_CYTHON = False
11+
else:
12+
USE_CYTHON = True
513

614

715
class BinaryDistribution(Distribution):
@@ -14,40 +22,54 @@ def is_pure(self):
1422
return False
1523

1624

17-
class build_ext_subclass(build_ext):
18-
"""
19-
This class is an ugly hack to a problem that arises when one must force
20-
a compiler to use specific flags by adding to the environment somethiing
21-
like the following:
22-
23-
CXX="clang --some_flagA --some_flagB -I/usr/bin/include/mylibC"
24-
25-
(as opposed to setting CXXFLAGS). Distutils in that case will complain
26-
that it cannot run the entire command as given because it is not
27-
found as an executable (specific error message is: "unable to execute...
28-
... no such file or directory").
29-
30-
This subclass of ``build_ext`` will extract the compiler name from the
31-
command line and insert any remaining arguments right after it.
32-
"""
33-
def build_extensions(self):
34-
ccm = self.compiler.compiler
35-
if ' ' in ccm[0]:
36-
self.compiler.compiler = ccm[0].split(' ') + ccm[1:]
37-
cxx = self.compiler.compiler_cxx
38-
if ' ' in cxx[0]:
39-
self.compiler.compiler_cxx = cxx[0].split(' ') + cxx[1:]
40-
build_ext.build_extensions(self)
41-
42-
4325
CXXFLAGS = u"""
4426
-O3
4527
-msse4.2
4628
-Wno-unused-value
4729
-Wno-unused-function
4830
""".split()
4931

50-
VERSION = '0.0.12'
32+
33+
INCLUDE_DIRS = ['include']
34+
CXXHEADERS = [
35+
"include/metro.h",
36+
"include/metrohash.h",
37+
"include/metrohash128.h",
38+
"include/metrohash128crc.h",
39+
"include/metrohash64.h",
40+
"include/platform.h",
41+
]
42+
CXXSOURCES = [
43+
"src/metrohash64.cc",
44+
"src/metrohash128.cc",
45+
]
46+
47+
CMDCLASS = {}
48+
EXT_MODULES = []
49+
50+
if USE_CYTHON:
51+
EXT_MODULES.append(
52+
Extension(
53+
"metrohash",
54+
CXXSOURCES + ["src/metrohash.pyx"],
55+
depends=CXXHEADERS,
56+
language="c++",
57+
extra_compile_args=CXXFLAGS,
58+
include_dirs=INCLUDE_DIRS)
59+
)
60+
CMDCLASS['build_ext'] = build_ext
61+
else:
62+
EXT_MODULES.append(
63+
Extension(
64+
"metrohash",
65+
CXXSOURCES + ["src/metrohash.cpp"],
66+
depends=CXXHEADERS,
67+
language="c++",
68+
extra_compile_args=CXXFLAGS,
69+
include_dirs=INCLUDE_DIRS)
70+
)
71+
72+
VERSION = '0.0.13'
5173
URL = "https://github.com/escherba/python-metrohash"
5274

5375
setup(
@@ -59,27 +81,9 @@ def build_extensions(self):
5981
download_url=URL + "/tarball/master/" + VERSION,
6082
name='metrohash',
6183
license='MIT',
62-
cmdclass={'build_ext': build_ext_subclass},
6384
zip_safe=False,
64-
ext_modules=[Extension(
65-
"metrohash",
66-
[
67-
"src/metrohash64.cc",
68-
"src/metrohash128.cc",
69-
"src/metrohash.pyx"
70-
],
71-
depends=[
72-
"include/metro.h",
73-
"include/metrohash.h",
74-
"include/metrohash128.h",
75-
"include/metrohash128crc.h",
76-
"include/metrohash64.h",
77-
"include/platform.h"
78-
],
79-
language="c++",
80-
extra_compile_args=CXXFLAGS,
81-
include_dirs=['include'])
82-
],
85+
cmdclass=CMDCLASS,
86+
ext_modules=EXT_MODULES,
8387
keywords=['hash', 'hashing', 'metrohash', 'cityhash'],
8488
classifiers=[
8589
'Development Status :: 4 - Beta',

0 commit comments

Comments
 (0)