Skip to content

Commit

Permalink
Merge pull request #165 from krzysztof-pawlik-gat/master
Browse files Browse the repository at this point in the history
Python improvements
  • Loading branch information
jonabc authored May 8, 2019
2 parents afba288 + 567c487 commit 6a107a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/licensed/sources/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Licensed
module Sources
class Pip < Source
VERSION_OPERATORS = %w(< > <= >= == !=).freeze
PACKAGE_REGEX = /^(\w+)(#{VERSION_OPERATORS.join("|")})?/
PACKAGE_REGEX = /^([\w-]+)(#{VERSION_OPERATORS.join("|")})?/

def enabled?
return unless virtual_env_pip && Licensed::Shell.tool_available?(virtual_env_pip)
Expand All @@ -16,7 +16,7 @@ def enabled?
def enumerate_dependencies
packages_from_requirements_txt.map do |package_name|
package = package_info(package_name)
location = File.join(package["Location"], package["Name"] + "-" + package["Version"] + ".dist-info")
location = File.join(package["Location"], package["Name"].gsub("-", "_") + "-" + package["Version"] + ".dist-info")
Dependency.new(
name: package["Name"],
version: package["Version"],
Expand All @@ -35,6 +35,7 @@ def enumerate_dependencies
def packages_from_requirements_txt
File.read(@config.pwd.join("requirements.txt"))
.lines
.reject { |line| line.include?("://") }
.map { |line| line.strip.match(PACKAGE_REGEX) { |match| match.captures.first } }
.compact
end
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/pip/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Pillow>5.4.0
Scrapy<1.6.0
numpy!=1.16.1
botocore == 1.12.91
boto3>=1.0,<=2.0
boto3>=1.0,<=2.0
lazy-object-proxy==1.4.0
10 changes: 10 additions & 0 deletions test/sources/pip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@
assert dep.record["summary"]
end
end

it "detects dependencies with hyphens in package name" do
Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "lazy-object-proxy" }
assert dep
assert_equal "pip", dep.record["type"]
assert dep.record["homepage"]
assert dep.record["summary"]
end
end
end
end
end

0 comments on commit 6a107a1

Please sign in to comment.