def test_empty_package_dir (self): # See SF 1668596/1720897. cwd = os.getcwd() # create the distribution files. sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) old_stdout = sys.stdout sys.stdout = StringIO.StringIO() try: dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''") finally: # Restore state. os.chdir(cwd) sys.stdout = old_stdout
def test_empty_package_dir(self): cwd = os.getcwd() sources = self.mkdtemp() open(os.path.join(sources, '__init__.py'), 'w').close() testdir = os.path.join(sources, 'doc') os.mkdir(testdir) open(os.path.join(testdir, 'testfile'), 'w').close() os.chdir(sources) old_stdout = sys.stdout sys.stdout = StringIO.StringIO() try: dist = Distribution({'packages': ['pkg'], 'package_dir': {'pkg': ''}, 'package_data': {'pkg': ['doc/*']}}) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''") finally: os.chdir(cwd) sys.stdout = old_stdout
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ sources = self.mkdtemp() pkg_dir = os.path.join(sources, 'pkg') os.mkdir(pkg_dir) open(os.path.join(pkg_dir, '__init__.py'), 'w').close() docdir = os.path.join(pkg_dir, 'doc') os.mkdir(docdir) open(os.path.join(docdir, 'testfile'), 'w').close() os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({ 'packages': ['pkg'], 'package_data': { 'pkg': ['doc/*'] } }) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail('failed package_data when data dir includes a dir')
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ # See bug 19286 sources = self.mkdtemp() pkg_dir = os.path.join(sources, "pkg") os.mkdir(pkg_dir) open(os.path.join(pkg_dir, "__init__.py"), "w").close() docdir = os.path.join(pkg_dir, "doc") os.mkdir(docdir) open(os.path.join(docdir, "testfile"), "w").close() # create the directory that could be incorrectly detected as a file os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data when data dir includes a dir")
def test_empty_package_dir(self): cwd = os.getcwd() sources = self.mkdtemp() open(os.path.join(sources, '__init__.py'), 'w').close() testdir = os.path.join(sources, 'doc') os.mkdir(testdir) open(os.path.join(testdir, 'testfile'), 'w').close() os.chdir(sources) old_stdout = sys.stdout sys.stdout = StringIO.StringIO() try: dist = Distribution({ 'packages': ['pkg'], 'package_dir': { 'pkg': '' }, 'package_data': { 'pkg': ['doc/*'] } }) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''") finally: os.chdir(cwd) sys.stdout = old_stdout
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({ "packages": ["pkg"], "package_dir": { "pkg": "" }, "package_data": { "pkg": ["doc/*"] } }) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ # See bug 19286 sources = self.mkdtemp() pkg_dir = os.path.join(sources, "pkg") os.mkdir(pkg_dir) open(os.path.join(pkg_dir, "__init__.py"), "w").close() docdir = os.path.join(pkg_dir, "doc") os.mkdir(docdir) open(os.path.join(docdir, "testfile"), "w").close() # create the directory that could be incorrectly detected as a file os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({ "packages": ["pkg"], "package_data": { "pkg": ["doc/*"] } }) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data when data dir includes a dir")
def BuildExtension(sources, output_dir, extension_name): from distutils import log from distutils.core import Distribution, Extension import os import tempfile build_dir = tempfile.mkdtemp() # Source file paths must be relative to current path. cwd = os.getcwd() src_files = [os.path.relpath(filename, cwd) for filename in sources] ext = Extension(extension_name, src_files) if os.name == 'nt': _FixDistutilsMsvcCompiler() # VS 2010 does not generate manifest, see http://bugs.python.org/issue4431 ext.extra_link_args = ['/MANIFEST'] dist = Distribution({ 'ext_modules': [ext] }) dist.script_args = ['build_ext', '--build-temp', build_dir, '--build-lib', output_dir] dist.parse_command_line() log.set_threshold(log.DEBUG) dist.run_commands() dist.script_args = ['clean', '--build-temp', build_dir, '--all'] dist.parse_command_line() log.set_threshold(log.DEBUG) dist.run_commands()
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ sources = self.mkdtemp() pkg_dir = os.path.join(sources, 'pkg') os.mkdir(pkg_dir) open(os.path.join(pkg_dir, '__init__.py'), 'w').close() docdir = os.path.join(pkg_dir, 'doc') os.mkdir(docdir) open(os.path.join(docdir, 'testfile'), 'w').close() os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({'packages': ['pkg'], 'package_data': {'pkg': ['doc/*']}}) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail('failed package_data when data dir includes a dir')
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")