Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#72 🐛 remove custom monorepo group to allow transitive dependenci… #100

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mvn/maven-build-cache-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</glob>
<includes>
<include>src/</include>
<include>tests/</include>
<include>pom.xml</include>
<include>pyproject.toml</include>
</includes>
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,9 @@ Habushu will replace invocations of Poetry's `build` and `publish` commands with
`poetry-monorepo-dependency-plugin`, which are `build-rewrite-path-deps` and `publish-rewrite-path-deps`, respectively.

To further ease working with monorepo dependencies, Habushu will specially handle how these dependencies are written to
intermediate `requirements.txt` exports if they are included in the `[tool.poetry.group.monorepo.dependencies]` group
within your `pyproject.toml` file. In this case, the dependencies will be excluded from the export unless `rewriteLocalPathDepsInArchives`
is set to true. This feature can be useful if installing the exported `requirements.txt` on another machine and/or
Docker container. If a monorepo dependency is not included in this specific group, it will be exported with a local path.
intermediate `requirements.txt` exports. In this case, the dependencies will be excluded from the export unless
`rewriteLocalPathDepsInArchives` is set to true. This feature can be useful if installing the exported
`requirements.txt` on another machine and/or Docker container.

Typically, this flag will only be `true` when deploying/releasing Habushu modules within a CI environment that are part of a monorepo project
structure which multiple Poetry projects depend on one another.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@Mojo(name = "build-deployment-artifacts", defaultPhase = LifecyclePhase.PACKAGE)
public class BuildDeploymentArtifactsMojo extends AbstractHabushuMojo {

public static final String TOOL_POETRY_GROUP_MONOREPO_DEPENDENCIES = "tool.poetry.group.monorepo.dependencies";
/**
* By default, export requirements.txt file.
*/
Expand Down Expand Up @@ -96,7 +95,6 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
if (exportRequirementsFile) {
getLog().info("Exporting requirements.txt file...");

String outputFile = exportRequirementsFolder + "/requirements.txt";
File directory = new File(exportRequirementsFolder);
if (!directory.exists()) {
directory.mkdir();
Expand All @@ -105,16 +103,9 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
List<String> command = new ArrayList<>();
command.add("export");
command.add("--output");
String outputFile = exportRequirementsFolder + "/requirements.txt";
command.add(outputFile);

List<String> customPoetryToolGroups = findCustomToolPoetryGroups();
if (!rewriteLocalPathDepsInArchives && customPoetryToolGroups.contains(TOOL_POETRY_GROUP_MONOREPO_DEPENDENCIES)) {
command.add("--without");
command.add("monorepo");
logLocalMonorepoCaveats();
}


if (!exportRequirementsWithHashes) {
command.add("--without-hashes");
}
Expand All @@ -129,23 +120,6 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
}
}

private void logLocalMonorepoCaveats() {
getLog().info(String.format("Excluding [%s] to prevent path references in requirements.txt",
TOOL_POETRY_GROUP_MONOREPO_DEPENDENCIES));
getLog().info("The following dependencies must be install manually if using requirements.txt (e.g., pip install needed-dependency.whl):");

try (FileConfig pyProjectConfig = FileConfig.of(getPoetryPyProjectTomlFile())) {
pyProjectConfig.load();
Optional<Config> packageSources = pyProjectConfig.getOptional(TOOL_POETRY_GROUP_MONOREPO_DEPENDENCIES);
if (packageSources.isPresent()) {
Config monoRepoDependencies = packageSources.get();
for (String dependencyKey : monoRepoDependencies.valueMap().keySet()) {
getLog().info(String.format("\t- %s", dependencyKey));
}
}
}
}

protected void setUpPlaceholderFileAsMavenArtifact() {
mavenArtifactFile.getParentFile().mkdirs();
try (PrintWriter writer = new PrintWriter(mavenArtifactFile)) {
Expand Down
2 changes: 1 addition & 1 deletion habushu-mixology-consumer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "habushu_mixology_consumer"
version = "2.11.1"
version = "2.12.0.dev"
description = "Example of how to use the habushu-maven-plugin to consume other Habushu modules"
authors = ["Eric Konieczny <[email protected]>"]
license = "MIT License"
Expand Down
12 changes: 12 additions & 0 deletions habushu-mixology-consumer/tests/features/steps/unpack_deps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from behave import *
from krausening.properties import PropertyManager
from habushu_mixology_consumer.nested.simple_dependency import (
call_worker_from_nested_dir,
)
Expand All @@ -13,3 +14,14 @@ def step_impl(context):
def step_impl(context):
print(context.result)
assert "nested so useful!" == context.result


@when("I reference krausening transitively from habushu-mixology")
def step_impl(context):
context.result = call_worker_from_nested_dir()


@then("I can access it in habushu-mixology-consumer without further intervention")
def step_impl(context):
property_manager = PropertyManager.get_instance()
assert property_manager is not None
4 changes: 3 additions & 1 deletion habushu-mixology-consumer/tests/features/unpack-deps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ Feature: Verify that dependencies get unpacked correctly for tests
When I reference a dependency in my python code
Then the build can successfully execute the tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I (Informational): just adding a test to catch any future regression where transitive dependencies don't make it into the project. Not a likely scenario, but at least there is a trip wire.


Scenario: Files can reference transitive dependencies and build successfully
When I reference krausening transitively from habushu-mixology
Then I can access it in habushu-mixology-consumer without further intervention
2 changes: 1 addition & 1 deletion habushu-mixology/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "habushu_mixology"
version = "2.11.1"
version = "2.12.0.dev"
description = "Example of how to use the habushu-maven-plugin"
authors = ["Eric Konieczny <[email protected]>"]
license = "MIT License"
Expand Down
Loading