pyproject_parser.classes

Classes to represent readme and license files.

Classes:

License([file, text])

Represents a license in PEP 621 configuration.

Readme([content_type, charset, file, text])

Represents a readme in PEP 621 configuration.

Data:

class License(file=None, text=None)[source]

Bases: object

Represents a license in PEP 621 configuration.

Parameters

Attributes:

file

The path to the license file.

text

The content of the license.

Methods:

from_dict(data)

Construct a License from a dictionary containing the same keys as the class constructor.

resolve([inplace])

Retrieve the contents of the license file if the file is set.

to_dict()

Construct a dictionary containing the keys of the License object.

to_pep621_dict()

Construct a dictionary containing the keys of the License object, suitable for use in PEP 621 pyproject.toml configuration.

file

Type:    Optional[Path]

The path to the license file.

classmethod from_dict(data)[source]

Construct a License from a dictionary containing the same keys as the class constructor.

Functionally identical to License(**data) but provided to give an identical API to Readme.

Parameters

data (Mapping[str, str])

Return type

~_L

resolve(inplace=False)[source]

Retrieve the contents of the license file if the file is set.

Returns a new License object with text set to the content of the file.

Parameters

inplace (bool) – Modifies and returns the current object rather than creating a new one. Default False.

Return type

~_L

text

Type:    Optional[str]

The content of the license.

to_dict()[source]

Construct a dictionary containing the keys of the License object.

Return type

Dict[str, str]

to_pep621_dict()[source]

Construct a dictionary containing the keys of the License object, suitable for use in PEP 621 pyproject.toml configuration.

Unlike to_dict() this ignores the text key if self.file is set.

Return type

Dict[str, str]

See also

from_dict()

class Readme(content_type=None, charset='UTF-8', file=None, text=None)[source]

Bases: object

Represents a readme in PEP 621 configuration.

Parameters
  • content_type (Optional[Literal['text/markdown', 'text/x-rst', 'text/plain']]) – The content type of the readme. Default None.

  • charset (str) – The charset / encoding of the readme. Default 'UTF-8'.

  • file (Union[str, Path, PathLike, None]) – The path to the license file. Default None.

  • text (Optional[str]) – The content of the license. Default None.

Attributes:

charset

The charset / encoding of the readme.

content_type

The content type of the readme.

file

The path to the readme file.

text

The content of the readme.

Methods:

from_dict(data)

Construct a Readme from a dictionary containing the same keys as the class constructor.

from_file(file[, charset])

Create a Readme from a filename.

resolve([inplace])

Retrieve the contents of the readme file if the self.file is set.

to_dict()

Construct a dictionary containing the keys of the Readme object.

to_pep621_dict()

Construct a dictionary containing the keys of the Readme object, suitable for use in PEP 621 pyproject.toml configuration.

charset

Type:    str

The charset / encoding of the readme.

content_type

Type:    Optional[Literal['text/markdown', 'text/x-rst', 'text/plain']]

The content type of the readme.

file

Type:    Optional[Path]

The path to the readme file.

classmethod from_dict(data)[source]

Construct a Readme from a dictionary containing the same keys as the class constructor.

In addition, content_type may instead be given as content-type.

Parameters

data (ReadmeDict)

Return type

~_R

classmethod from_file(file, charset='UTF-8')[source]

Create a Readme from a filename.

Parameters
  • file (Union[str, Path, PathLike]) – The path to the readme file.

  • charset (str) – The charset / encoding of the readme file. Default 'UTF-8'.

Return type

~_R

resolve(inplace=False)[source]

Retrieve the contents of the readme file if the self.file is set.

Returns a new Readme object with text set to the content of the file.

Parameters

inplace (bool) – Modifies and returns the current object rather than creating a new one. Default False.

Return type

~_R

text

Type:    Optional[str]

The content of the readme.

to_dict()[source]

Construct a dictionary containing the keys of the Readme object.

Return type

ReadmeDict

to_pep621_dict()[source]

Construct a dictionary containing the keys of the Readme object, suitable for use in PEP 621 pyproject.toml configuration.

Unlike to_dict() this ignores the text key if self.file is set, and ignores self.content_type if it matches the content-type inferred from the file extension.

See also

from_dict()

Return type

Dict[str, str]

_L = TypeVar(_L, bound=License)

Type:    TypeVar

Invariant TypeVar bound to pyproject_parser.classes.License.

_R = TypeVar(_R, bound=Readme)

Type:    TypeVar

Invariant TypeVar bound to pyproject_parser.classes.Readme.