-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #17 - Partial complete work to add removing of path dependencies invocations * #17 - Adding back original commands so they stay intact * #17 - modifying export command behavior * #17 - modifying export command intercept logic * #17 - modifying export intercept debug mode * #17 - removing unneeded built in export command imports * #17 - correcting spelling in README and adding export to enable verbiage
- Loading branch information
1 parent
d63b869
commit 534db6a
Showing
7 changed files
with
163 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/poetry_monorepo_dependency_plugin/path_dependency_remover.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import typing | ||
|
||
from cleo.io.io import IO as cleoIO | ||
import cleo.io.outputs.output | ||
from poetry.core.pyproject.toml import PyProjectTOML | ||
from poetry.core.constraints.version import Version | ||
from poetry.core.packages.dependency import Dependency | ||
from poetry.core.packages.directory_dependency import DirectoryDependency | ||
from poetry.core.packages.dependency_group import DependencyGroup | ||
|
||
|
||
class PathDependencyRemover: | ||
""" | ||
Exposes core functionality for gathering a pyproject.toml's path dependencies, | ||
determining if they are Poetry projects, and if so, extracting the corresponding | ||
dependency. | ||
""" | ||
|
||
def update_dependency_group( | ||
self, | ||
io: cleoIO, | ||
pyproject: PyProjectTOML, | ||
dependency_group: DependencyGroup, | ||
) -> None: | ||
""" | ||
Removes all path dependencies to Poetry projects. | ||
:param io: instance of Cleo IO that may be used for logging diagnostic output during | ||
plugin execution | ||
:param pyproject: encapsulates the pyproject.toml of the current project for which | ||
path dependencies will be rewritten | ||
:param dependency_group: specifies the dependency group from which to pin path | ||
dependencies, this will usually be "main" | ||
:return: none | ||
""" | ||
io.write_line( | ||
"Updating dependency constraints...", | ||
verbosity=cleo.io.outputs.output.Verbosity.DEBUG, | ||
) | ||
|
||
for dependency in dependency_group.dependencies: | ||
if not isinstance( | ||
dependency, | ||
DirectoryDependency, | ||
): | ||
continue | ||
|
||
io.write_line( | ||
f" • Removing {dependency.name} path dependency)", | ||
verbosity=cleo.io.outputs.output.Verbosity.DEBUG, | ||
) | ||
|
||
dependency_group.remove_dependency(dependency.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: Remove path dependencies from Poetry projects | ||
|
||
Scenario Outline: Remove project dependencies with paths | ||
Given a project with a local path dependencies to other Poetry projects | ||
When the project is exported using the plugin's command-line mode | ||
Then the path dependencies for "<dependency name>" are removed from poetry dependencies | ||
Examples: | ||
| dependency name | ||
| spam | ||
| spam | ||
| spam | ||
| ham | ||
| ham | ||
| ham | ||
| eggs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest.mock | ||
import unittest | ||
from pathlib import Path | ||
|
||
import cleo.io.io | ||
import poetry.core.factory | ||
from behave import * | ||
import nose.tools as nt | ||
|
||
from poetry_monorepo_dependency_plugin.path_dependency_remover import ( | ||
PathDependencyRemover, | ||
) | ||
|
||
|
||
@when("the project is exported using the plugin's command-line mode") | ||
def step_impl(context): | ||
path_dependency_remover = PathDependencyRemover() | ||
mock_io = unittest.mock.create_autospec(cleo.io.io.IO) | ||
path_dependency_remover.update_dependency_group( | ||
mock_io, | ||
context.project_with_local_deps.pyproject, | ||
context.project_with_local_deps.package.dependency_group("main"), | ||
) | ||
|
||
|
||
@then( | ||
'the path dependencies for "{dependency_name}" are removed from poetry dependencies' | ||
) | ||
def step_impl(context, dependency_name): | ||
mydependencies = context.project_with_local_deps.package.dependency_group( | ||
"main" | ||
).dependencies | ||
|
||
nt.assert_not_in( | ||
dependency_name, | ||
mydependencies, | ||
f"Found the path dependency {dependency_name}", | ||
) |