Ticket #4244: setup-4244.patch
| File setup-4244.patch, 6.3 KB (added by thijs, 10 months ago) |
|---|
-
twisted/python/test/test_dist.py
7 7 8 8 9 9 import os 10 import shutil11 10 import sys 12 11 13 12 from distutils.core import Distribution … … 15 14 from twisted.trial.unittest import TestCase 16 15 17 16 from twisted.python import dist 18 from twisted.python.dist import get_setup_args, ConditionalExtension 17 from twisted.python.dist import (get_setup_args, ConditionalExtension, 18 build_scripts_twisted) 19 19 from twisted.python.filepath import FilePath 20 20 21 21 22 22 23 class SetupTest(TestCase): 23 24 """ 24 25 Tests for L{get_setup_args}. … … 57 58 self.assertEqual(ext.define_macros, [("whatever", 2), ("WIN32", 1)]) 58 59 59 60 61 60 62 class GetExtensionsTest(TestCase): 61 63 """ 62 64 Tests for L{dist.getExtensions}. … … 195 197 self.assertEqual(dist.getVersion("blat", base=self.dirname), "9.8.10") 196 198 197 199 200 198 201 class GetScriptsTest(TestCase): 199 202 """ 200 203 Tests for L{dist.getScripts} which returns the scripts which should be … … 295 298 296 299 297 300 301 class DummyCommand: 302 """ 303 A fake Command. 304 """ 305 def __init__(self, **kwargs): 306 for kw, val in kwargs.items(): 307 setattr(self, kw, val) 308 309 def ensure_finalized(self): 310 pass 311 312 313 314 class BuildScriptsTest(TestCase): 315 """ 316 Tests for L{dist.build_scripts_twisted}. 317 """ 318 319 def setUp(self): 320 self.source = FilePath(self.mktemp()) 321 self.target = FilePath(self.mktemp()) 322 self.source.makedirs() 323 self.addCleanup(os.chdir, os.getcwd()) 324 os.chdir(self.source.path) 325 326 327 def test_notWindows(self): 328 """ 329 L{build_scripts_twisted} does not rename scripts on non-Windows 330 platforms. 331 """ 332 self.patch(os, "name", "twisted") 333 built = self.buildScripts() 334 for name in ['script1', 'script2.py', 'shell.sh']: 335 self.assertTrue(name in built) 336 337 338 def test_windows(self): 339 """ 340 L{build_scripts_twisted} renames scripts so they end with '.py' on 341 the Windows platform. 342 """ 343 self.patch(os, "name", "nt") 344 built = self.buildScripts() 345 for name in ['script1.py', 'script2.py', 'shell.sh.py']: 346 self.assertTrue(name in built) 347 348 349 def buildScripts(self): 350 """ 351 Writes 3 types of scripts and runs the L{build_scripts_twisted} 352 command. 353 """ 354 self.writeScript(self.source, "script1", 355 ("#! /usr/bin/env python2.3\n" 356 "# bogus script w/ Python sh-bang\n" 357 "pass\n")) 358 359 self.writeScript(self.source, "script2.py", 360 ("#!/usr/bin/python\n" 361 "# bogus script w/ Python sh-bang\n" 362 "pass\n")) 363 364 self.writeScript(self.source, "shell.sh", 365 ("#!/bin/sh\n" 366 "# bogus shell script w/ sh-bang\n" 367 "exit 0\n")) 368 369 expected = ['script1', 'script2.py', 'shell.sh'] 370 cmd = self.getBuildScriptsCmd(self.target, 371 [self.source.child(fn).path 372 for fn in expected]) 373 cmd.finalize_options() 374 cmd.run() 375 376 return self.target.listdir() 377 378 379 def getBuildScriptsCmd(self, target, scripts): 380 """ 381 Create a distribution with a dummy command and wrap it in 382 L{build_scripts_twisted}. 383 """ 384 dist = Distribution() 385 dist.scripts = scripts 386 dist.command_obj["build"] = DummyCommand( 387 build_scripts = target.path, 388 force = 1, 389 executable = sys.executable 390 ) 391 return build_scripts_twisted(dist) 392 393 394 def writeScript(self, dir, name, text): 395 """ 396 Write the script to disk. 397 """ 398 f = open(dir.child(name).path, "w") 399 try: 400 f.write(text) 401 finally: 402 f.close() 403 404 405 298 406 class FakeModule(object): 299 407 """ 300 408 A fake module, suitable for dependency injection in testing. … … 308 416 """ 309 417 self._attrs = attrs 310 418 419 311 420 def __getattr__(self, name): 312 421 """ 313 422 Gets an attribute of this fake module from its attrs. -
twisted/python/dist.py
1 # -*- test-case-name: twisted.python.test.test_dist -*- 2 # Copyright (c) Twisted Matrix Laboratories. 3 # See LICENSE for details. 4 1 5 """ 2 6 Distutils convenience functionality. 3 7 … … 282 286 ## Helpers and distutil tweaks 283 287 284 288 class build_scripts_twisted(build_scripts.build_scripts): 285 """Renames scripts so they end with '.py' on Windows.""" 286 289 """ 290 Renames scripts so they end with '.py' on Windows. 291 """ 287 292 def run(self): 288 293 build_scripts.build_scripts.run(self) 289 294 if not os.name == "nt": 290 295 return 291 296 for f in os.listdir(self.build_dir): 292 fpath =os.path.join(self.build_dir, f)297 fpath = os.path.join(self.build_dir, f) 293 298 if not fpath.endswith(".py"): 294 299 try: 295 300 os.unlink(fpath + ".py") 296 except EnvironmentError ,e:297 if e.args[1] =='No such file or directory':301 except EnvironmentError as e: 302 if e.args[1] == 'No such file or directory': 298 303 pass 299 304 os.rename(fpath, fpath + ".py") 300 305 -
setup.py
67 67 try: 68 68 list(parse_requirements(requirements)) 69 69 except: 70 print """You seem to be running a very old version of setuptools.70 print("""You seem to be running a very old version of setuptools. 71 71 This version of setuptools has a bug parsing dependencies, so automatic 72 72 dependency resolution is disabled. 73 """ 73 """) 74 74 else: 75 75 setup_args['install_requires'] = requirements 76 76 setup_args['include_package_data'] = True
