Commit 4c1a43d1 authored by Jason R. Coombs's avatar Jason R. Coombs

Use with statement in setup.py

parent a37fa956
...@@ -13,17 +13,15 @@ from distutils.util import convert_path ...@@ -13,17 +13,15 @@ from distutils.util import convert_path
command_ns = {} command_ns = {}
init_path = convert_path('setuptools/command/__init__.py') init_path = convert_path('setuptools/command/__init__.py')
init_file = open(init_path) with open(init_path) as init_file:
exec(init_file.read(), command_ns) exec(init_file.read(), command_ns)
init_file.close()
SETUP_COMMANDS = command_ns['__all__'] SETUP_COMMANDS = command_ns['__all__']
main_ns = {} main_ns = {}
ver_path = convert_path('setuptools/version.py') ver_path = convert_path('setuptools/version.py')
ver_file = open(ver_path) with open(ver_path) as ver_file:
exec(ver_file.read(), main_ns) exec(ver_file.read(), main_ns)
ver_file.close()
import setuptools import setuptools
from setuptools.command.build_py import build_py as _build_py from setuptools.command.build_py import build_py as _build_py
...@@ -70,23 +68,17 @@ class test(_test): ...@@ -70,23 +68,17 @@ class test(_test):
_test.run(self) _test.run(self)
return # even though _test.run will raise SystemExit return # even though _test.run will raise SystemExit
f = open(entry_points) # save the content
with open(entry_points) as f:
# running the test
try:
ep_content = f.read() ep_content = f.read()
finally:
f.close()
# run the test
try: try:
_test.run(self) _test.run(self)
finally: finally:
# restoring the file # restore the file
f = open(entry_points, 'w') with open(entry_points, 'w') as f:
try:
f.write(ep_content) f.write(ep_content)
finally:
f.close()
readme_file = open('README.txt') readme_file = open('README.txt')
...@@ -96,9 +88,9 @@ if os.path.exists('CHANGES (links).txt'): ...@@ -96,9 +88,9 @@ if os.path.exists('CHANGES (links).txt'):
else: else:
# but if the release script has not run, fall back to the source file # but if the release script has not run, fall back to the source file
changes_file = open('CHANGES.txt') changes_file = open('CHANGES.txt')
long_description = readme_file.read() + '\n' + changes_file.read() with readme_file:
readme_file.close() with changes_file:
changes_file.close() long_description = readme_file.read() + '\n' + changes_file.read()
package_data = {'setuptools': ['site-patch.py']} package_data = {'setuptools': ['site-patch.py']}
if sys.platform == 'win32' or os.environ.get("SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES") not in (None, "", "0"): if sys.platform == 'win32' or os.environ.get("SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES") not in (None, "", "0"):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment