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: Support ~= version specifier in requirements.txt and pipfile #5902

Merged
merged 2 commits into from
Oct 5, 2023
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 @@ -74,7 +74,7 @@ public class PipAnalyzer extends AbstractFileTypeAnalyzer {
/**
* o * Matches AC_INIT variables in the output configure script.
*/
private static final Pattern PACKAGE_VERSION = Pattern.compile("^([^#].*?)(?:[=>]=([\\.\\*0-9]+?))?$", Pattern.MULTILINE);
private static final Pattern PACKAGE_VERSION = Pattern.compile("^([^#].*?)(?:[=~>]=([\\.\\*0-9]+?))?$", Pattern.MULTILINE);

/**
* The file filter used to determine which files this analyzer supports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class PipfileAnalyzer extends AbstractFileTypeAnalyzer {
/**
* o * Matches AC_INIT variables in the output configure script.
*/
private static final Pattern PACKAGE_VERSION = Pattern.compile("^([^#].*?) = \"(?:[=>]=([\\.\\*0-9]+?))?\"$", Pattern.MULTILINE);
private static final Pattern PACKAGE_VERSION = Pattern.compile("^([^#].*?) = \"(?:[=~>]=([\\.\\*0-9]+?))?\"$", Pattern.MULTILINE);

/**
* The file filter used to determine which files this analyzer supports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,25 @@ public void testAnalyzePackageJson() throws Exception {
engine.addDependency(result);
analyzer.analyze(result, engine);
assertFalse(ArrayUtils.contains(engine.getDependencies(), result));
assertEquals(23, engine.getDependencies().length);
boolean found = false;
assertEquals(24, engine.getDependencies().length);
boolean foundPyYAML = false;
boolean foundCryptography = false;
for (Dependency d : engine.getDependencies()) {
if ("PyYAML".equals(d.getName())) {
found = true;
foundPyYAML = true;
assertEquals("3.12", d.getVersion());
assertThat(d.getDisplayFileName(), equalTo("PyYAML:3.12"));
assertEquals(PythonDistributionAnalyzer.DEPENDENCY_ECOSYSTEM, d.getEcosystem());
}
if ("cryptography".equals(d.getName())) {
foundCryptography = true;
assertEquals("1.8.2", d.getVersion());
assertThat(d.getDisplayFileName(), equalTo("cryptography:1.8.2"));
assertEquals(PythonDistributionAnalyzer.DEPENDENCY_ECOSYSTEM, d.getEcosystem());
}
}
assertTrue("Expeced to find PyYAML", found);
assertTrue("Expected to find PyYAML", foundPyYAML);
assertTrue("Expected to find cryptography", foundCryptography);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,25 @@ public void testAnalyzePackageJson() throws Exception {
engine.addDependency(result);
analyzer.analyze(result, engine);
assertFalse(ArrayUtils.contains(engine.getDependencies(), result));
assertEquals(39, engine.getDependencies().length);
boolean found = false;
assertEquals(40, engine.getDependencies().length);
boolean foundUrllib3 = false;
boolean foundCryptography = false;
for (Dependency d : engine.getDependencies()) {
if ("urllib3".equals(d.getName())) {
found = true;
foundUrllib3 = true;
assertEquals("1.25.9", d.getVersion());
assertThat(d.getDisplayFileName(), equalTo("urllib3:1.25.9"));
assertEquals(PythonDistributionAnalyzer.DEPENDENCY_ECOSYSTEM, d.getEcosystem());
}
if ("cryptography".equals(d.getName())) {
foundCryptography = true;
assertEquals("1.8.2", d.getVersion());
assertThat(d.getDisplayFileName(), equalTo("cryptography:1.8.2"));
assertEquals(PythonDistributionAnalyzer.DEPENDENCY_ECOSYSTEM, d.getEcosystem());
}
}
assertTrue("Expeced to find urllib3", found);
assertTrue("Expeced to find urllib3", foundUrllib3);
assertTrue("Expeced to find cryptography", foundCryptography);
}
}
}
1 change: 1 addition & 0 deletions src/test/resources/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ py-flags = "==1.1.2"
CacheControl = "==0.12.5"
prometheus_client = "==0.7.1"
PyYAML = "==5.3.1"
cryptography = "~=1.8.2"

[requires]
python_version = "3.6"
3 changes: 2 additions & 1 deletion src/test/resources/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ six==1.11.0
spyne==2.12.14
suds-jurko==0.6
urllib3
Werkzeug>=0.14.1
Werkzeug>=0.14.1
cryptography~=1.8.2