Skip to content

Commit

Permalink
chore: merge extras-descriptions and extras context items
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Oct 21, 2023
1 parent 34f74b7 commit 6fe40ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
12 changes: 8 additions & 4 deletions mknodes/info/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
import mknodes as mk

from mknodes.data import buildsystems, commitconventions, installmethods, tools
from mknodes.info import linkprovider, mkdocsconfigfile, packageregistry, pyproject
from mknodes.info import (
folderinfo,
linkprovider,
mkdocsconfigfile,
packageregistry,
pyproject,
)
from mknodes.utils import clihelpers, log, superdict


Expand Down Expand Up @@ -135,7 +141,7 @@ class PackageContext(Context):
"""The names of the dependencies."""
required_packages: dict = dataclasses.field(default_factory=dict)
"""PackageInfos for the dependencies."""
extras: dict[str, list[str]] = dataclasses.field(default_factory=dict)
extras: dict[str, folderinfo.PackageExtra] = dataclasses.field(default_factory=dict)
"""The extras of the distribution."""
urls: dict[str, str] = dataclasses.field(default_factory=dict)
"""A set of URLs related to the distribution."""
Expand Down Expand Up @@ -197,8 +203,6 @@ class PackageContext(Context):
default_factory=list,
)
"""Commit types defined in pyproject mknodes section *[pyproject]*"""
extras_descriptions: dict[str, str] = dataclasses.field(default_factory=dict)
"""Descriptions for the extras, defined in pyproject mknodes section *[pyproject]*"""
package_repos: list[installmethods.InstallMethodStr] = dataclasses.field(
default_factory=list,
)
Expand Down
31 changes: 29 additions & 2 deletions mknodes/info/folderinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import contextlib
import dataclasses
import functools
import importlib
import os
Expand Down Expand Up @@ -53,6 +54,21 @@
)


@dataclasses.dataclass
class PackageExtra:
"""A class describing a package extra, used to define additional dependencies."""

name: str
"""Name of the extra."""
packages: list[str] = dataclasses.field(default_factory=list)
"""List of packages which are part of the extra."""
description: str = ""
"""Optional description for the extra.
Must be defined in pyproject mknodes section.
"""


class FolderInfo:
"""Aggregates information about a working dir."""

Expand Down Expand Up @@ -126,6 +142,18 @@ def info(self) -> packageinfo.PackageInfo:
"""Return a PackageInfo object for given distribution."""
return packageregistry.get_info(self.pyproject.name or self.git.repo_name)

@functools.cached_property
def extras(self) -> dict[str, PackageExtra]:
"""Return a dict containing extras and the packages {extra: [package_1, ...]}."""
dct = {}
for k, v in self.info.extras.items():
dct[k] = PackageExtra(
k,
packages=v,
description=self.pyproject.extras_descriptions.get(k, ""),
)
return dct

@functools.cached_property
def repository_url(self) -> str:
"""Return url of the repository by querying multiple sources.
Expand Down Expand Up @@ -280,7 +308,7 @@ def context(self) -> contexts.PackageContext:
required_python_version=self.info.required_python_version,
required_packages=self.info.required_packages,
required_package_names=self.info.required_package_names,
extras=self.info.extras,
extras=self.extras,
tools=self.tools,
entry_points=self.info.entry_points,
cli=self.info.cli,
Expand All @@ -298,7 +326,6 @@ def context(self) -> contexts.PackageContext:
configured_build_systems=self.pyproject.configured_build_systems,
tool_section=self.pyproject.tool,
commit_types=self.pyproject.allowed_commit_types,
extras_descriptions=self.pyproject.extras_descriptions,
package_repos=self.pyproject.package_repos,
line_length=self.pyproject.line_length,
)
Expand Down

0 comments on commit 6fe40ea

Please sign in to comment.