Reference

poetry_merge_lock.__main__

Command-line interface.

poetry_merge_lock.core

Core module.

poetry_merge_lock.core.activate_dependencies(packages)

Activate the optional dependencies of every package.

Activating optional dependencies ensures their inclusion when the lock file is written. Normally, optional dependencies are activated by the solver if another package depends on them. But invoking the solver would result in regenerating the lock file from scratch, losing the information in the original lock file. So we activate the dependencies manually instead. We know the solver would activate them because they would not be present in the lock file otherwise.

Parameters

packages (List[poetry.packages.package.Package]) – The list of packages.

Return type

None

poetry_merge_lock.core.load(locker)

Load a lock file with merge conflicts.

Parameters

locker (poetry.packages.locker.Locker) – The locker object.

Returns

The merged TOML document.

Return type

tomlkit.toml_document.TOMLDocument

poetry_merge_lock.core.load_packages(locker, lock_data)

Load the packages from a TOML document with lock data.

Parameters
  • locker (poetry.packages.locker.Locker) – The locker object.

  • lock_data (tomlkit.toml_document.TOMLDocument) – The lock data.

Returns

The list of packages.

Return type

List[poetry.packages.package.Package]

poetry_merge_lock.core.load_toml_versions(toml_file)

Load a pair of TOML documents from a TOML file with merge conflicts.

Parameters

toml_file (pathlib.Path) – Path to the lock file.

Returns

A pair of TOML documents, corresponding to our version and their version.

Return type

Tuple[tomlkit.toml_document.TOMLDocument, tomlkit.toml_document.TOMLDocument]

poetry_merge_lock.core.merge_lock(poetry)

Resolve merge conflicts in Poetry’s lock file.

Parameters

poetry (poetry.poetry.Poetry) –

Return type

None

poetry_merge_lock.core.save(locker, lock_data, root)

Validate the lock data and write it to disk.

Parameters
  • locker (poetry.packages.locker.Locker) – The locker object.

  • lock_data (tomlkit.toml_document.TOMLDocument) – The lock data.

  • root (poetry.packages.package.Package) – The root package of the Poetry project.

Return type

None

poetry_merge_lock.parser

Line-based parser for files with merge conflicts.

class poetry_merge_lock.parser.State(value)

Parser state for files with merge conflicts.

class poetry_merge_lock.parser.Token(value)

Token for parsing files with merge conflicts.

exception poetry_merge_lock.parser.UnexpectedTokenError(token)

The parser encountered an unexpected token.

Parameters

token (poetry_merge_lock.parser.Token) –

Return type

None

poetry_merge_lock.parser.parse(lines)

Parse a sequence of lines with merge conflicts.

Parameters

lines (Sequence[str]) – The sequence of lines to be parsed.

Returns

A pair of sequences of lines. The first sequence corresponds to our version, and the second, to their version.

Return type

Tuple[Sequence[str], Sequence[str]]

poetry_merge_lock.parser.parse_line(line, state)

Parse a single line in a file with merge conflicts.

Parameters
Returns

A pair, consisting of the token for the line, and the new parser state.

Raises

UnexpectedTokenError – The parser encountered an unexpected token.

Return type

Tuple[poetry_merge_lock.parser.Token, poetry_merge_lock.parser.State]

poetry_merge_lock.parser.parse_lines(lines)

Parse a sequence of lines with merge conflicts.

Parameters

lines (Sequence[str]) – The sequence of lines to be parsed.

Yields

Pairs, where first item in each pair is a line in our version, and the second, in their version. An item is None if the line does not occur in that version.

Raises

ValueError – A conflict marker was not terminated.

Return type

Iterator[Tuple[Optional[str], Optional[str]]]

poetry_merge_lock.parser.tokenize(line)

Return the token for the line.

Parameters

line (str) –

Return type

poetry_merge_lock.parser.Token

poetry_merge_lock.mergetool

Merge tool for Poetry lock files at the TOML level.

exception poetry_merge_lock.mergetool.MergeConflictError(keys, ours, theirs)

An item in the TOML document cannot be merged.

Parameters
  • keys (List[tomlkit.items.Key]) –

  • ours (Any) –

  • theirs (Any) –

Return type

None

poetry_merge_lock.mergetool.merge(value, other)

Merge two versions of lock data.

This function returns a TOML document with the following merged entries:

  • package

  • metadata.files

Any other entries, e.g. metadata.content-hash, are omitted. They are generated from pyproject.toml when the lock data is written to disk.

Parameters
  • value (tomlkit.toml_document.TOMLDocument) – Our version of the lock data.

  • other (tomlkit.toml_document.TOMLDocument) – Their version of the lock data.

Returns

The merged lock data.

Return type

tomlkit.toml_document.TOMLDocument

poetry_merge_lock.mergetool.merge_locked_package_files(value, other)

Merge two TOML tables containing package files.

Parameters
  • value (tomlkit.items.Table) – The package files in our version of the lock file.

  • other (tomlkit.items.Table) – The package files in their version of the lock file.

Returns

The package files obtained from merging both versions.

Raises

MergeConflictError – The tables contain different files for the same package.

Return type

tomlkit.items.Table

poetry_merge_lock.mergetool.merge_locked_packages(value, other)

Merge two TOML arrays containing locked packages.

Parameters
  • value (List[tomlkit.items.Table]) – The packages in our version of the lock file.

  • other (List[tomlkit.items.Table]) – The packages in their version of the lock file.

Returns

The packages obtained from merging both versions.

Raises

MergeConflictError – The lists contain different values for the same package.

Return type

List[tomlkit.items.Table]