From 433ad949e8c44f26d8268da2d4def426a7319a8c Mon Sep 17 00:00:00 2001 From: Satish Manda <> Date: Fri, 1 Dec 2023 16:35:56 -0500 Subject: [PATCH] #66 Added functionality to upgrade the poetry-core version required by the Habushu --- .../habushu/PyenvAndPoetrySetup.java | 11 +- .../CustomPoetrycoreVersionMigration.java | 162 ++++++++++++++++++ .../habushu/util/PoetryUtil.java | 18 ++ .../habushu/util/TomlUtils.java | 63 +++++++ .../src/main/resources/migrations.json | 9 + .../PoetrycoreVersionMigrationSteps.java | 94 ++++++++++ .../with-poetry-core-version-1-0-0.toml | 22 +++ .../with-poetry-core-version-1-6-0.toml | 22 +++ .../with-poetry-core-version-1-7-0.toml | 22 +++ .../with-poetry-core-version-2-0-0.toml | 22 +++ .../poetry-core-version-migration.feature | 23 +++ 11 files changed, 460 insertions(+), 8 deletions(-) create mode 100644 habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/migration/CustomPoetrycoreVersionMigration.java create mode 100644 habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/PoetryUtil.java create mode 100644 habushu-maven-plugin/src/test/java/org/technologybrewery/habushu/migration/PoetrycoreVersionMigrationSteps.java create mode 100644 habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-0-0.toml create mode 100644 habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-6-0.toml create mode 100644 habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-7-0.toml create mode 100644 habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-2-0-0.toml create mode 100644 habushu-maven-plugin/src/test/resources/specifications/poetry-core-version-migration.feature diff --git a/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/PyenvAndPoetrySetup.java b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/PyenvAndPoetrySetup.java index e8e91a6..f39c4aa 100644 --- a/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/PyenvAndPoetrySetup.java +++ b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/PyenvAndPoetrySetup.java @@ -11,6 +11,7 @@ import org.technologybrewery.habushu.exec.PoetryCommandHelper; import org.technologybrewery.habushu.exec.PyenvCommandHelper; import org.technologybrewery.habushu.exec.PythonVersionHelper; +import org.technologybrewery.habushu.util.PoetryUtil; import java.io.File; import java.util.ArrayList; @@ -34,12 +35,6 @@ class PyenvAndPoetrySetup { */ static final String PYTHON_DEFAULT_VERSION_REQUIREMENT = "3.11.4"; - /** - * Specifies the semver compliant requirement for the version of Poetry that - * must be installed and available for Habushu to use. - */ - protected static final String POETRY_VERSION_REQUIREMENT = "^1.5.0"; - /** * The desired version of Python to use. */ @@ -129,10 +124,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { } else { Semver poetryVersionSemver = new Semver(poetryInstallStatusAndVersion.getRight(), SemverType.NPM); - if (!poetryVersionSemver.satisfies(POETRY_VERSION_REQUIREMENT)) { + if (!poetryVersionSemver.satisfies(PoetryUtil.POETRY_VERSION_REQUIREMENT)) { missingRequiredToolMsgs.add(String.format( "Poetry version %s was installed - Habushu requires that installed version of Poetry satisfies %s. Please update Poetry by executing 'poetry self update' or visit https://python-poetry.org/docs/#installation for more information", - poetryInstallStatusAndVersion.getRight(), POETRY_VERSION_REQUIREMENT)); + poetryInstallStatusAndVersion.getRight(), PoetryUtil.POETRY_VERSION_REQUIREMENT)); } else { log.info("Found Poetry " + poetryInstallStatusAndVersion.getRight()); } diff --git a/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/migration/CustomPoetrycoreVersionMigration.java b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/migration/CustomPoetrycoreVersionMigration.java new file mode 100644 index 0000000..2d2aa59 --- /dev/null +++ b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/migration/CustomPoetrycoreVersionMigration.java @@ -0,0 +1,162 @@ +package org.technologybrewery.habushu.migration; + +import com.electronwill.nightconfig.core.CommentedConfig; +import com.electronwill.nightconfig.core.Config; +import com.electronwill.nightconfig.core.file.FileConfig; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.technologybrewery.baton.AbstractMigration; +import org.technologybrewery.baton.BatonException; +import org.technologybrewery.habushu.HabushuException; +import org.technologybrewery.habushu.util.TomlReplacementTuple; +import org.technologybrewery.habushu.util.TomlUtils; +import org.technologybrewery.habushu.util.PoetryUtil; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + + +/** + * Automatically migrates Poetry-core version in the [build-system] group to the + * version where the major version and minor version are inline with the + * Poetry-core version required by Habushu defined by the POETRY_CORE_VERSION_REQUIREMENT in the + * PoetryUtil. As noted in the project's README.md, this prevents these dependencies from causing issues + * when Poetry projects are exported in development releases. + */ +public class CustomPoetrycoreVersionMigration extends AbstractMigration { + + public static final Logger logger = LoggerFactory.getLogger(CustomPoetrycoreVersionMigration.class); + + protected Map replacements = new HashMap<>(); + + private boolean isMajorVersionUpdateRequired; + private boolean isMinorVersionUpdateRequired; + + @Override + protected boolean shouldExecuteOnFile(File file) { + try (FileConfig tomlFileConfig = FileConfig.of(file)) { + tomlFileConfig.load(); + Optional toolBuildSystem = tomlFileConfig.getOptional(TomlUtils.BUILD_SYSTEM); + if (toolBuildSystem.isPresent()) { + Config buildSystem = toolBuildSystem.get(); + Map dependencyMap = buildSystem.valueMap(); + for (Map.Entry dependency : dependencyMap.entrySet()) { + isMajorVersionUpdateRequired = false; + isMinorVersionUpdateRequired = false; + // check if we need to upgrade the poetry-core version. + if(isPoetrycoreUpgradeRequired(dependency)) { + return true; + } + } + } + } + return false; + } + + @Override + protected boolean performMigration(File pyProjectTomlFile) { + String fileContent = StringUtils.EMPTY; + try (BufferedReader reader = new BufferedReader(new FileReader(pyProjectTomlFile))) { + String line = reader.readLine(); + while (line != null) { + boolean isEmptyLine = line.isBlank(); + + if (line.contains(StringUtils.SPACE) && line.contains(TomlUtils.EQUALS)) { + String key = line.substring(0, line.indexOf(StringUtils.SPACE)); + if (key == null) { + key = line.substring(0, line.indexOf(TomlUtils.EQUALS)); + } + + if (key != null) { + key = key.strip(); + + TomlReplacementTuple matchedTuple = replacements.get(key); + if ((matchedTuple != null) && (line.contains(TomlUtils.POETRY_CORE)) && (line.contains(TomlUtils.EQUALS))) { + // update the poetry-core major version upgrade if required. + StringBuilder stringBuilder = new StringBuilder(line); + if(isMajorVersionUpdateRequired){ + int majorIndex = line.lastIndexOf(TomlUtils.EQUALS) + 1; + int endMajorIndex = line.indexOf(TomlUtils.DOT); + String poetryCoreReqMajorVer = TomlUtils.getMajorReqVersion(PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT); + stringBuilder = stringBuilder.replace(majorIndex, endMajorIndex, poetryCoreReqMajorVer); + line = stringBuilder.toString(); + logger.debug("Updating the Poetry-core major version to {}.", poetryCoreReqMajorVer); + } + + // update the poetry-core minor version if required. + if (isMinorVersionUpdateRequired) { + int minorVersionIndex = line.indexOf(TomlUtils.DOT) + 1; + int endMinorVersionIndex = line.lastIndexOf(TomlUtils.DOT); + String poetryCoreReqMinorVersion = TomlUtils.getMinorReqVersion(PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT); + stringBuilder = stringBuilder.replace(minorVersionIndex, endMinorVersionIndex, poetryCoreReqMinorVersion); + line = stringBuilder.toString(); + logger.debug("Updating the Poetry-core minor version to {}.", poetryCoreReqMinorVersion); + } + logger.info("Updated the Poetry-core version to {} required by Habushu.", PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT); + } + } + } + fileContent += line + "\n"; + line = reader.readLine(); + } + + } catch (IOException e) { + throw new HabushuException("Problem reading pyproject.toml while updating the build-sytem's Poetry-core version!", e); + } + + try { + TomlUtils.writeTomlFile(pyProjectTomlFile, fileContent); + } catch (IOException e) { + throw new BatonException("Problem while writing dependencies to TomlFile while updating the build-system's Poetry-core version!", e); + } + return true; + } + + private boolean isPoetrycoreUpgradeRequired(Map.Entry dependency) { + replacements.clear(); + String packageName = dependency.getKey(); + + if (packageName.equals(TomlUtils.REQUIRES)) { + String dependencyVal = dependency.getValue().toString(); + if (dependencyVal.contains(TomlUtils.POETRY_CORE) && dependencyVal.contains(TomlUtils.EQUALS)) { + String poetrycoreVer = dependencyVal.substring(TomlUtils.getIndexOfFirstDigit(dependencyVal), TomlUtils.getIndexOfLastDigit(dependencyVal)); + int endMajorVerIndex = poetrycoreVer.indexOf(TomlUtils.DOT); + int poetryCoreMajorVer = Integer.parseInt(poetrycoreVer.substring(0, endMajorVerIndex)); + int poetryCoreReqMajorVersion = Integer.parseInt(TomlUtils.getMajorReqVersion(PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT)); + + // if the major version is less than required major version then return true. + if(poetryCoreMajorVer < poetryCoreReqMajorVersion) { + isMajorVersionUpdateRequired = true; + isMinorVersionUpdateRequired = true; + } + + // Now check for the minor version. If the major version is equal to the required + // major version but if the minor version is less than the required minor version + // then upgrade for minor version is needed. + int minorVerIndex = poetrycoreVer.indexOf(TomlUtils.DOT) + 1; + int endMinorVerIndex = poetrycoreVer.lastIndexOf(TomlUtils.DOT); + int poetryCoreMinorVer = Integer.parseInt(poetrycoreVer.substring(minorVerIndex, endMinorVerIndex)); + int poetryCoreReqMinorVersion = Integer.parseInt(TomlUtils.getMinorReqVersion(PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT)); + + if ((poetryCoreMajorVer == poetryCoreReqMajorVersion && poetryCoreMinorVer < poetryCoreReqMinorVersion)) { + isMinorVersionUpdateRequired = true; + } + + // Return true if major or minor version upgarde is required. + if(isMajorVersionUpdateRequired || isMinorVersionUpdateRequired) { + TomlReplacementTuple replacementTuple = new TomlReplacementTuple(packageName, poetrycoreVer, "poetry-core>=1.6.0"); + replacements.put(packageName, replacementTuple); + logger.debug("Found build-system's Poetry-core version : {} less than the required version for Habushu. It will be updated to the required version of {}.", poetrycoreVer, PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT); + return true; + } + } + } + return false; + } +} diff --git a/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/PoetryUtil.java b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/PoetryUtil.java new file mode 100644 index 0000000..f50fe51 --- /dev/null +++ b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/PoetryUtil.java @@ -0,0 +1,18 @@ +package org.technologybrewery.habushu.util; + +/** + * Common utility methods for handling TOML Poetry. + */ +public final class PoetryUtil { + /** + * Specifies the semver compliant requirement for the version of Poetry that + * must be installed and available for Habushu to use. + */ + public static final String POETRY_VERSION_REQUIREMENT = "^1.5.0"; + + /** + * Specifies the semver compliant requirement for the version of Poetry-core that + * must be installed and available for Habushu to use. + */ + public static final String POETRY_CORE_VERSION_REQUIREMENT = "^1.6.0"; +} \ No newline at end of file diff --git a/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/TomlUtils.java b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/TomlUtils.java index f43359d..e9280f9 100644 --- a/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/TomlUtils.java +++ b/habushu-maven-plugin/src/main/java/org/technologybrewery/habushu/util/TomlUtils.java @@ -9,6 +9,9 @@ import java.io.Writer; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Common utility methods for handling TOML files. */ @@ -23,6 +26,12 @@ public final class TomlUtils { public static final String DEVELOP = "develop"; public static final String EXTRAS = "extras"; + public static final String BUILD_SYSTEM = "build-system"; + public static final String REQUIRES = "requires"; + public static final String POETRY_CORE ="poetry-core"; + public static final String DOT = "."; + + protected TomlUtils() { // prevent instantiation of all static class } @@ -107,4 +116,58 @@ private static void addCommaBetweenValues(int valuesRemaining, StringBuilder sb) } } + /** + * Finds and returns the index of the first digit in a given string. + * + * @param input string + * @return index of the first digit. If not found then it will return -1. + */ + public static int getIndexOfFirstDigit(String input) { + Pattern pattern = Pattern.compile("\\d"); + Matcher matcher = pattern.matcher(input); + if(matcher.find()){ + return matcher.start(); + } + return -1; + } + + /** + * Finds and returns the index of the last digit in a given string. + * + * @param input string + * @return index of the last digit. If not found then it will return -1. + */ + public static int getIndexOfLastDigit(String input) { + Pattern pattern = Pattern.compile("\\d"); + Matcher matcher = pattern.matcher(input); + int lastDigitIndex = -1; + while(matcher.find()){ + lastDigitIndex = matcher.end(); + } + return lastDigitIndex; + } + + /** + * Finds and returns the minor version in a given version string. + * + * @param input version string + * @return the minor version. + */ + public static String getMinorReqVersion(String version) { + int minorVerReqIndex = version.indexOf(TomlUtils.DOT) + 1; + int endMinorVerReqIndex = version.lastIndexOf(TomlUtils.DOT); + return version.substring(minorVerReqIndex, endMinorVerReqIndex); + } + + /** + * Finds and returns the major version in a given version string. + * + * @param input version string + * @return the major version. + */ + public static String getMajorReqVersion(String version) { + int majorVerReqIndex = getIndexOfFirstDigit(version); + int endMajorVerReqIndex = version.indexOf(TomlUtils.DOT); + return version.substring(majorVerReqIndex, endMajorVerReqIndex); + } } diff --git a/habushu-maven-plugin/src/main/resources/migrations.json b/habushu-maven-plugin/src/main/resources/migrations.json index 4371f69..b937f74 100644 --- a/habushu-maven-plugin/src/main/resources/migrations.json +++ b/habushu-maven-plugin/src/main/resources/migrations.json @@ -7,5 +7,14 @@ "includes": ["pyproject.toml"] } ] + }, + { + "name": "custom-poetry-core-version-migration", + "implementation": "org.technologybrewery.habushu.migration.CustomPoetrycoreVersionMigration", + "fileSets": [ + { + "includes": ["pyproject.toml"] + } + ] } ] \ No newline at end of file diff --git a/habushu-maven-plugin/src/test/java/org/technologybrewery/habushu/migration/PoetrycoreVersionMigrationSteps.java b/habushu-maven-plugin/src/test/java/org/technologybrewery/habushu/migration/PoetrycoreVersionMigrationSteps.java new file mode 100644 index 0000000..6ef752d --- /dev/null +++ b/habushu-maven-plugin/src/test/java/org/technologybrewery/habushu/migration/PoetrycoreVersionMigrationSteps.java @@ -0,0 +1,94 @@ +package org.technologybrewery.habushu.migration; + +import com.electronwill.nightconfig.core.Config; +import com.electronwill.nightconfig.core.file.FileConfig; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.technologybrewery.habushu.util.TomlUtils; + +import java.io.File; +import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.technologybrewery.habushu.util.PoetryUtil; + +public class PoetrycoreVersionMigrationSteps { + + private File testTomlFileDirectory = new File("./target/test-classes/migration/poetrycore"); + private File pyProjectToml; + + private boolean shouldExecute; + + private boolean executionSucceeded; + + @Given("an existing pyproject.toml file with poetry-core version of 1.6.0 in the build-system group") + public void an_existing_pyproject_toml_file_with_poetry_core_version_of_1_6_0_in_the_build_system_group() { + pyProjectToml = new File(testTomlFileDirectory, "with-poetry-core-version-1-6-0.toml"); + } + + @Given("an existing pyproject.toml file with poetry-core version less than 1.6.0 in the build-system group") + public void an_existing_pyproject_toml_file_with_poetry_core_version_less_than_1_6_0_in_the_build_system_group() { + pyProjectToml = new File(testTomlFileDirectory, "with-poetry-core-version-1-0-0.toml"); + } + + @Given("an existing pyproject.toml file with poetry-core version of 1.7.0 in the build-system group") + public void an_existing_pyproject_toml_file_with_poetry_core_version_of_1_7_0_in_the_build_system_group() { + pyProjectToml = new File(testTomlFileDirectory, "with-poetry-core-version-1-7-0.toml"); + } + + @Given("an existing pyproject.toml file with poetry-core version of 2.0.0 in the build-system group") + public void an_existing_pyproject_toml_file_with_poetry_core_version_of_2_0_0_in_the_build_system_group() { + pyProjectToml = new File(testTomlFileDirectory, "with-poetry-core-version-2-0-0.toml"); + } + + @When("Habushu poetry core migration executes") + public void habushu_migrations_execute() { + CustomPoetrycoreVersionMigration migration = new CustomPoetrycoreVersionMigration(); + shouldExecute = migration.shouldExecuteOnFile(pyProjectToml); + executionSucceeded = (shouldExecute) ? migration.performMigration(pyProjectToml) : false; + } + + @Then("the poetry-core version is updated to 1.6.0 in the build-system group") + public void the_poetry_core_version_is_updated_to_1_6_0_in_the_build_system_group() { + verifyExeuctionOccurred(); + try (FileConfig tomlFileConfig = FileConfig.of(pyProjectToml)) { + tomlFileConfig.load(); + + Optional toolBuildSystem = tomlFileConfig.getOptional(TomlUtils.BUILD_SYSTEM); + String poetrycoreVer = ""; + if (toolBuildSystem.isPresent()) { + Config buildSystem = toolBuildSystem.get(); + Map dependencyMap = buildSystem.valueMap(); + for (Map.Entry dependency : dependencyMap.entrySet()) { + + String packageName = dependency.getKey(); + if (packageName.equals(TomlUtils.REQUIRES)) { + String dependencyVal = dependency.getValue().toString(); + if (dependencyVal.contains(TomlUtils.POETRY_CORE) && dependencyVal.contains(TomlUtils.EQUALS)) { + poetrycoreVer = dependencyVal.substring(TomlUtils.getIndexOfFirstDigit(dependencyVal), TomlUtils.getIndexOfLastDigit(dependencyVal)); + break; + } + } + } + } + int indexStart = TomlUtils.getIndexOfFirstDigit(PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT); + String poetryCoreVersionRequired = PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT.substring(indexStart,PoetryUtil.POETRY_CORE_VERSION_REQUIREMENT.length() ); + assertEquals(poetryCoreVersionRequired, poetrycoreVer,"poetry-core version is not matching with the required poetry-core version and should be updated"); + } + } + + @Then("no update was performed for poetry-core version") + public void no_update_was_performed_for_poetry_core_version() { + assertFalse(shouldExecute, "no update was performed for poetry-core version!"); + } + + private void verifyExeuctionOccurred() { + assertTrue(shouldExecute, "Migration should have been selected to execute!"); + assertTrue(executionSucceeded, "Migration should have executed successfully!"); + } +} \ No newline at end of file diff --git a/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-0-0.toml b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-0-0.toml new file mode 100644 index 0000000..8009b38 --- /dev/null +++ b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-0-0.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "habushu_mixology" +version = "2.9.0.dev" +description = "Example of how to use the habushu-maven-plugin" +authors = ["Eric Konieczny "] +license = "MIT License" + +[tool.poetry.dependencies] +python = "^3.11" +krausening = "17" +cryptography = "^41.0.3" +uvicorn = {version = "^0.18.0", extras = ["standard"]} + +[tool.poetry.dev-dependencies] +black = "^22.3.0" +behave = "^1.2.6" +grpcio-tools = "^1.48.0" +python-dotenv = "^0.20.0" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-6-0.toml b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-6-0.toml new file mode 100644 index 0000000..025c008 --- /dev/null +++ b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-6-0.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "habushu_mixology" +version = "2.9.0.dev" +description = "Example of how to use the habushu-maven-plugin" +authors = ["Eric Konieczny "] +license = "MIT License" + +[tool.poetry.dependencies] +python = "^3.11" +krausening = "17" +cryptography = "^41.0.3" +uvicorn = {version = "^0.18.0", extras = ["standard"]} + +[tool.poetry.dev-dependencies] +black = "^22.3.0" +behave = "^1.2.6" +grpcio-tools = "^1.48.0" +python-dotenv = "^0.20.0" + +[build-system] +requires = ["poetry-core>=1.6.0"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-7-0.toml b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-7-0.toml new file mode 100644 index 0000000..2325c09 --- /dev/null +++ b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-1-7-0.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "habushu_mixology" +version = "2.9.0.dev" +description = "Example of how to use the habushu-maven-plugin" +authors = ["Eric Konieczny "] +license = "MIT License" + +[tool.poetry.dependencies] +python = "^3.11" +krausening = "17" +cryptography = "^41.0.3" +uvicorn = {version = "^0.18.0", extras = ["standard"]} + +[tool.poetry.dev-dependencies] +black = "^22.3.0" +behave = "^1.2.6" +grpcio-tools = "^1.48.0" +python-dotenv = "^0.20.0" + +[build-system] +requires = ["poetry-core>=1.7.0"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-2-0-0.toml b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-2-0-0.toml new file mode 100644 index 0000000..ce35dd2 --- /dev/null +++ b/habushu-maven-plugin/src/test/resources/migration/poetrycore/with-poetry-core-version-2-0-0.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "habushu_mixology" +version = "2.9.0.dev" +description = "Example of how to use the habushu-maven-plugin" +authors = ["Eric Konieczny "] +license = "MIT License" + +[tool.poetry.dependencies] +python = "^3.11" +krausening = "17" +cryptography = "^41.0.3" +uvicorn = {version = "^0.18.0", extras = ["standard"]} + +[tool.poetry.dev-dependencies] +black = "^22.3.0" +behave = "^1.2.6" +grpcio-tools = "^1.48.0" +python-dotenv = "^0.20.0" + +[build-system] +requires = ["poetry-core>=2.0.0"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/habushu-maven-plugin/src/test/resources/specifications/poetry-core-version-migration.feature b/habushu-maven-plugin/src/test/resources/specifications/poetry-core-version-migration.feature new file mode 100644 index 0000000..2752cf0 --- /dev/null +++ b/habushu-maven-plugin/src/test/resources/specifications/poetry-core-version-migration.feature @@ -0,0 +1,23 @@ +Feature: Poetry-core version migration + Baton will migrate the poetry-core version within the pyproject.toml file to match the required version needed by the Habushu. + + +Scenario: Migrate poetry-core version when existing poetry-core version is less than 1.6.0 +Given an existing pyproject.toml file with poetry-core version less than 1.6.0 in the build-system group +When Habushu poetry core migration executes +Then the poetry-core version is updated to 1.6.0 in the build-system group + +Scenario: No migration will be performed when the poetry-core version is equal to 1.6.0 +Given an existing pyproject.toml file with poetry-core version of 1.6.0 in the build-system group +When Habushu poetry core migration executes +Then no update was performed for poetry-core version + +Scenario: No migration will be performed when the poetry-core version of 1.7.0 +Given an existing pyproject.toml file with poetry-core version of 1.7.0 in the build-system group +When Habushu poetry core migration executes +Then no update was performed for poetry-core version + +Scenario: No migration will be performed when the poetry-core version of 2.0.0 +Given an existing pyproject.toml file with poetry-core version of 2.0.0 in the build-system group +When Habushu poetry core migration executes +Then no update was performed for poetry-core version \ No newline at end of file