def add_requirement(<EOL>self,<EOL>install_req,  <EOL>parent_req_name=None,  <EOL>extras_requested=None  <EOL>):<EOL>
name = install_req.name<EOL>if not install_req.match_markers(extras_requested):<EOL><INDENT>logger.info(<EOL>"<STR_LIT>",<EOL>name, install_req.markers,<EOL>)<EOL>return [], None<EOL><DEDENT>if install_req.link and install_req.link.is_wheel:<EOL><INDENT>wheel = Wheel(install_req.link.filename)<EOL>if self.check_supported_wheels and not wheel.supported():<EOL><INDENT>raise InstallationError(<EOL>"<STR_LIT>" %<EOL>wheel.filename<EOL>)<EOL><DEDENT><DEDENT>assert install_req.is_direct == (parent_req_name is None), (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>if not name:<EOL><INDENT>self.unnamed_requirements.append(install_req)<EOL>return [install_req], None<EOL><DEDENT>try:<EOL><INDENT>existing_req = self.get_requirement(name)<EOL><DEDENT>except KeyError:<EOL><INDENT>existing_req = None<EOL><DEDENT>has_conflicting_requirement = (<EOL>parent_req_name is None and<EOL>existing_req and<EOL>not existing_req.constraint and<EOL>existing_req.extras == install_req.extras and<EOL>existing_req.req.specifier != install_req.req.specifier<EOL>)<EOL>if has_conflicting_requirement:<EOL><INDENT>raise InstallationError(<EOL>"<STR_LIT>"<EOL>% (install_req, existing_req, name)<EOL>)<EOL><DEDENT>if not existing_req:<EOL><INDENT>self.requirements[name] = install_req<EOL>if name.lower() != name:<EOL><INDENT>self.requirement_aliases[name.lower()] = name<EOL><DEDENT>return [install_req], install_req<EOL><DEDENT>if install_req.constraint or not existing_req.constraint:<EOL><INDENT>return [], existing_req<EOL><DEDENT>does_not_satisfy_constraint = (<EOL>install_req.link and<EOL>not (<EOL>existing_req.link and<EOL>install_req.link.path == existing_req.link.path<EOL>)<EOL>)<EOL>if does_not_satisfy_constraint:<EOL><INDENT>self.reqs_to_cleanup.append(install_req)<EOL>raise InstallationError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % name,<EOL>)<EOL><DEDENT>existing_req.constraint = False<EOL>existing_req.extras = tuple(sorted(<EOL>set(existing_req.extras) | set(install_req.extras)<EOL>))<EOL>logger.debug(<EOL>"<STR_LIT>",<EOL>existing_req, existing_req.extras,<EOL>)<EOL>return [existing_req], existing_req<EOL>
Add install_req as a requirement to install.

        :param parent_req_name: The name of the requirement that needed this
            added. The name is used because when multiple unnamed requirements
            resolve to the same name, we could otherwise end up with dependency
            links that point outside the Requirements set. parent_req must
            already be added. Note that None implies that this is a user
            supplied requirement, vs an inferred one.
        :param extras_requested: an iterable of extras used to evaluate the
            environment markers.
        :return: Additional requirements to scan. That is either [] if
            the requirement is not applicable, or [install_req] if the
            requirement is applicable and has just been added.