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

fix: skip pyproject.toml unless it contains tool.poetry before ensuring lockfiles #6681

Merged
merged 1 commit into from
May 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ protected void analyzeDependency(Dependency dependency, Engine engine) throws An
//do not report on the build file itself
engine.removeDependency(dependency);

final Toml result = new Toml().read(dependency.getActualFile());
if (PYPROJECT_TOML.equals(dependency.getActualFile().getName())) {
if (result.getTable("tool.poetry") == null) {
LOGGER.debug("skipping {} as it does not contain `tool.poetry`", dependency.getDisplayFileName());
return;
}

final File parentPath = dependency.getActualFile().getParentFile();
ensureLock(parentPath);
//exit as we can't analyze pyproject.toml - insufficient version information
return;
}

final Toml result = new Toml().read(dependency.getActualFile());
if (PYPROJECT_TOML.equals(dependency.getActualFile().getName()) && result.getTables("tool.poetry") == null) {
LOGGER.debug("skipping {} as it does not contain `tool.poetry`", dependency.getDisplayFileName());
return;
}
final List<Toml> projectsLocks = result.getTables("package");
if (projectsLocks == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ public void testPoetryLock() throws AnalysisException {
assertTrue("Expeced to find PyYAML", found);
}

@Test(expected = AnalysisException.class)
@Test
public void testPyprojectToml() throws AnalysisException {
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, "python-myproject-toml/pyproject.toml"));
//returns with no error.
analyzer.analyze(result, engine);
}

@Test(expected = AnalysisException.class)
public void testPoetryToml() throws AnalysisException {
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, "python-poetry-toml/pyproject.toml"));
//causes an exception.
analyzer.analyze(result, engine);
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/resources/python-poetry-toml/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading