def _import_packages(packages, optional=None):
if not optional:<EOL><INDENT>optional = []<EOL><DEDENT>package_references = set()<EOL>failures = set()<EOL>for package_name in packages:<EOL><INDENT>try:<EOL><INDENT>package_reference = __import__(package_name, globals(), locals(), [], <NUM_LIT:0>)<EOL>package_references.add(package_reference)<EOL><DEDENT>except ImportError:<EOL><INDENT>failures.add(package_name)<EOL><DEDENT><DEDENT>if failures:<EOL><INDENT>raise ImportError(u"<STR_LIT>".format(u"<STR_LIT:U+002CU+0020>".join(failures)))<EOL><DEDENT>failures = set()<EOL>for package_name in optional:<EOL><INDENT>try:<EOL><INDENT>package_reference = __import__(package_name, globals(), locals(), [], <NUM_LIT:0>)<EOL>package_references.add(package_reference)<EOL><DEDENT>except ImportError:<EOL><INDENT>failures.add(package_name)<EOL><DEDENT><DEDENT>for failure in failures:<EOL><INDENT>warn(ImportWarning(u"<STR_LIT>".format(failure)))<EOL><DEDENT>return package_references<EOL>
Get actual package references from an iterable of package names
:param packages: iterable of package names
:type packages: iter of basestr
:return: set of package references
:rtype: set