Skip to content

Commit

Permalink
#39 ⬆️ update default python version from 3.9.16 to 3.11.4 so ensure …
Browse files Browse the repository at this point in the history
…latest binary installer is available; ✨ catch poetry check error and perform remediation
  • Loading branch information
d-ryan-ashcraft committed Aug 24, 2023
1 parent eaeeecb commit 4ff66d3
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mvn clean install -Dhabushu.pythonVersion=3.10.4

The desired version of Python to use. Habushu delegates to `pyenv` for managing versions of Python depending on the configuration `usePyenv`.

Default: `3.9.13`
Default: `3.11.4`

#### usePyenv ####

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,35 @@ public class InitializeHabushuMojo extends AbstractHabushuMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

getLog().info("Validating Poetry-based project structure...");
PoetryCommandHelper poetryHelper = createPoetryCommandHelper();
poetryHelper.execute(Arrays.asList("check"));

String currentPythonPackageVersion = poetryHelper.execute(Arrays.asList("version", "-s"));
String pomVersion = project.getVersion();
String expectedPythonPackageVersion = getPythonPackageVersion(pomVersion, false, null);

if (!StringUtils.equals(currentPythonPackageVersion, expectedPythonPackageVersion)) {
if (overridePackageVersion) {
getLog().info(String.format("Setting Poetry package version to %s", expectedPythonPackageVersion));
getLog().info(
"If you do *not* want the Poetry package version to be automatically synced with the POM version, set <overridePackageVersion>false</overridePackageVersion> in the plugin's <configuration>");
poetryHelper.executeAndLogOutput(Arrays.asList("version", expectedPythonPackageVersion));
} else {
getLog().debug(String.format(
"Poetry package version set to %s in pyproject.toml does not align with expected POM-derived version of %s",
currentPythonPackageVersion, expectedPythonPackageVersion));
}

}
getLog().info("Validating Poetry-based project structure...");
PoetryCommandHelper poetryHelper = createPoetryCommandHelper();
try {
poetryHelper.execute(Arrays.asList("check"));
} catch (HabushuException e) {
getLog().debug("Failure encountered while running 'poetry check'!", e);
getLog().warn("poetry check failed (debug contains more details) - this is likely due to a "
+ "mismatch between your pyproject.toml and poetry.lock file - attempting to correct...");
poetryHelper.execute(Arrays.asList("lock", "--no-update"));
getLog().warn("Corrected - pyproject.toml and poetry.lock now synced");
}

String currentPythonPackageVersion = poetryHelper.execute(Arrays.asList("version", "-s"));
String pomVersion = project.getVersion();
String expectedPythonPackageVersion = getPythonPackageVersion(pomVersion, false, null);

if (!StringUtils.equals(currentPythonPackageVersion, expectedPythonPackageVersion)) {
if (overridePackageVersion) {
getLog().info(String.format("Setting Poetry package version to %s", expectedPythonPackageVersion));
getLog().info(
"If you do *not* want the Poetry package version to be automatically synced with the POM version, set <overridePackageVersion>false</overridePackageVersion> in the plugin's <configuration>");
poetryHelper.executeAndLogOutput(Arrays.asList("version", expectedPythonPackageVersion));
} else {
getLog().debug(String.format(
"Poetry package version set to %s in pyproject.toml does not align with expected POM-derived version of %s",
currentPythonPackageVersion, expectedPythonPackageVersion));
}

}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PyenvAndPoetrySetup {
* Specifies the semver compliant requirement for the default version of Python that
* must be installed and available for Habushu to use.
*/
static final String PYTHON_DEFAULT_VERSION_REQUIREMENT = "3.9.16";
static final String PYTHON_DEFAULT_VERSION_REQUIREMENT = "3.11.4";

/**
* Specifies the semver compliant requirement for the version of Poetry that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public void replace_development_version_is_disabled() {
mojo.overridePackageVersion = false;
}

@When("Habushu executes")
public void habushu_executes() throws Exception {
@When("Habushu dependency management executes")
public void habushu_dependency_management_executes() throws Exception {
try {
mojo.processManagedDependencyMismatches();
} catch (HabushuException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.technologybrewery.habushu;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;

public class PythonVersionManagementSteps {

@Given("no explicitly specified Python version is provided")
public void no_explicitly_specified_python_version_is_provided() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}

@Given("an explicitly specified Python version is configured")
public void an_explicitly_specified_python_version_is_configured() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}

@Then("Habushu's default version of Python is leveraged")
public void habushu_s_default_version_of_python_is_leveraged() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
@Then("the configured version is leveraged")
public void the_configured_version_is_leveraged() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ Feature: Test dependency management capabilities to help align package versions

Scenario: Dependency management is not enabled if no dependency management entries are specified
Given a Habushu configuration with no dependency management entries
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has no updates

Scenario: Dependency management makes no changes are made if managed dependencies are found but disabled
Given a Habushu configuration with dependency management entries
And update managed dependencies when found is disabled
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has no updates

Scenario: The build stops if configured to fail when dependency management changes are needed
Given a Habushu configuration with dependency management entries
And fail on managed dependency mismatches is enabled
When Habushu executes
When Habushu dependency management executes
Then the build process is halted

Scenario Outline: [tool.poetry.dependencies] dependency is changed when managed and not matching current value
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has updates

Examples:
Expand All @@ -30,7 +30,7 @@ Feature: Test dependency management capabilities to help align package versions

Scenario Outline: [tool.poetry.dev-dependencies] dependency is changed when managed and not matching current value
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has updates

Examples:
Expand All @@ -43,7 +43,7 @@ Feature: Test dependency management capabilities to help align package versions

Scenario Outline: [tool.poetry.group.<group>] dependency is changed when managed and not matching current value
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has updates

Examples:
Expand All @@ -55,7 +55,7 @@ Feature: Test dependency management capabilities to help align package versions

Scenario: Inactive managed dependencies are skipped
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has updates

Examples:
Expand All @@ -66,7 +66,7 @@ Feature: Test dependency management capabilities to help align package versions

Scenario: SNAPSHOT managed dependencies get corrected to dev dependencies by default with Poetry version 1.5.0 + (overridePackageVersion is true)
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>" and "<poetryVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file is updated to contain "<package>" and "<updatedOperatorAndVersion>"

Examples:
Expand All @@ -76,7 +76,7 @@ Feature: Test dependency management capabilities to help align package versions

Scenario: SHIM - SNAPSHOT managed dependencies get corrected to ^ dev dependencies with any Poetry version and a ^ in the version (overridePackageVersion is true)
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>" and "<poetryVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file is updated to contain "<package>" and "<updatedOperatorAndVersion>"

Examples:
Expand All @@ -89,7 +89,7 @@ Feature: Test dependency management capabilities to help align package versions
Scenario: SNAPSHOT managed dependencies do NOT get corrected to dev dependencies when overridePackageVersion is false
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>"
And replace development version is disabled
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file is updated to contain "<package>" and "<operatorAndVersion>"

Examples:
Expand All @@ -99,7 +99,7 @@ Feature: Test dependency management capabilities to help align package versions

Scenario: Skip altering local development versions when processing SNAPSHOT managed dependencies
Given a Habushu configuration with a managed dependency of "<package>" and "<operatorAndVersion>"
When Habushu executes
When Habushu dependency management executes
Then the pyproject.toml file has no updates

Examples:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Python version management via Habushu

# Scenario: By default, Habushu's preferred Python version is leveraged
# Given no explicitly specified Python version is provided
# When Habushu executes
# Then Habushu's default version of Python is leveraged
#
# Scenario: Habushu's default version of Python is overridden with a customized version
# Given an explicitly specified Python version is configured
# When Habushu executes
# Then the configured version is leveraged
2 changes: 1 addition & 1 deletion habushu-mixology-consumer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Eric Konieczny <[email protected]>"]
license = "MIT License"

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.11"
habushu-mixology = {path = "../habushu-mixology", develop = true}

[tool.poetry.dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion habushu-mixology/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Eric Konieczny <[email protected]>"]
license = "MIT License"

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.11"
krausening = "17"
cryptography = "^41.0.3"
uvicorn = {version = "^0.18.0", extras = ["standard"]}
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<tag>HEAD</tag>
</scm>

<properties>
<!-- override parent POM until it is next upgrade (arguably, this property should not be in parent at all: -->
<version.python.default>3.11.4</version.python.default>
</properties>

<dependencyManagement>
<dependencies>
<!-- Explicitly upgrading transitive dependency for habushu-maven-plugin
Expand Down

0 comments on commit 4ff66d3

Please sign in to comment.