def test_convert_package_names(self): result, error = calmjs_dist.convert_package_names('setuptools calmjs') self.assertEqual(result, ['setuptools', 'calmjs']) self.assertEqual(error, []) result, error = calmjs_dist.convert_package_names('calmjs [dev]') self.assertEqual(result, ['calmjs']) self.assertEqual(error, ['[dev]']) result, error = calmjs_dist.convert_package_names('calmjs[dev]') self.assertEqual(result, ['calmjs[dev]']) self.assertEqual(error, []) result, error = calmjs_dist.convert_package_names(['setuptools']) self.assertEqual(result, ['setuptools']) self.assertEqual(error, []) result, error = calmjs_dist.convert_package_names( ['setuptools', '[dev]', 'calmjs [dev]']) self.assertEqual(result, ['setuptools', 'calmjs [dev]']) self.assertEqual(error, ['[dev]'])
def test_convert_package_names(self): result, error = calmjs_dist.convert_package_names('setuptools calmjs') self.assertEqual(result, ['setuptools', 'calmjs']) self.assertEqual(error, []) result, error = calmjs_dist.convert_package_names('calmjs [dev]') self.assertEqual(result, ['calmjs']) self.assertEqual(error, ['[dev]']) result, error = calmjs_dist.convert_package_names('calmjs[dev]') self.assertEqual(result, ['calmjs[dev]']) self.assertEqual(error, []) result, error = calmjs_dist.convert_package_names( ['setuptools']) self.assertEqual(result, ['setuptools']) self.assertEqual(error, []) result, error = calmjs_dist.convert_package_names( ['setuptools', '[dev]', 'calmjs [dev]']) self.assertEqual(result, ['setuptools', 'calmjs [dev]']) self.assertEqual(error, ['[dev]'])
def pkg_manager_view(self, package_names, stream=None, explicit=False, **kw): """ Returns the manifest JSON for the Python package name. Default npm implementation calls for package.json. If this class is initiated using standard procedures, this will mimic the functionality of ``npm view`` but mostly for showing the dependencies. This is done as a default action. Arguments: package_names The names of the python packages with their requirements to source the package.json from. stream If specified, the generated package.json will be written to there. explicit If True, the package names specified are the explicit list to search for - no dependency resolution will then be done. Returns the manifest json as a dict. """ # For looking up the pkg_name to dist converter for explicit to_dists = { False: find_packages_requirements_dists, True: pkg_names_to_dists, } # assuming string, and assume whitespaces are invalid. pkg_names, malformed = convert_package_names(package_names) if malformed: msg = 'malformed package name(s) specified: %s' % ', '.join( malformed) raise ValueError(msg) if len(pkg_names) == 1: logger.info( "generating a flattened '%s' for '%s'", self.pkgdef_filename, pkg_names[0], ) else: logger.info( "generating a flattened '%s' for packages {%s}", self.pkgdef_filename, ', '.join(pkg_names), ) # remember the filename is in the context of the distribution, # not the filesystem. dists = to_dists[explicit](pkg_names) pkgdef_json = flatten_dist_egginfo_json( dists, filename=self.pkgdef_filename, dep_keys=self.dep_keys, ) if pkgdef_json.get(self.pkg_name_field, NotImplemented) is NotImplemented: # use the last item. pkg_name = Requirement.parse(pkg_names[-1]).project_name pkgdef_json[self.pkg_name_field] = pkg_name if stream: self.dump(pkgdef_json, stream) stream.write('\n') return pkgdef_json
def pkg_manager_view( self, package_names, stream=None, explicit=False, **kw): """ Returns the manifest JSON for the Python package name. Default npm implementation calls for package.json. If this class is initiated using standard procedures, this will mimic the functionality of ``npm view`` but mostly for showing the dependencies. This is done as a default action. Arguments: package_names The names of the python packages with their requirements to source the package.json from. stream If specified, the generated package.json will be written to there. explicit If True, the package names specified are the explicit list to search for - no dependency resolution will then be done. Returns the manifest json as a dict. """ # For looking up the pkg_name to dist converter for explicit to_dists = { False: find_packages_requirements_dists, True: pkg_names_to_dists, } # assuming string, and assume whitespaces are invalid. pkg_names, malformed = convert_package_names(package_names) if malformed: msg = 'malformed package name(s) specified: %s' % ', '.join( malformed) raise ValueError(msg) if len(pkg_names) == 1: logger.info( "generating a flattened '%s' for '%s'", self.pkgdef_filename, pkg_names[0], ) else: logger.info( "generating a flattened '%s' for packages {%s}", self.pkgdef_filename, ', '.join(pkg_names), ) # remember the filename is in the context of the distribution, # not the filesystem. dists = to_dists[explicit](pkg_names) pkgdef_json = flatten_dist_egginfo_json( dists, filename=self.pkgdef_filename, dep_keys=self.dep_keys, ) if pkgdef_json.get( self.pkg_name_field, NotImplemented) is NotImplemented: # use the last item. pkg_name = Requirement.parse(pkg_names[-1]).project_name pkgdef_json[self.pkg_name_field] = pkg_name if stream: self.dump(pkgdef_json, stream) stream.write('\n') return pkgdef_json