requirementslib.models.lockfile module

class requirementslib.models.lockfile.Lockfile(path: pathlib.Path = NOTHING, requirements: list = NOTHING, dev_requirements: list = NOTHING, projectfile: requirementslib.models.project.ProjectFile = NOTHING, lockfile: plette.lockfiles.Lockfile = NOTHING, newlines: str = 'n')[source]

Bases: object

as_requirements(include_hashes=False, dev=False)[source]

Returns a list of requirements in pip-style format

classmethod create(path, create=True)[source]
default
dev_requirements
dev_requirements_list
develop
extended_keys
classmethod from_data(path, data, meta_from_project=True)[source]

Create a new lockfile instance from a dictionary.

Parameters:
  • path (str) – Path to the project root.
  • data (dict) – Data to load into the lockfile.
  • meta_from_project (bool) – Attempt to populate the meta section from the project root, default True.
get(k)[source]
get_deps(dev=False, only=True)[source]
get_requirements(dev=True, only=False)[source]

Produces a generator which generates requirements from the desired section.

Parameters:dev (bool) – Indicates whether to use dev requirements, defaults to False
Returns:Requirements from the relevant the relevant pipfile
Return type:Requirement
classmethod load(path, create=True)[source]

Create a new lockfile instance.

Parameters:
  • project_path (str or pathlib.Path) – Path to project root or lockfile
  • lockfile_name (str) – Name of the lockfile in the project root directory
  • pipfile_path (pathlib.Path) – Path to the project pipfile
Returns:

A new lockfile representing the supplied project paths

Return type:

Lockfile

classmethod load_projectfile(path, create=True, data=None)[source]

Given a path, load or create the necessary lockfile.

Parameters:
  • path (str) – Path to the project root or lockfile
  • create (bool) – Whether to create the lockfile if not found, defaults to True
Raises:
  • OSError – Thrown if the project root directory doesn’t exist
  • FileNotFoundError – Thrown if the lockfile doesn’t exist and create=False
Returns:

A project file instance for the supplied project

Return type:

ProjectFile

lockfile
classmethod lockfile_from_pipfile(pipfile_path)[source]
newlines
path
projectfile
classmethod read_projectfile(path)[source]

Read the specified project file and provide an interface for writing/updating.

Parameters:path (str) – Path to the target file.
Returns:A project file with the model and location for interaction
Return type:ProjectFile
requirements
requirements_list
section_keys
write()[source]
requirementslib.models.lockfile.preferred_newlines(f)[source]