<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_valid_package_name(name, raise_error=False):
 """Test the validity of a package name string. Args: name (str):
 Name to test. raise_error (bool):
 If True, raise an exception on failure Returns: bool. """

    is_valid = PACKAGE_NAME_REGEX.match(name)
    if raise_error and not is_valid:
        raise PackageRequestError("Not a valid package name: %r" % name)
    return is_valid