Python setuptools.dist.Distribution() Examples
The following are 30
code examples of setuptools.dist.Distribution().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
setuptools.dist
, or try the search function
.
Example #1
Source File: config.py From python-netsurv with MIT License | 6 votes |
def parse_configuration( distribution, command_options, ignore_option_errors=False): """Performs additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: list """ meta = ConfigMetadataHandler( distribution.metadata, command_options, ignore_option_errors) meta.parse() options = ConfigOptionsHandler( distribution, command_options, ignore_option_errors) options.parse() return [meta, options]
Example #2
Source File: test_dist.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_get_dist_package_decoding_error(self): # Quiet stdout from distutils logs stub_stdouts(self) # trailing comma package_json = '{"dependencies": {"left-pad": "~1.1.1"},}' # bad data could be created by a competiting package. mock_provider = MockProvider({ self.pkgname: package_json, }) mock_dist = pkg_resources.Distribution( metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_egginfo_json(mock_dist) # Should still not fail. self.assertIsNone(results)
Example #3
Source File: test_upload_docs.py From pledgeservice with Apache License 2.0 | 6 votes |
def test_create_zipfile(self): # Test to make sure zipfile creation handles common cases. # This explicitly includes a folder containing an empty folder. dist = Distribution() cmd = upload_docs(dist) cmd.upload_dir = self.upload_dir cmd.target_dir = self.upload_dir tmp_dir = tempfile.mkdtemp() tmp_file = os.path.join(tmp_dir, 'foo.zip') try: zip_file = cmd.create_zipfile(tmp_file) assert zipfile.is_zipfile(tmp_file) zip_file = zipfile.ZipFile(tmp_file) # woh... assert zip_file.namelist() == ['index.html'] zip_file.close() finally: shutil.rmtree(tmp_dir)
Example #4
Source File: test_npm.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_view(self): stub_mod_call(self, cli) stub_base_which(self, which_npm) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--install', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_npm, 'install'],))
Example #5
Source File: test_bdist_egg.py From oss-ftp with MIT License | 6 votes |
def test_bdist_egg(self): dist = Distribution(dict( script_name='setup.py', script_args=['bdist_egg'], name='foo', py_modules=['hi'] )) os.makedirs(os.path.join('build', 'src')) old_stdout = sys.stdout sys.stdout = o = StringIO() try: dist.parse_command_line() dist.run_commands() finally: sys.stdout = old_stdout # let's see if we got our egg link at the right place [content] = os.listdir('dist') self.assertTrue(re.match('foo-0.0.0-py[23].\d.egg$', content))
Example #6
Source File: test_upload_docs.py From oss-ftp with MIT License | 6 votes |
def test_create_zipfile(self): # Test to make sure zipfile creation handles common cases. # This explicitly includes a folder containing an empty folder. dist = Distribution() cmd = upload_docs(dist) cmd.upload_dir = self.upload_dir cmd.target_dir = self.upload_dir tmp_dir = tempfile.mkdtemp() tmp_file = os.path.join(tmp_dir, 'foo.zip') try: zip_file = cmd.create_zipfile(tmp_file) assert zipfile.is_zipfile(tmp_file) zip_file = zipfile.ZipFile(tmp_file) # woh... assert zip_file.namelist() == ['index.html'] zip_file.close() finally: shutil.rmtree(tmp_dir)
Example #7
Source File: test_npm.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_init_install_develop(self): stub_mod_call(self, cli) stub_base_which(self, which_npm) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--init', '--install', '--development'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) # Should still invoke install self.assertEqual(self.call_args[0], ( [which_npm, 'install', '--production=false'],))
Example #8
Source File: test_npm.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_init_install_production(self): stub_mod_call(self, cli) stub_base_which(self, which_npm) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--init', '--install', '--production'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) # Should still invoke install self.assertEqual(self.call_args[0], ( [which_npm, 'install', '--production=true'],))
Example #9
Source File: test_npm.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_no_init_nodevnoprod(self): # install implies init stub_mod_call(self, cli) stub_base_which(self, which_npm) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--install'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # The cli will still automatically write to that, as install # implies init. self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_npm, 'install'],))
Example #10
Source File: config.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def parse_configuration( distribution, command_options, ignore_option_errors=False): """Performs additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: list """ options = ConfigOptionsHandler( distribution, command_options, ignore_option_errors) options.parse() meta = ConfigMetadataHandler( distribution.metadata, command_options, ignore_option_errors, distribution.package_dir) meta.parse() return meta, options
Example #11
Source File: test_npm.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_view(self): stub_mod_call(self, cli) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertFalse(exists(join(tmpdir, 'package.json'))) # also log handlers removed. self.assertEqual(len(getLogger('calmjs.cli').handlers), 0) # written to stdout with the correct indentation level. self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
Example #12
Source File: test_easy_install.py From oss-ftp with MIT License | 6 votes |
def test_no_find_links(self): # new option '--no-find-links', that blocks find-links added at # the project level dist = Distribution() cmd = easy_install(dist) cmd.check_pth_processing = lambda: True cmd.no_find_links = True cmd.find_links = ['link1', 'link2'] cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok') cmd.args = ['ok'] cmd.ensure_finalized() self.assertEqual(cmd.package_index.scanned_urls, {}) # let's try without it (default behavior) cmd = easy_install(dist) cmd.check_pth_processing = lambda: True cmd.find_links = ['link1', 'link2'] cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok') cmd.args = ['ok'] cmd.ensure_finalized() keys = sorted(cmd.package_index.scanned_urls.keys()) self.assertEqual(keys, ['link1', 'link2'])
Example #13
Source File: config.py From lambda-packs with MIT License | 6 votes |
def parse_configuration( distribution, command_options, ignore_option_errors=False): """Performs additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: list """ options = ConfigOptionsHandler( distribution, command_options, ignore_option_errors) options.parse() meta = ConfigMetadataHandler( distribution.metadata, command_options, ignore_option_errors, distribution.package_dir) meta.parse() return meta, options
Example #14
Source File: test_sdist.py From pledgeservice with Apache License 2.0 | 6 votes |
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)
Example #15
Source File: test_dist.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_build_calmjs_artifacts_standard(self): dist = distutils_dist.Distribution() build_cmd = dist.get_command_obj('build') original_subcmds = list(build_cmd.sub_commands) calmjs_dist.build_calmjs_artifacts(dist, 'build_artifact', False) self.assertEqual(original_subcmds, build_cmd.sub_commands) # keys are named after the build step. calmjs_dist.build_calmjs_artifacts(dist, 'build_artifact', True) self.assertEqual( ('build_artifact', calmjs_dist.has_calmjs_artifact_declarations), build_cmd.sub_commands[-1], ) calmjs_dist.build_calmjs_artifacts(dist, 'calmjs_artifact', True) self.assertEqual( ('calmjs_artifact', calmjs_dist.has_calmjs_artifact_declarations), build_cmd.sub_commands[-1], )
Example #16
Source File: test_develop.py From pledgeservice with Apache License 2.0 | 6 votes |
def notest_develop_with_setup_requires(self): wanted = ("Could not find suitable distribution for " "Requirement.parse('I-DONT-EXIST')") old_dir = os.getcwd() os.chdir(self.dir) try: try: dist = Distribution({'setup_requires': ['I_DONT_EXIST']}) except DistutilsError: e = sys.exc_info()[1] error = str(e) if error == wanted: pass finally: os.chdir(old_dir)
Example #17
Source File: test_yarn.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_view(self): stub_mod_call(self, cli) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertFalse(exists(join(tmpdir, 'package.json'))) # also log handlers removed. self.assertEqual(len(getLogger('calmjs.cli').handlers), 0) # written to stdout with the correct indentation level. self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
Example #18
Source File: config.py From ironpython2 with Apache License 2.0 | 6 votes |
def parse_configuration( distribution, command_options, ignore_option_errors=False): """Performs additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: list """ options = ConfigOptionsHandler( distribution, command_options, ignore_option_errors) options.parse() meta = ConfigMetadataHandler( distribution.metadata, command_options, ignore_option_errors, distribution.package_dir) meta.parse() return meta, options
Example #19
Source File: config.py From python-netsurv with MIT License | 6 votes |
def parse_configuration( distribution, command_options, ignore_option_errors=False): """Performs additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :rtype: list """ meta = ConfigMetadataHandler( distribution.metadata, command_options, ignore_option_errors) meta.parse() options = ConfigOptionsHandler( distribution, command_options, ignore_option_errors) options.parse() return [meta, options]
Example #20
Source File: test_sdist.py From oss-ftp with MIT License | 6 votes |
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)
Example #21
Source File: test_yarn.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_no_init_nodevnoprod(self): # install implies init stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--install'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # The cli will still automatically write to that, as install # implies init. self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_yarn, 'install'],))
Example #22
Source File: test_yarn.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_init_install_production(self): stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--init', '--install', '--production'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) # Should still invoke install self.assertEqual(self.call_args[0], ( [which_yarn, 'install', '--production=true'],))
Example #23
Source File: test_yarn.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_init_install_develop(self): stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--init', '--install', '--development'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) # Should still invoke install self.assertEqual(self.call_args[0], ( [which_yarn, 'install', '--production=false'],))
Example #24
Source File: test_sdist.py From oss-ftp with MIT License | 6 votes |
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)
Example #25
Source File: test_yarn.py From calmjs with GNU General Public License v2.0 | 6 votes |
def test_install_view(self): stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--install', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_yarn, 'install'],))
Example #26
Source File: test_develop.py From oss-ftp with MIT License | 6 votes |
def notest_develop_with_setup_requires(self): wanted = ("Could not find suitable distribution for " "Requirement.parse('I-DONT-EXIST')") old_dir = os.getcwd() os.chdir(self.dir) try: try: Distribution({'setup_requires': ['I_DONT_EXIST']}) except DistutilsError: e = sys.exc_info()[1] error = str(e) if error == wanted: pass finally: os.chdir(old_dir)
Example #27
Source File: test_easy_install.py From pledgeservice with Apache License 2.0 | 6 votes |
def test_no_find_links(self): # new option '--no-find-links', that blocks find-links added at # the project level dist = Distribution() cmd = easy_install(dist) cmd.check_pth_processing = lambda: True cmd.no_find_links = True cmd.find_links = ['link1', 'link2'] cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok') cmd.args = ['ok'] cmd.ensure_finalized() self.assertEqual(cmd.package_index.scanned_urls, {}) # let's try without it (default behavior) cmd = easy_install(dist) cmd.check_pth_processing = lambda: True cmd.find_links = ['link1', 'link2'] cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok') cmd.args = ['ok'] cmd.ensure_finalized() keys = sorted(cmd.package_index.scanned_urls.keys()) self.assertEqual(keys, ['link1', 'link2'])
Example #28
Source File: test_sdist.py From oss-ftp with MIT License | 5 votes |
def test_write_manifest_skips_non_utf8_filenames(self): """ Files that cannot be encoded to UTF-8 (specifically, those that weren't originally successfully decoded and have surrogate escapes) should be omitted from the manifest. See https://bitbucket.org/tarek/distribute/issue/303 for history. """ dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' mm = manifest_maker(dist) mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') os.mkdir('sdist_test.egg-info') # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) # Add filename with surrogates and write manifest with quiet(): mm.run() u_filename = filename.decode('utf-8', 'surrogateescape') mm.filelist.append(u_filename) # Re-write manifest mm.write_manifest() manifest = open(mm.manifest, 'rbU') contents = manifest.read() manifest.close() # The manifest should be UTF-8 encoded try: contents.decode('UTF-8') except UnicodeDecodeError: e = sys.exc_info()[1] self.fail(e) # The Latin-1 filename should have been skipped self.assertFalse(posix(filename) in contents) # The filelist should have been updated as well self.assertFalse(u_filename in mm.filelist.files)
Example #29
Source File: __init__.py From lambda-packs with MIT License | 5 votes |
def _install_setup_requires(attrs): # Note: do not use `setuptools.Distribution` directly, as # our PEP 517 backend patch `distutils.core.Distribution`. dist = distutils.core.Distribution(dict( (k, v) for k, v in attrs.items() if k in ('dependency_links', 'setup_requires') )) # Honor setup.cfg's options. dist.parse_config_files(ignore_option_errors=True) if dist.setup_requires: dist.fetch_build_eggs(dist.setup_requires)
Example #30
Source File: test_easy_install.py From pledgeservice with Apache License 2.0 | 5 votes |
def test_local_index(self): # make sure the local index is used # when easy_install looks for installed # packages new_location = tempfile.mkdtemp() target = tempfile.mkdtemp() egg_file = os.path.join(new_location, 'foo-1.0.egg-info') f = open(egg_file, 'w') try: f.write('Name: foo\n') finally: f.close() sys.path.append(target) old_ppath = os.environ.get('PYTHONPATH') os.environ['PYTHONPATH'] = os.path.pathsep.join(sys.path) try: dist = Distribution() dist.script_name = 'setup.py' cmd = easy_install(dist) cmd.install_dir = target cmd.args = ['foo'] cmd.ensure_finalized() cmd.local_index.scan([new_location]) res = cmd.easy_install('foo') actual = os.path.normcase(os.path.realpath(res.location)) expected = os.path.normcase(os.path.realpath(new_location)) self.assertEqual(actual, expected) finally: sys.path.remove(target) for basedir in [new_location, target, ]: if not os.path.exists(basedir) or not os.path.isdir(basedir): continue try: shutil.rmtree(basedir) except: pass if old_ppath is not None: os.environ['PYTHONPATH'] = old_ppath else: del os.environ['PYTHONPATH']