1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
"""
intervaltree: A mutable, self-balancing interval tree for Python 2 and 3.
Queries may be by point, by range overlap, or by range envelopment.
Distribution logic
Note that "python setup.py test" invokes pytest on the package. With appropriately
configured setup.cfg, this will check both xxx_test modules and docstrings.
Copyright 2013-2015 Chaim-Leib Halbert
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import errno
import sys
import subprocess
from warnings import warn
from setuptools import setup
from setuptools.command.test import test as TestCommand
import re
## CONFIG
target_version = '2.1.0'
create_rst = True
def development_version_number():
p = subprocess.Popen('git describe'.split(), stdout=subprocess.PIPE)
git_describe = p.communicate()[0].strip()
release, build, commitish = git_describe.split('-')
result = "{0}b{1}".format(release, build)
return result
is_dev_version = 'PYPI' in os.environ and os.environ['PYPI'] == 'pypitest'
if is_dev_version:
version = development_version_number()
else: # This is a RELEASE version
version = target_version
print("Version: " + version)
if is_dev_version:
print("This is a DEV version.")
print("Target: " + target_version)
## Filesystem utilities
def read_file(path):
"""Reads file into string."""
with open(path, 'r') as f:
data = f.read()
return data
def mkdir_p(path):
"""Like `mkdir -p` in unix"""
if not path.strip():
return
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def rm_f(path):
"""Like `rm -f` in unix"""
try:
os.unlink(path)
except OSError as e:
if e.errno == errno.ENOENT:
pass
else:
raise
def update_file(path, data):
"""Writes data to path, creating path if it doesn't exist"""
# delete file if already exists
rm_f(path)
# create parent dirs if needed
parent_dir = os.path.dirname(path)
if not os.path.isdir(os.path.dirname(parent_dir)):
mkdir_p(parent_dir)
# write file
with open(path, 'w') as f:
f.write(data)
## PyTest
# This is a plug-in for setuptools that will invoke py.test
# when you run python setup.py test
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import pytest # import here, because outside the required eggs aren't loaded yet
sys.exit(pytest.main(self.test_args))
def get_rst():
if os.path.isdir('pyandoc/pandoc') and os.path.islink('pandoc'):
print("Generating README.rst from README.md and CHANGELOG.md")
return generate_rst()
elif os.path.isfile('README.rst'):
print("Reading README.rst")
return read_file('README.rst')
else:
warn("No README.rst found!")
print("Reading README.md")
data = ''.join([
read_file('README.md'),
'\n',
read_file('CHANGELOG.md'),
])
return data
## Convert README to rst for PyPI
def generate_rst():
"""Converts Markdown to RST for PyPI"""
md = read_file("README.md")
md = pypi_sanitize_markdown(md)
rst = markdown2rst(md)
rst = pypi_prepare_rst(rst)
changes_md = pypi_sanitize_markdown(read_file("CHANGELOG.md"))
changes_rst = markdown2rst(changes_md)
rst += "\n" + changes_rst
# Write it
if create_rst:
update_file('README.rst', rst)
else:
rm_f('README.rst')
return rst
def markdown2rst(md):
"""Convert markdown to rst format using pandoc. No other processing."""
# import here, because outside it might not used
try:
import pandoc
except ImportError as e:
raise
else:
pandoc.PANDOC_PATH = 'pandoc' # until pyandoc gets updated
doc = pandoc.Document()
doc.markdown_github = md
rst = doc.rst
return rst
## Sanitizers
def pypi_sanitize_markdown(md):
"""Prepare markdown for conversion to PyPI rst"""
md = chop_markdown_header(md)
md = remove_markdown_links(md)
return md
def pypi_prepare_rst(rst):
"""Add a notice that the rst was auto-generated"""
head = """\
.. This file is automatically generated by setup.py from README.md and CHANGELOG.md.
"""
rst = head + rst
return rst
def chop_markdown_header(md):
"""
Remove empty lines and travis-ci header from markdown string.
:param md: input markdown string
:type md: str
:return: simplified markdown string data
:rtype: str
"""
md = md.splitlines()
while not md[0].strip() or md[0].startswith('[!['):
md = md[1:]
md = '\n'.join(md)
return md
def remove_markdown_links(md):
"""PyPI doesn't like links, so we remove them."""
# named links, e.g. [hello][url to hello] or [hello][]
md = re.sub(
r'\[((?:[^\]]|\\\])+)\]' # link text
r'\[((?:[^\]]|\\\])*)\]', # link name
'\\1',
md
)
# url links, e.g. [example.com](http://www.example.com)
md = re.sub(
r'\[((?:[^\]]|\\\])+)\]' # link text
r'\(((?:[^\]]|\\\])*)\)', # link url
'\\1',
md
)
return md
## Run setuptools
setup(
name='intervaltree',
version=version,
install_requires=['sortedcontainers'],
description='Editable interval tree data structure for Python 2 and 3',
long_description=get_rst(),
classifiers=[ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'License :: OSI Approved :: Apache Software License',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Software Development :: Libraries',
'Topic :: Text Processing :: General',
'Topic :: Text Processing :: Linguistic',
'Topic :: Text Processing :: Markup',
],
keywords="interval-tree data-structure intervals tree", # Separate with spaces
author='Chaim-Leib Halbert, Konstantin Tretyakov',
author_email='chaim.leib.halbert@gmail.com',
url='https://github.com/chaimleib/intervaltree',
download_url='https://github.com/chaimleib/intervaltree/tarball/' + version,
license="Apache License, Version 2.0",
packages=["intervaltree"],
include_package_data=True,
zip_safe=True,
tests_require=['pytest'],
cmdclass={'test': PyTest},
entry_points={}
)
|