forked from dcramer/chardet
-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
executable file
·108 lines (93 loc) · 3.73 KB
/
setup.py
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
kw = {
'zip_safe' : False,
'packages' : ['charade'],
}
try:
from setuptools import setup
kw['entry_points'] = {
'console_scripts' : [
'charade = charade:charade_cli'
],
}
except ImportError:
from distutils.core import setup # NOQA
# patch distutils if it can't cope with the "classifiers" or "download_url"
# keywords (prior to python 2.3.0).
from distutils.dist import DistributionMetadata
if not hasattr(DistributionMetadata, 'classifiers'):
DistributionMetadata.classifiers = None
if not hasattr(DistributionMetadata, 'download_url'):
DistributionMetadata.download_url = None
# When installing the charade script, we want to make it executable on Windows.
# There are many ways to do this, but this seems to be the best. 'Borrowed'
# from: http://matthew-brett.github.io/pydagogue/installing_scripts.html
import os.path
try:
from distutils.command.install_scripts import install_scripts
BAT_FILE_TEMPLATE = r"""@echo off
set mypath=%~dp0
set pyscript="%mypath%{FNAME}"
set /p line1=<%pyscript%
if "%line1:~0,2%" == "#!" (goto :goodstart)
echo First line of %pyscript% does not start with "#!"
exit /b 1
:goodstart
set py_exe=%line1:~2%
call %py_exe% %pyscript% %*
"""
class WindowsScriptCompat(install_scripts):
"""
A class that ensures that executable scripts correctly install on
Windows.
"""
def run(self):
install_scripts.run(self) # Ugh, old-style classes.
if os.name == "nt":
for filepath in self.get_outputs():
# If we can find an executable in the shebang of a script
# file, make a batch file wrapper for it.
with open(filepath, 'rt') as f:
first_line = f.readline()
if not (first_line.startswith('#!') and
'python' in first_line.lower()):
continue
path, name = os.path.split(filepath)
froot, extension = os.path.splitext(name)
bat_file = os.path.join(path, froot + '.bat')
bat_contents = BAT_FILE_TEMPLATE.replace('{FNAME}', name)
if not self.dry_run:
with open(bat_file, 'wt') as out:
out.write(bat_contents)
return
kw["script"] = ['bin/charade']
cmdclass={'install_scripts': WindowsScriptCompat},
except ImportError:
# Uh...let's just hope the user isn't on Windows!
pass
from charade import __version__
setup(
name='charade',
version=__version__,
description='Universal encoding detector for python 2 and 3',
long_description='\n\n'.join([open('README.rst').read(),
open('HISTORY.rst').read()]),
author='Mark Pilgrim',
author_email='[email protected]',
maintainer='Ian Cordasco',
maintainer_email='[email protected]',
url='https://github.com/sigmavirus24/charade',
license="LGPL",
keywords=['encoding', 'i18n', 'xml'],
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Library or Lesser General Public"
" License (LGPL)",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Linguistic",
],
**kw
)