Package: poetry-lock-groups-plugin
DEPRECATION NOTICEWarning- this plugin has beendeprecated.  Developers should instead consider using thepoetry-monorepo-dependency-pluginto support deploying and releasing Poetry projects with path-based dependencies on other Poetry projects within a monorepo.Overviewpoetry-lock-groups-pluginis a lightweight plugin which enables Poetry'sdependency groupoptions
(--with,--without,--only) when executing thelockcommand.  Broadly, this plugin helps enable a solution pattern that developers may use when working with and releasing
packages within a more complex Python monorepo environment that relies on path-based dependencies.InstallationExecute the following command:poetryselfaddpoetry-lock-groups-pluginUse CaseWhen working within a Python monorepo project structure withlocal path dependencies, a frequently encountered challenge involves publishing these packages to a PyPI index in a way that can be easily utilized by downstream consumers.  Specifically, while editable path dependencies work well to support normal development activities, publishing a package with local path dependencies into a usablesdistorwheelarchive typically involves replacing those path dependencies with references to packages that are resolvable within a PyPI repository.In order to support this scenario, rather than maintaining two distinct versions ofpyproject.toml(one with local path dependencies and the other with PyPI resolvable dependencies), developers may leverage dependency groups. Vanilla Poetry recognizes dependency groups only at theinstallphase - by advancing that recognition to thelockstage, we enable predictable, flexible patterns to support monorepo development.ExampleGiven the followingpyproject.tomlwheremy-poetry-projectdepends oncommon-librarywithin the same monorepo project structure:[tool.poetry]name="my-poetry-project"version="0.1.0.dev"description=""[tool.poetry.dependencies]python="^3.9"[tool.poetry.plugins."poetry.application.plugin"]lock-groups-plugin="poetry_lock_groups.plugin:LockGroupsPlugin"[tool.poetry.group.remote.dependencies]common-library="^1.2.6"[tool.poetry.group.local.dependencies]common-library={path="../../common-library/"}[build-system]requires=["poetry-core>=1.2"]build-backend="poetry.core.masonry.api"By running the following command:poetrylock--withremote--withoutlocalThis will generate apoetry.lockfile that includes the dependency definitions within theremotegroup, but without those in thelocalgroup.  Note that if we included both groups, or simply refrained from specifying group usages, we would see behavior
identical to that in vanilla Poetry, which is, in this case, undefined.Developers will typically execute the following commands as a part of their development workflow while building/testing functionality:poetrylock--withlocal--withoutremote
poetryinstall--withlocal--withoutremoteHowever, when performing releases, developers will execute the following to ensure that local path dependencies are removed from archives that are published to the configured PyPI repository:poetrylock--withremote--withoutlocalpoetryinstall--withremote--withoutlocalConsider usingHabushuto codify and automate this workflow!Usage ConsiderationsNote that the following sequence of commands may fail:poetrylock--withoutlocalpoetryinstall--withlocalThis is because thepoetry installcommand searchespoetry.lockto install dependencies. By building the lock file without thelocalgroup, any dependencies that exist only within that group will have no known sources, rendering them unresolvable.poetry-lock-groups-pluginonlymodifies lock operations initiated via thelockcommand.  It makes no attempt to modify behavior resulting from an implied lock, such as when runningpoetry installwithout having already created a lock file.Alternative ApproachesInstead of using dependency groups as described above to capture local path dependencies in a monorepo project, developers may consider using thepoetry-stickywheel-pluginor other similar approach to dynamically re-writepyproject.tomlon archive deployment with local path dependency declarations appropriately replaced.Releasing to PyPIReleasingpoetry-lock-groups-pluginleverages themaven-release-pluginto automate release preparation and delegates to thehabushu-maven-pluginto publish the package to PyPI during thedeployphase.  APyPI accountwith access to thepoetry-lock-groups-pluginproject is required. PyPI account credentials should be specified in yoursettings.xmlunder the<id>pypi</id><server>entry:<settings><servers><server><id>pypi</id><username>pypi-username</username><password>pypi-password</password></server></servers></settings>