예제 #1
0
def _project_wheel_metadata(
        builder: build.ProjectBuilder) -> 'importlib_metadata.PackageMetadata':
    with tempfile.TemporaryDirectory() as tmpdir:
        path = pathlib.Path(builder.metadata_path(tmpdir))
        # https://github.com/python/importlib_metadata/pull/343
        return importlib_metadata.PathDistribution(
            path).metadata  # type: ignore
예제 #2
0
def parse_metadata(cls, location):
    """
    Return a PythonPackage from an  PKG-INFO or METADATA file ``location``
    string or pathlib.Path-like object.

    Looks in neighboring files as needed when an installed layout is found.
    """
    path = location
    if not isinstance(location, (Path, ZipPath)):
        path = Path(location)

    # build from dir if we are an installed distro
    parent = path.parent
    if parent.name.endswith(meta_dir_suffixes):
        path = parent

    dist = importlib_metadata.PathDistribution(path)

    # FIXME: handle other_urls
    meta = dist.metadata
    urls, other_urls = get_urls(meta)

    return cls(
        name=get_attribute(meta, 'Name'),
        version=get_attribute(meta, 'Version'),
        description=get_description(meta, location),
        declared_license=get_declared_license(meta),
        keywords=get_keywords(meta),
        parties=get_parties(meta),
        dependencies=get_dist_dependencies(dist),
        **urls,
    )
예제 #3
0
def test_metadata_path_legacy(tmp_dir, package_legacy):
    builder = build.ProjectBuilder(package_legacy)

    metadata = importlib_metadata.PathDistribution(
        pathlib.Path(builder.metadata_path(tmp_dir)), ).metadata

    assert metadata['name'] == 'legacy'
    assert metadata['Version'] == '1.0.0'
예제 #4
0
def test_metadata_path_with_prepare(tmp_dir, package_test_setuptools):
    builder = build.ProjectBuilder(package_test_setuptools)

    metadata = importlib_metadata.PathDistribution(
        pathlib.Path(builder.metadata_path(tmp_dir)), ).metadata

    assert metadata['name'] == 'test-setuptools'
    assert metadata['Version'] == '1.0.0'
예제 #5
0
def test_metadata_path_no_prepare(tmp_dir, test_no_prepare_path):
    builder = build.ProjectBuilder(test_no_prepare_path)

    metadata = importlib_metadata.PathDistribution(
        pathlib.Path(builder.metadata_path(tmp_dir)), ).metadata

    assert metadata['name'] == 'test-no-prepare'
    assert metadata['Version'] == '1.0.0'
예제 #6
0
def load(root):
    """
    Given a source directory (root) of a package,
    return an importlib.metadata.Distribution object
    with metadata build from that package.
    """
    root = os.path.expanduser(root)
    system = compat_system(root)
    builder = functools.partial(build, source_dir=root, system=system)
    path = Path(build_as_zip(builder))
    return imp_meta.PathDistribution(path)
예제 #7
0
    def find_distributions(cls, context=metadata.DistributionFinder.Context()):
        name = (
            ".*" if context.name is None
            # See normalize_name_wheel in build-wheel.py.
            else re.sub(r"[^A-Za-z0-9.]+", '_', context.name))
        pattern = fr"^{name}(-.*)?\.(dist|egg)-info$"

        for entry in context.path:
            path_cls = AssetPath if entry.startswith(ASSET_PREFIX +
                                                     "/") else pathlib.Path
            entry_path = path_cls(entry)
            if entry_path.is_dir():
                for sub_path in entry_path.iterdir():
                    if re.search(pattern, sub_path.name, re.IGNORECASE):
                        yield metadata.PathDistribution(sub_path)
예제 #8
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try:
    import importlib.metadata as importlib_metadata
except ImportError:  # pragma: NO COVER
    import importlib_metadata
import os
import pathlib
import unittest
import unittest.mock

MOCK_PACKAGE_PATH = importlib_metadata.PackagePath("extra-dll", "bezier.dll")
MOCK_PACKAGE_PATH.dist = importlib_metadata.PathDistribution(pathlib.Path(""))


class Test__get_extra_dll_dir(unittest.TestCase):
    @staticmethod
    def _call_function_under_test(bezier_files):
        from bezier import __config__

        return __config__._get_extra_dll_dir(bezier_files)

    def test_no_matches(self):
        extra_dll_dir = self._call_function_under_test(())
        self.assertIsNone(extra_dll_dir)

    def test_multiple_choices_with_match(self):
        mock_path1 = importlib_metadata.PackagePath("bezier", "__config__.py")