11# -*- coding: utf-8 -*-
22
3- from __future__ import absolute_import
4-
53import os
6- import re
74import sys
8- import codecs
9- try :
10- from setuptools import setup
11- except ImportError :
12- from distutils .core import setup
5+ from setuptools import setup
6+ from setuptools .command .test import test as TestCommand
137
148rootpath = os .path .abspath (os .path .dirname (__file__ ))
159
1610
11+ class PyTest (TestCommand ):
12+ def finalize_options (self ):
13+ TestCommand .finalize_options (self )
14+ # FIXME: '--doctest-modules'
15+ self .test_args = ['--verbose' ]
16+ self .test_suite = True
17+
18+ def run_tests (self ):
19+ import pytest
20+ errno = pytest .main (self .test_args )
21+ sys .exit (errno )
22+
23+
1724def read (* parts ):
18- return codecs . open (os .path .join (rootpath , * parts ), 'r' ).read ()
25+ return open (os .path .join (rootpath , * parts ), 'r' ).read ()
1926
2027
21- def find_version (* file_paths ):
22- version_file = read (* file_paths )
23- version_match = re .search (r"^__version__ = ['\"]([^'\"]*)['\"]" ,
24- version_file , re .M )
25- if version_match :
26- return version_match .group (1 )
27- raise RuntimeError ("Unable to find version string." )
28+ def extract_version (module = 'folium' ):
29+ version = None
30+ fname = os .path .join (rootpath , module , '__init__.py' )
31+ with open (fname ) as f :
32+ for line in f :
33+ if (line .startswith ('__version__' )):
34+ _ , version = line .split ('=' )
35+ version = version .strip ()[1 :- 1 ] # Remove quotation characters.
36+ break
37+ return version
2838
2939
3040def walk_subpkg (name ):
@@ -47,20 +57,23 @@ def walk_subpkg(name):
4757 'templates/*.js' ,
4858 'templates/*.txt' ] + walk_subpkg ('templates/tiles' )}
4959pkgs = ['folium' ,
50- 'folium.plugins' ,
51- ]
60+ 'folium.plugins' ]
5261
5362LICENSE = read ('LICENSE.txt' )
54- version = find_version ('folium' , '__init__.py' )
5563long_description = '{}\n {}' .format (read ('README.rst' ), read ('CHANGES.txt' ))
5664
65+ # Dependencies.
66+ with open ('requirements.txt' ) as f :
67+ tests_require = f .readlines ()
68+ install_requires = [t .strip () for t in tests_require ]
69+
70+
5771config = dict (name = 'folium' ,
58- version = version ,
72+ version = extract_version () ,
5973 description = 'Make beautiful maps with Leaflet.js & Python' ,
6074 long_description = long_description ,
6175 author = 'Rob Story' ,
6276 author_email = 'wrobstory@gmail.com' ,
63- license = 'MIT License' ,
6477 url = 'https://github.com/python-visualization/folium' ,
6578 keywords = 'data visualization' ,
6679 classifiers = ['Development Status :: 4 - Beta' ,
@@ -70,16 +83,11 @@ def walk_subpkg(name):
7083 'License :: OSI Approved :: MIT License' ],
7184 packages = pkgs ,
7285 package_data = pkg_data ,
86+ cmdclass = dict (test = PyTest ),
87+ tests_require = ['pytest' ],
88+ license = LICENSE ,
89+ install_requires = install_requires ,
7390 zip_safe = False )
7491
7592
76- if sys .argv [- 1 ] == 'publish' :
77- os .system ("python setup.py sdist upload" )
78- print ("Remember to also tag the version." )
79- sys .exit ()
80- elif sys .argv [- 1 ] == 'tag' :
81- os .system ("git tag -a %s -m 'version %s'" % (version , version ))
82- os .system ("git push --tags" )
83- sys .exit ()
84-
8593setup (** config )
0 commit comments