1
1
#!/usr/bin/env python
2
- # -*- encoding: utf-8 -*-
3
2
4
- from __future__ import absolute_import
5
- from __future__ import print_function
3
+ import setuptools
6
4
7
- import io
8
- from glob import glob
9
- from os .path import basename
10
- from os .path import dirname
11
- from os .path import join
12
- from os .path import splitext
13
- import re
14
- import sys
15
-
16
- from setuptools import find_packages
17
- from setuptools import setup
18
-
19
- version = '0.0.0'
20
-
21
- #### Small hack to force using a plain version number if the option
22
- #### --plain-version is passed to setup.py
23
-
24
- USE_DEFAULT_VERSION = False
25
- try :
26
- sys .argv .remove ('--use-default-version' )
27
- USE_DEFAULT_VERSION = True
28
- except ValueError :
29
- pass
30
- ####
31
-
32
-
33
- def get_version (default = version , template = '{tag}.{distance}.{commit}{dirty}' ,
34
- use_default = USE_DEFAULT_VERSION ):
35
- """
36
- Return a version collected from git if possible or fall back to an
37
- hard-coded default version otherwise. If `use_default` is True,
38
- always use the default version.
39
- """
40
- if use_default :
41
- return default
42
- try :
43
- tag , distance , commit , dirty = get_git_version ()
44
- if not distance and not dirty :
45
- # we are from a clean Git tag: use tag
46
- return tag
47
-
48
- distance = 'post{}' .format (distance )
49
- if dirty :
50
- time_stamp = get_time_stamp ()
51
- dirty = '.dirty.' + get_time_stamp ()
52
- else :
53
- dirty = ''
54
-
55
- return template .format (** locals ())
56
- except :
57
- # no git data: use default version
58
- return default
59
-
60
-
61
- def get_time_stamp ():
62
- """
63
- Return a numeric UTC time stamp without microseconds.
64
- """
65
- from datetime import datetime
66
- return (datetime .isoformat (datetime .utcnow ()).split ('.' )[0 ]
67
- .replace ('T' , '' ).replace (':' , '' ).replace ('-' , '' ))
68
-
69
-
70
- def get_git_version ():
71
- """
72
- Return version parts from Git or raise an exception.
73
- """
74
- from subprocess import check_output , STDOUT
75
- # this may fail with exceptions
76
- cmd = 'git' , 'describe' , '--tags' , '--long' , '--dirty' ,
77
- version = check_output (cmd , stderr = STDOUT ).strip ()
78
- dirty = version .endswith ('-dirty' )
79
- tag , distance , commit = version .split ('-' )[:3 ]
80
- # lower tag and strip V prefix in tags
81
- tag = tag .lower ().lstrip ('v ' ).strip ()
82
- # strip leading g from git describe commit
83
- commit = commit .lstrip ('g' ).strip ()
84
- return tag , int (distance ), commit , dirty
85
-
86
-
87
- def read (* names , ** kwargs ):
88
- return io .open (
89
- join (dirname (__file__ ), * names ),
90
- encoding = kwargs .get ('encoding' , 'utf8' )
91
- ).read ()
92
-
93
-
94
- setup (
95
- name = '' ,
96
- version = get_version (),
97
- license = 'Apache-2.0' ,
98
- description = '' ,
99
- long_description = read ('README.rst' ),
100
- author = 'nexB. Inc. and others' ,
101
-
102
- url = '' ,
103
- packages = find_packages ('src' ),
104
- package_dir = {'' : 'src' },
105
- py_modules = [splitext (basename (path ))[0 ] for path in glob ('src/*.py' )],
106
- include_package_data = True ,
107
- zip_safe = False ,
108
- classifiers = [
109
- # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
110
- 'Development Status :: 5 - Production/Stable' ,
111
- 'Intended Audience :: Developers' ,
112
- 'Programming Language :: Python' ,
113
- 'Programming Language :: Python :: 3' ,
114
- 'Programming Language :: Python :: 3.6' ,
115
- 'Programming Language :: Python :: 3.7' ,
116
- 'Programming Language :: Python :: 3.8' ,
117
- 'Topic :: Software Development' ,
118
- 'Topic :: Utilities' ,
119
- ],
120
- keywords = [
121
- ],
122
- install_requires = [
123
- ]
124
- )
5
+ if __name__ == "__main__" :
6
+ setuptools .setup ()
0 commit comments