@classmethod<EOL><INDENT>def from_path(cls, path, format=None):<DEDENT>
name = None<EOL>data = None<EOL>if format is None:<EOL><INDENT>formats = (FileFormat.py, FileFormat.yaml)<EOL><DEDENT>else:<EOL><INDENT>formats = (format,)<EOL><DEDENT>try:<EOL><INDENT>mode = os.stat(path).st_mode<EOL><DEDENT>except (IOError, OSError):<EOL><INDENT>raise PackageMetadataError(<EOL>"<STR_LIT>" % path)<EOL><DEDENT>is_dir = stat.S_ISDIR(mode)<EOL>for name_ in config.plugins.package_repository.filesystem.package_filenames:<EOL><INDENT>for format_ in formats:<EOL><INDENT>if is_dir:<EOL><INDENT>filepath = os.path.join(path, "<STR_LIT>" % (name_,<EOL>format_.extension))<EOL>exists = os.path.isfile(filepath)<EOL><DEDENT>else:<EOL><INDENT>if format is None:<EOL><INDENT>if os.path.splitext(path)[<NUM_LIT:1>] != format_.extension:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>filepath = path<EOL>exists = True<EOL><DEDENT>if exists:<EOL><INDENT>data = load_from_file(filepath, format_, disable_memcache=True)<EOL>break<EOL><DEDENT><DEDENT>if data:<EOL><INDENT>name = data.get("<STR_LIT:name>")<EOL>if name is not None or isinstance(name, basestring):<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>if data is None:<EOL><INDENT>raise PackageMetadataError("<STR_LIT>" % path)<EOL><DEDENT>if name is None or not isinstance(name, basestring):<EOL><INDENT>raise PackageMetadataError(<EOL>"<STR_LIT>" % filepath)<EOL><DEDENT>package = create_package(name, data, package_cls=cls)<EOL>result = package._get_preprocessed(data)<EOL>if result:<EOL><INDENT>package, data = result<EOL><DEDENT>package.filepath = filepath<EOL>package.includes = set()<EOL>def visit(d):<EOL><INDENT>for k, v in d.iteritems():<EOL><INDENT>if isinstance(v, SourceCode):<EOL><INDENT>package.includes |= (v.includes or set())<EOL><DEDENT>elif isinstance(v, dict):<EOL><INDENT>visit(v)<EOL><DEDENT><DEDENT><DEDENT>visit(data)<EOL>package._validate_includes()<EOL>return package<EOL>
Load a developer package.

        A developer package may for example be a package.yaml or package.py in a
        user's source directory.

        Args:
            path: Directory containing the package definition file, or file
                path for the package file itself
            format: which FileFormat to use, or None to check both .py and .yaml

        Returns:
            `Package` object.