Skip to content

Commit 61f5a86

Browse files
committed
1 parent d715478 commit 61f5a86

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include fastentrypoints.py

fastentrypoints.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright (c) 2016, Aaron Christianson
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are
6+
# met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in the
13+
# documentation and/or other materials provided with the distribution.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
'''
27+
Monkey patch setuptools to write faster console_scripts with this format:
28+
29+
import sys
30+
from mymodule import entry_function
31+
sys.exit(entry_function())
32+
33+
This is better.
34+
35+
(c) 2016, Aaron Christianson
36+
http://github.com/ninjaaron/fast-entry_points
37+
'''
38+
from setuptools.command import easy_install
39+
import re
40+
TEMPLATE = '''\
41+
# -*- coding: utf-8 -*-
42+
import re
43+
import sys
44+
45+
from {0} import {1}
46+
47+
if __name__ == '__main__':
48+
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
49+
sys.exit({2}())'''
50+
51+
52+
@classmethod
53+
def get_args(cls, dist, header=None):
54+
"""
55+
Yield write_script() argument tuples for a distribution's
56+
console_scripts and gui_scripts entry points.
57+
"""
58+
if header is None:
59+
header = cls.get_header()
60+
spec = str(dist.as_requirement())
61+
for type_ in 'console', 'gui':
62+
group = type_ + '_scripts'
63+
for name, ep in dist.get_entry_map(group).items():
64+
# ensure_safe_name
65+
if re.search(r'[\\/]', name):
66+
raise ValueError("Path separators not allowed in script names")
67+
script_text = TEMPLATE.format(
68+
ep.module_name, ep.attrs[0], '.'.join(ep.attrs))
69+
args = cls._get_script_args(type_, name, header, script_text)
70+
for res in args:
71+
yield res
72+
73+
74+
easy_install.ScriptWriter.get_args = get_args
75+
76+
77+
def main():
78+
import os
79+
import re
80+
import shutil
81+
import sys
82+
dests = sys.argv[1:] or ['.']
83+
filename = re.sub('\.pyc$', '.py', __file__)
84+
85+
for dst in dests:
86+
shutil.copy(filename, dst)
87+
manifest_path = os.path.join(dst, 'MANIFEST.in')
88+
setup_path = os.path.join(dst, 'setup.py')
89+
90+
# Insert the include statement to MANIFEST.in if not present
91+
with open(manifest_path, 'a+') as manifest:
92+
manifest.seek(0)
93+
manifest_content = manifest.read()
94+
if not 'include fastentrypoints.py' in manifest_content:
95+
manifest.write(('\n' if manifest_content else '')
96+
+ 'include fastentrypoints.py')
97+
98+
# Insert the import statement to setup.py if not present
99+
with open(setup_path, 'a+') as setup:
100+
setup.seek(0)
101+
setup_content = setup.read()
102+
if not 'import fastentrypoints' in setup_content:
103+
setup.seek(0)
104+
setup.truncate()
105+
setup.write('import fastentrypoints\n' + setup_content)
106+
107+
print(__name__)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fastentrypoints
12
# -*- coding: utf-8 -*-
23
from setuptools import find_packages, setup
34

0 commit comments

Comments
 (0)