Skip to content

Commit

Permalink
Update project to use Cython
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Aug 7, 2018
1 parent 000e23b commit 0c6a549
Show file tree
Hide file tree
Showing 28 changed files with 138 additions and 49 deletions.
1 change: 1 addition & 0 deletions .appveyor_support/environments/dpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dependencies:
- python==3.6
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
- coveralls==1.3.0
1 change: 1 addition & 0 deletions .appveyor_support/environments/tst_py27.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .appveyor_support/environments/tst_py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .appveyor_support/environments/tst_py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .circleci/environments/dpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dependencies:
- python==3.6
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
- coveralls==1.3.0
1 change: 1 addition & 0 deletions .circleci/environments/tst_py27.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .circleci/environments/tst_py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .circleci/environments/tst_py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[run]
branch = True
source = pysharedmem
plugins = Cython.Coverage
[report]
exclude_lines =
# Include the no cover pragma as it needs to be listed explicitly when
# using exclude_lines.
# ( http://coverage.readthedocs.io/en/coverage-4.1/excluding.html#advanced-exclusion )
pragma: no cover

# Ignore coverage of code that requires the module to be executed.
if __name__ == .__main__.:

Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pysharedmem/_version.py export-subst
_version.py export-subst

*.bat text eol=crlf
*.sh text eol=lf
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ __pycache__/

# C extensions
*.so
src/pysharedmem.c
src/version.pxi

# Distribution / packaging
.Python
Expand Down
1 change: 1 addition & 0 deletions .travis_support/environments/dpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dependencies:
- python==3.6
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
- coveralls==1.3.0
1 change: 1 addition & 0 deletions .travis_support/environments/tst_py27.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .travis_support/environments/tst_py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
1 change: 1 addition & 0 deletions .travis_support/environments/tst_py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ channels:
dependencies:
- pip==18.0
- wheel==0.31.1
- cython==0.28.5
- coverage==4.5.1
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ recursive-exclude * *.py[co]

recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif

include pyproject.toml

include versioneer.py
include pysharedmem/_version.py
include _version.py
2 changes: 1 addition & 1 deletion pysharedmem/_version.py → _version.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_config():
cfg.style = "pep440"
cfg.tag_prefix = "v"
cfg.parentdir_prefix = "pysharedmem"
cfg.versionfile_source = "pysharedmem/_version.py"
cfg.versionfile_source = "_version.py"
cfg.verbose = False
return cfg

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To install pysharedmem, run this command in your terminal:
$ pip install pysharedmem
This is the preferred method to install pysharedmem, as it will always install the most recent stable release.
This is the preferred method to install pysharedmem, as it will always install the most recent stable release.

If you don't have `pip`_ installed, this `Python installation guide`_ can guide
you through the process.
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "cython"]
8 changes: 0 additions & 8 deletions pysharedmem/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion pysharedmem/core.py

This file was deleted.

2 changes: 2 additions & 0 deletions readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
conda:
file: environment_doc.yml
python:
setup_py_install: true
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versioneer]
VCS = git
style = pep440
versionfile_source = pysharedmem/_version.py
versionfile_build = pysharedmem/_version.py
versionfile_source = _version.py
versionfile_build = _version.py
tag_prefix = v
parentdir_prefix = pysharedmem

Expand Down
93 changes: 88 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,121 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import glob
import os
import sys

import setuptools
from setuptools import setup
from setuptools import setup, Extension

from distutils.sysconfig import get_config_var, get_python_inc

import versioneer

version = versioneer.get_version()

with open("README.rst") as readme_file:
readme = readme_file.read()

with open("HISTORY.rst") as history_file:
history = history_file.read()

requirements = [
setup_requirements = [
"Cython>=0.28.5",
]

install_requirements = [
# TODO: put package requirements here
]

test_requirements = [
# TODO: put package test requirements here
]

cmdclasses = dict()
cmdclasses.update(versioneer.get_cmdclass())

if not (({"develop", "test"} & set(sys.argv)) or
any([v.startswith("build") for v in sys.argv]) or
any([v.startswith("bdist") for v in sys.argv]) or
any([v.startswith("install") for v in sys.argv])):
setup_requirements = []
else:
with open("src/version.pxi", "w") as f:
f.writelines([
"__version__ = " + "\"" + str(version) + "\""
])


try:
i = sys.argv.index("test")
sys.argv = sys.argv[:i] + ["build_ext", "--inplace"] + sys.argv[i:]
except ValueError:
pass


include_dirs = [
os.path.dirname(get_python_inc()),
get_python_inc()
]
library_dirs = list(filter(
lambda v: v is not None,
[get_config_var("LIBDIR")]
))

headers = []
sources = glob.glob("src/*.pxd") + glob.glob("src/*.pyx")
libraries = []
define_macros = []
extra_compile_args = []
cython_directives = {}
cython_line_directives = {}


if "test" in sys.argv:
cython_directives["binding"] = True
cython_directives["embedsignature"] = True
cython_directives["profile"] = True
cython_directives["linetrace"] = True
define_macros += [
("CYTHON_PROFILE", 1),
("CYTHON_TRACE", 1),
("CYTHON_TRACE_NOGIL", 1),
]


ext_modules = [
Extension(
"pysharedmem",
sources=sources,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
language="c"
)
]
for em in ext_modules:
em.cython_directives = dict(cython_directives)
em.cython_line_directives = dict(cython_line_directives)


setup(
name="pysharedmem",
version=versioneer.get_version(),
version=version,
description="Code for using interprocess shared memory in Python",
long_description=readme + "\n\n" + history,
author="John Kirkham",
author_email="kirkhamj@janelia.hhmi.org",
url="https://github.com/jakirkham/pysharedmem",
cmdclass=versioneer.get_cmdclass(),
cmdclass=cmdclasses,
packages=setuptools.find_packages(exclude=["tests*"]),
include_package_data=True,
install_requires=requirements,
setup_requires=setup_requirements,
install_requires=install_requirements,
headers=headers,
ext_modules=ext_modules,
license="BSD 3-Clause",
zip_safe=False,
keywords="pysharedmem",
Expand Down
1 change: 1 addition & 0 deletions src/pysharedmem.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions src/pysharedmem.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cimport pysharedmem

include "version.pxi"
29 changes: 0 additions & 29 deletions tests/test_core.py

This file was deleted.

14 changes: 14 additions & 0 deletions tests/test_pysharedmem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import unittest


class TestImportTopLevel(unittest.TestCase):
def runTest(self):
try:
import pysharedmem
except ImportError:
self.fail("Unable to import `pysharedmem`.")

0 comments on commit 0c6a549

Please sign in to comment.