Package: hatch-min-requirements
hatch-min-requirementsHatchling plugin to create optional-dependencies pinned to minimum versionsRationaleWhen creating a library, it is often useful to specify the minimum version of a
dependency that is required.  However, pip's default behavior is to install thelatestversion of a package that satisfies your requirement.  As a result, if
aren't carefully testing your minimum dependencies, you may inadvertently
introduce changes to your package that are not compatible with the minimum
version you specified.This plugin will inspect your packages dependencies and dynamically add an extra
(namedmin-reqsby default) to theproject.optional-dependenciestable of
yourpyproject.tomlfile.  This extra will contain all of your dependendencies
pinned to theirminimumversion.This makes it easy to test your package against your minimum stated dependencies
on CI, or to install your package with the minimum dependencies for local
development.UsageIn yourpyproject.tomlmake the following changes:Appendhatch-min-requirementsto[build-system.requires].Add a[tool.hatch.metadata.hooks.min_requirements]table.[build-system]requires=["hatchling","hatch-min-requirements"]build-backend="hatchling.build"[tool.hatch.metadata.hooks.min_requirements]Then, you caninstall your package using themin-reqsextraand it will
dynamically use the minimum compatible versions of your dependencies.pipinstall-e.[min-reqs]Environment variablesEnvironment variables can be used to configure the behavior.
Described in detail below:VariableDefaultDescriptionMIN_REQS_EXTRA_NAMEmin-reqsThe name of the extra to add topyproject.tomlMIN_REQS_PIN_UNCONSTRAINEDTruePin unconstrained dependencies to minimum available version on PyPI. (e.g.numpy->numpy==1.3.0)MIN_REQS_OFFLINEFalseDo not connect to PyPI to fetch available versionsMIN_REQS_TRY_PIPTrueUsepipto fetch available versions in online mode.  Set to0to use stdlib tools onlyUtilitiesThis package provides two convenience functions that can be used directly
(without being a hatch plugin).hatch_min_requirements.sub_min_compatible_versionTakes a pip requirement string and returns a new requirement string with the
minimum compatible version substituted in.>>>sub_min_compatible_version("numpy")'numpy==1.3.0'>>>sub_min_compatible_version("numpy>=1.4.1")'numpy==1.4.1'>>>sub_min_compatible_version("numpy>1.3")'numpy==1.4.1'>>>sub_min_compatible_version("numpy[extra1,extra2]>=1.20,<2.0")'numpy[extra1,extra2]==1.20.0'>>>sub_min_compatible_version("numpy[extra]<2; python_version == '3.6'")"numpy[extra]==1.3.0 ; python_version == '3.6'"hatch_min_requirements.patch_pyprojectTakes a path to apyproject.tomlfile and patches it to include themin-reqsextra.  The original file is backed up with a.BAKextension.>>>patch_pyproject("path/to/pyproject.toml")ConsiderationsDependencies with no constraintsIn cases of dependencies declared without constraints (e.g.foo), the pluginwillsearch for the minimum available version of the package from PyPI. The
goal here is to encourageaccuraterequirement pinning. If you want to disable
this behavior and leave unconstrained specifiers as is, you can either set theMIN_REQS_PIN_UNCONSTRAINEDenvironment variable to0orFalse, or use
offline mode withMIN_REQS_OFFLINE=1(see below).Offline ModeIn cases such as upper-bounds (<X.Y), non-inclusive lower bounds (>X.Y), and
exclusions (!=X.Y), it's not possible to declare a minimum version without
fetching available versions from PyPI.  By default, this pluginwillattempt
to connect to PyPI in order to determine compatible minimum version strings.  If
you want to disable this behavior, you can set theMIN_REQS_OFFLINEenvironment variable to1orTrue.MIN_REQS_OFFLINE=1pipinstall-e.[min-reqs]In offline mode, no attempt is made to guess the next compatible version of a
package after a non-inclusive lower bound.  Instead, the plugin will simply use
your dependency as stated (meaning you won't be testing lower bounds).  If you
want to test lower bounds without connecting to PyPI, you should pin your
dependencies withinclusivelower bounds:[project]
dependencies = [
    "foo>=1.2.3"  # will be pinned to "foo==1.2.3"
    "baz~=1.2"    # will be pinned to "baz==1.2"
    "bar>1.2.3"   # will be unchanged
]Usage of pip vs standard-lib toolsFetching the available versions of a package is not trivial, andpipis thede factotool for doing so.  Ifpipis available in the build environment,
this plugin will use it to fetch the available versions of a package. But, you
must opt in to this behavior by addingpipto yourbuild-system.requiresinpyproject.toml:[build-system]requires=["hatchling","hatch-min-requirements","pip"]To explicitly opt out of using pip (even if it's available) and use standard library tools only, you can
set theMIN_REQS_TRY_PIPenvironment variable to0orFalse.TODOaddofflineandno-pipoptions to themin_requirementstable in
pyproject