1
1
# -*- coding: utf-8 -*-
2
2
3
- from __future__ import absolute_import
4
-
5
3
import os
6
- import re
7
4
import 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
13
7
14
8
rootpath = os .path .abspath (os .path .dirname (__file__ ))
15
9
16
10
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
+
17
24
def read (* parts ):
18
- return codecs . open (os .path .join (rootpath , * parts ), 'r' ).read ()
25
+ return open (os .path .join (rootpath , * parts ), 'r' ).read ()
19
26
20
27
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
28
38
29
39
30
40
def walk_subpkg (name ):
@@ -47,20 +57,23 @@ def walk_subpkg(name):
47
57
'templates/*.js' ,
48
58
'templates/*.txt' ] + walk_subpkg ('templates/tiles' )}
49
59
pkgs = ['folium' ,
50
- 'folium.plugins' ,
51
- ]
60
+ 'folium.plugins' ]
52
61
53
62
LICENSE = read ('LICENSE.txt' )
54
- version = find_version ('folium' , '__init__.py' )
55
63
long_description = '{}\n {}' .format (read ('README.rst' ), read ('CHANGES.txt' ))
56
64
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
+
57
71
config = dict (name = 'folium' ,
58
- version = version ,
72
+ version = extract_version () ,
59
73
description = 'Make beautiful maps with Leaflet.js & Python' ,
60
74
long_description = long_description ,
61
75
author = 'Rob Story' ,
62
76
63
- license = 'MIT License' ,
64
77
url = 'https://github.com/python-visualization/folium' ,
65
78
keywords = 'data visualization' ,
66
79
classifiers = ['Development Status :: 4 - Beta' ,
@@ -70,16 +83,11 @@ def walk_subpkg(name):
70
83
'License :: OSI Approved :: MIT License' ],
71
84
packages = pkgs ,
72
85
package_data = pkg_data ,
86
+ cmdclass = dict (test = PyTest ),
87
+ tests_require = ['pytest' ],
88
+ license = LICENSE ,
89
+ install_requires = install_requires ,
73
90
zip_safe = False )
74
91
75
92
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
-
85
93
setup (** config )
0 commit comments