def test_defaults_case_sensitivity(self): """ Make sure default files (README.*, etc.) are added in a case-sensitive way to avoid problems with packages built on Windows. """ open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close() dist = Distribution(SETUP_ATTRS) # the extension deliberately capitalized for this test # to make sure the actual filename (not capitalized) gets added # to the manifest dist.script_name = 'setup.PY' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() # lowercase all names so we can test in a case-insensitive way to make sure the files are not included manifest = map(lambda x: x.lower(), cmd.filelist.files) self.assertFalse('readme.rst' in manifest, manifest) self.assertFalse('setup.py' in manifest, manifest) self.assertFalse('setup.cfg' in manifest, manifest)
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() filename = os.path.join(b'sdist_test', Filenames.utf_8) open(filename, 'w').close() with quiet(): cmd.run() if sys.platform == 'darwin': filename = decompose(filename) if six.PY3: fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': if fs_enc == 'cp1252': # Python 3 mangles the UTF-8 filename filename = filename.decode('cp1252') assert filename in cmd.filelist.files else: filename = filename.decode('mbcs') assert filename in cmd.filelist.files else: filename = filename.decode('utf-8') assert filename in cmd.filelist.files else: assert filename in cmd.filelist.files
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = "setup.py" cmd = sdist(dist) cmd.ensure_finalized() # UTF-8 filename filename = os.path.join(b("sdist_test"), b("smörbröd.py")) open(filename, "w").close() with quiet(): cmd.run() if sys.platform == "darwin": filename = decompose(filename) if six.PY3: fs_enc = sys.getfilesystemencoding() if sys.platform == "win32": if fs_enc == "cp1252": # Python 3 mangles the UTF-8 filename filename = filename.decode("cp1252") assert filename in cmd.filelist.files else: filename = filename.decode("mbcs") assert filename in cmd.filelist.files else: filename = filename.decode("utf-8") assert filename in cmd.filelist.files else: assert filename in cmd.filelist.files
def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = "setup.py" cmd = sdist(dist) cmd.ensure_finalized() # Create manifest with quiet(): cmd.run() # Add Latin-1 filename to manifest filename = os.path.join(b("sdist_test"), LATIN1_FILENAME) cmd.manifest = os.path.join("sdist_test.egg-info", "SOURCES.txt") manifest = open(cmd.manifest, "ab") manifest.write(b("\n") + filename) manifest.close() # The file must exist to be included in the filelist open(filename, "w").close() # Re-read manifest cmd.filelist.files = [] with quiet(): cmd.read_manifest() # The Latin-1 filename should have been skipped filename = filename.decode("latin-1") assert filename not in cmd.filelist.files
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() quiet() try: cmd.run() finally: unquiet() if sys.version_info >= (3,): filename = filename.decode('latin-1') if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped self.assertFalse(filename in cmd.filelist.files) else: # No conversion takes place under Python 2 and the file # is included. We shall keep it that way for BBB. self.assertTrue(filename in cmd.filelist.files)
def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Create manifest with quiet(): cmd.run() # Add Latin-1 filename to manifest filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b('\n') + filename) manifest.close() # The file must exist to be included in the filelist open(filename, 'w').close() # Re-read manifest cmd.filelist.files = [] with quiet(): try: cmd.read_manifest() except UnicodeDecodeError: e = sys.exc_info()[1] self.fail(e) # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files)
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = "setup.py" cmd = sdist(dist) cmd.ensure_finalized() # UTF-8 filename filename = os.path.join(b("sdist_test"), b("smörbröd.py")) open(filename, "w").close() quiet() try: cmd.run() finally: unquiet() if sys.platform == "darwin": filename = decompose(filename) if sys.version_info >= (3,): if sys.platform == "win32": # Python 3 mangles the UTF-8 filename filename = filename.decode("cp1252") self.assertTrue(filename in cmd.filelist.files) else: filename = filename.decode("utf-8") self.assertTrue(filename in cmd.filelist.files) else: self.assertTrue(filename in cmd.filelist.files)
def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Create manifest with quiet(): cmd.run() # Add Latin-1 filename to manifest filename = os.path.join(b'sdist_test', Filenames.latin_1) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b'\n' + filename) manifest.close() # The file must exist to be included in the filelist open(filename, 'w').close() # Re-read manifest cmd.filelist.files = [] with quiet(): cmd.read_manifest() # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') assert filename not in cmd.filelist.files
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # UTF-8 filename filename = os.path.join(b('sdist_test'), b('smörbröd.py')) open(filename, 'w').close() with quiet(): cmd.run() if sys.platform == 'darwin': filename = decompose(filename) if PY3: fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': if fs_enc == 'cp1252': # Python 3 mangles the UTF-8 filename filename = filename.decode('cp1252') self.assertTrue(filename in cmd.filelist.files) else: filename = filename.decode('mbcs') self.assertTrue(filename in cmd.filelist.files) else: filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) else: self.assertTrue(filename in cmd.filelist.files)
def test_manifest_is_read_with_surrogateescape_error_handler(self): # Test for #303. # This is hard to test on HFS Plus because it quotes unknown # bytes (see previous test). Furthermore, egg_info.FileList # only appends filenames that os.path.exist. # We therefore write the manifest file by hand and check whether # read_manifest produces a UnicodeDecodeError. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) quiet() try: cmd.run() # Add Latin-1 filename to manifest cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(filename+b('\n')) manifest.close() # Re-read manifest try: cmd.read_manifest() except UnicodeDecodeError, e: self.fail(e) finally: unquiet()
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(self.make_strings(SETUP_ATTRS)) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b'sdist_test', Filenames.latin_1) open(filename, 'w').close() assert os.path.isfile(filename) with quiet(): cmd.run() # not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however # on mbcs filesys it is not in latin-1 encoding fs_enc = sys.getfilesystemencoding() if fs_enc != 'mbcs': fs_enc = 'latin-1' filename = filename.decode(fs_enc) assert filename in cmd.filelist.files else: # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') filename not in cmd.filelist.files
def run(self): dist_options["version"] = self.get_version() dist = Distribution(dist_options) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() cmd.run()
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(self.make_strings(SETUP_ATTRS)) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() filename = os.path.join(b'sdist_test', Filenames.utf_8) open(filename, 'w').close() with quiet(): cmd.run() if sys.platform == 'darwin': filename = decompose(filename) fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': if fs_enc == 'cp1252': # Python mangles the UTF-8 filename filename = filename.decode('cp1252') assert filename in cmd.filelist.files else: filename = filename.decode('mbcs') assert filename in cmd.filelist.files else: filename = filename.decode('utf-8') assert filename in cmd.filelist.files
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # UTF-8 filename filename = os.path.join(b('sdist_test'), b('smörbröd.py')) open(filename, 'w').close() quiet() try: cmd.run() finally: unquiet() if sys.platform == 'darwin': filename = decompose(filename) if sys.version_info >= (3,): if sys.platform == 'win32': # Python 3 mangles the UTF-8 filename filename = filename.decode('cp1252') self.assertTrue(filename in cmd.filelist.files) else: filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) else: self.assertTrue(filename in cmd.filelist.files)
def test_defaults_case_sensitivity(self, tmpdir): """ Make sure default files (README.*, etc.) are added in a case-sensitive way to avoid problems with packages built on Windows. """ touch(tmpdir / 'readme.rst') touch(tmpdir / 'SETUP.cfg') dist = Distribution(SETUP_ATTRS) # the extension deliberately capitalized for this test # to make sure the actual filename (not capitalized) gets added # to the manifest dist.script_name = 'setup.PY' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() # lowercase all names so we can test in a # case-insensitive way to make sure the files # are not included. manifest = map(lambda x: x.lower(), cmd.filelist.files) assert 'readme.rst' not in manifest, manifest assert 'setup.py' not in manifest, manifest assert 'setup.cfg' not in manifest, manifest
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() quiet() try: cmd.run() finally: unquiet() if sys.version_info >= (3, ): filename = filename.decode('latin-1') if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped self.assertFalse(filename in cmd.filelist.files) else: # No conversion takes place under Python 2 and the file # is included. We shall keep it that way for BBB. self.assertTrue(filename in cmd.filelist.files)
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Create manifest with quiet(): cmd.run() # Add UTF-8 filename to manifest filename = os.path.join(b'sdist_test', Filenames.utf_8) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b'\n' + filename) manifest.close() # The file must exist to be included in the filelist open(filename, 'w').close() # Re-read manifest cmd.filelist.files = [] with quiet(): cmd.read_manifest() # The filelist should contain the UTF-8 filename filename = filename.decode('utf-8') assert filename in cmd.filelist.files
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = "setup.py" cmd = sdist(dist) cmd.ensure_finalized() # Create manifest with quiet(): cmd.run() # Add UTF-8 filename to manifest filename = os.path.join(b("sdist_test"), b("smörbröd.py")) cmd.manifest = os.path.join("sdist_test.egg-info", "SOURCES.txt") manifest = open(cmd.manifest, "ab") manifest.write(b("\n") + filename) manifest.close() # The file must exist to be included in the filelist open(filename, "w").close() # Re-read manifest cmd.filelist.files = [] with quiet(): cmd.read_manifest() # The filelist should contain the UTF-8 filename if six.PY3: filename = filename.decode("utf-8") assert filename in cmd.filelist.files
def test_defaults_case_sensitivity(self): """ Make sure default files (README.*, etc.) are added in a case-sensitive way to avoid problems with packages built on Windows. """ open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close() dist = Distribution(SETUP_ATTRS) # the extension deliberately capitalized for this test # to make sure the actual filename (not capitalized) gets added # to the manifest dist.script_name = 'setup.PY' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() # lowercase all names so we can test in a # case-insensitive way to make sure the files # are not included. manifest = map(lambda x: x.lower(), cmd.filelist.files) assert 'readme.rst' not in manifest, manifest assert 'setup.py' not in manifest, manifest assert 'setup.cfg' not in manifest, manifest
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Create manifest with quiet(): cmd.run() # Add UTF-8 filename to manifest filename = os.path.join(b'sdist_test', Filenames.utf_8) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b'\n' + filename) manifest.close() # The file must exist to be included in the filelist open(filename, 'w').close() # Re-read manifest cmd.filelist.files = [] with quiet(): cmd.read_manifest() # The filelist should contain the UTF-8 filename if six.PY3: filename = filename.decode('utf-8') assert filename in cmd.filelist.files
def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # UTF-8 filename filename = os.path.join(b('sdist_test'), b('smörbröd.py')) open(filename, 'w').close()
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close()
def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in package_data are included in the manifest even if they're not added to version control. """ dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized()
def test_setup_py_exists(self): dist = Distribution(SETUP_ATTRS) dist.script_name = 'foo.py' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() manifest = cmd.filelist.files assert 'setup.py' in manifest
def test_setup_py_missing(self): dist = Distribution(SETUP_ATTRS) dist.script_name = 'foo.py' cmd = sdist(dist) cmd.ensure_finalized() if os.path.exists("setup.py"): os.remove("setup.py") with quiet(): cmd.run() manifest = cmd.filelist.files assert 'setup.py' not in manifest
def test_pyproject_toml_in_sdist(self, tmpdir): """ Check if pyproject.toml is included in source distribution if present """ touch(tmpdir / 'pyproject.toml') dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() manifest = cmd.filelist.files assert 'pyproject.toml' in manifest
def test_setup_py_excluded(self): with open("MANIFEST.in", "w") as manifest_file: manifest_file.write("exclude setup.py") dist = Distribution(SETUP_ATTRS) dist.script_name = 'foo.py' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() manifest = cmd.filelist.files assert 'setup.py' not in manifest
def test_pyproject_toml_excluded(self, tmpdir): """ Check that pyproject.toml can excluded even if present """ touch(tmpdir / 'pyproject.toml') with open('MANIFEST.in', 'w') as mts: print('exclude pyproject.toml', file=mts) dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() manifest = cmd.filelist.files assert 'pyproject.toml' not in manifest
def test_package_data_and_include_package_data_in_sdist(self): """ Ensure package_data and include_package_data work together. """ setup_attrs = {**SETUP_ATTRS, 'include_package_data': True} assert setup_attrs['package_data'] dist = Distribution(setup_attrs) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() self.assert_package_data_in_manifest(cmd)
def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in package_data are included in the manifest even if they're not added to version control. """ dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() with quiet(): cmd.run() manifest = cmd.filelist.files self.assertTrue(os.path.join('sdist_test', 'a.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest)
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() self.assertTrue(os.path.isfile(filename)) with quiet(): cmd.run() if PY3: # not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however # on mbcs filesys it is not in latin-1 encoding fs_enc = sys.getfilesystemencoding() if fs_enc == 'mbcs': filename = filename.decode('mbcs') else: filename = filename.decode('latin-1') self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) else: # Under Python 2 there seems to be no decoded string in the # filelist. However, due to decode and encoding of the # file name to get utf-8 Manifest the latin1 maybe excluded try: # fs_enc should match how one is expect the decoding to # be proformed for the manifest output. fs_enc = sys.getfilesystemencoding() filename.decode(fs_enc) self.assertTrue(filename in cmd.filelist.files) except UnicodeDecodeError: self.assertFalse(filename in cmd.filelist.files)
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # UTF-8 filename filename = os.path.join('sdist_test', 'smörbröd.py') open(filename, 'w').close() quiet() try: cmd.run() finally: unquiet() # The filelist should contain the UTF-8 filename if sys.platform == 'darwin': filename = decompose(filename) self.assertTrue(filename in cmd.filelist.files)
def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in package_data are included in the manifest even if they're not added to version control. """ dist = Distribution(SETUP_ATTRS) dist.script_name = "setup.py" cmd = sdist(dist) cmd.ensure_finalized() # squelch output quiet() try: cmd.run() finally: unquiet() manifest = cmd.filelist.files self.assertTrue(os.path.join("sdist_test", "a.txt") in manifest) self.assertTrue(os.path.join("sdist_test", "b.txt") in manifest) self.assertTrue(os.path.join("sdist_test", "c.rst") not in manifest)
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() self.assertTrue(os.path.isfile(filename)) quiet() try: cmd.run() finally: unquiet() if sys.version_info >= (3, ): #not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however # on mbcs filesys it is not in latin-1 encoding fs_enc = sys.getfilesystemencoding() if fs_enc == 'mbcs': filename = filename.decode('mbcs') else: filename = filename.decode('latin-1') self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) else: # No conversion takes place under Python 2 and the file # is included. We shall keep it that way for BBB. self.assertTrue(filename in cmd.filelist.files)
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() self.assertTrue(os.path.isfile(filename)) quiet() try: cmd.run() finally: unquiet() if sys.version_info >= (3,): #not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however # on mbcs filesys it is not in latin-1 encoding fs_enc = sys.getfilesystemencoding() if fs_enc == 'mbcs': filename = filename.decode('mbcs') else: filename = filename.decode('latin-1') self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) else: # No conversion takes place under Python 2 and the file # is included. We shall keep it that way for BBB. self.assertTrue(filename in cmd.filelist.files)
def test_custom_build_py(self): """ Ensure projects defining custom build_py don't break when creating sdists (issue #2849) """ from distutils.command.build_py import build_py as OrigBuildPy using_custom_command_guard = mock.Mock() class CustomBuildPy(OrigBuildPy): """ Some projects have custom commands inheriting from `distutils` """ def get_data_files(self): using_custom_command_guard() return super().get_data_files() setup_attrs = {**SETUP_ATTRS, 'include_package_data': True} assert setup_attrs['package_data'] dist = Distribution(setup_attrs) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Make sure we use the custom command cmd.cmdclass = {'build_py': CustomBuildPy} cmd.distribution.cmdclass = {'build_py': CustomBuildPy} assert cmd.distribution.get_command_class('build_py') == CustomBuildPy msg = "setuptools instead of distutils" with quiet(), pytest.warns(SetuptoolsDeprecationWarning, match=msg): cmd.run() using_custom_command_guard.assert_called() self.assert_package_data_in_manifest(cmd)
def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() quiet() try: cmd.run() finally: unquiet() # The filelist should contain the Latin-1 filename # (in one representation or other) if sys.platform == 'darwin': filename = hfs_quote(filename) elif sys.version_info >= (3,): filename = filename.decode(sys.getfilesystemencoding(), 'surrogateescape') self.assertTrue(filename in cmd.filelist.files)
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Create manifest quiet() try: cmd.run() finally: unquiet() # Add UTF-8 filename to manifest filename = os.path.join(b('sdist_test'), b('smörbröd.py')) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b('\n') + filename) manifest.close() # The file must exist to be included in the filelist open(filename, 'w').close() # Re-read manifest cmd.filelist.files = [] quiet() try: cmd.read_manifest() finally: unquiet() # The filelist should contain the UTF-8 filename if sys.version_info >= (3, ): filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files)
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() # Create manifest quiet() try: cmd.run() finally: unquiet() # Add UTF-8 filename to manifest filename = os.path.join(b('sdist_test'), b('smörbröd.py')) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b('\n')+filename) manifest.close() # The file must exist to be included in the filelist open(filename, 'w').close() # Re-read manifest cmd.filelist.files = [] quiet() try: cmd.read_manifest() finally: unquiet() # The filelist should contain the UTF-8 filename if sys.version_info >= (3,): filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files)
def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized()
def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized()
def initialize_options(self): self.sdist = sdist(self.distribution) self.bdist_wheel = bdist_wheel(self.distribution) self.sdist.initialize_options() self.bdist_wheel.initialize_options()