Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 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
27 changes: 27 additions & 0 deletions fetchcode/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,30 @@ def get_rubygems_data_from_purl(purl):
download_url=download_url,
**purl.to_dict(),
)


@router.route("pkg:brew/.*")
def get_homebrew_data_from_purl(purl):
Comment thread
pombredanne marked this conversation as resolved.
"""
Generate `Package` object from the `purl` string of rubygems type
"""
purl = PackageURL.from_string(purl)
name = purl.name
base_path = "https://formulae.brew.sh/api/formula"
api_url = f"{base_path}/{name}.json"
response = get_response(api_url)
declared_license = response.get("license")
homepage_url = response.get("homepage")
version = response.get("versions")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraction of version does not seem to be correct

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again sorry will correct this too.

download_path = response.get("urls")["stable"]["url"]

@TG1999 TG1999 Oct 14, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urls = response.get('urls') or {{}}
stable_url = urls.get('stable') or {}
download_url = stable_url.get('url')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 345-349 and use this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok, will replace that, sorry for these mistakes, will remember and learn continuing further. Thank you for the feedback

if download_path:
download_url = response.get("urls")["stable"]["url"]
else:
download_url = None
yield Package(
homepage_url=homepage_url,
api_url=api_url,
declared_license=declared_license,
download_url=download_url,
**purl.to_dict(),
)
38 changes: 38 additions & 0 deletions tests/data/homebrew.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"0": {
"type": "brew",
"namespace": null,
"name": "node",
"version": null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should collect version data; it seems like there is a bug in your code, as I see you attempt to collect this version data in package.py (on line 344-345)

@zaheerabbas21 zaheerabbas21 Oct 17, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG, Thanks for pointing out the bug, I know this is supposed to be a good first issue, but I am really new to the development side, I appreciate all the help.

But I am stuck here, as you said I changed the version in the tests/data/homebrew.json file. But I do not know how to pass the versions to the Package to yield it, I tried the key version, but did not work. So please tell me how to pass the version variable to the package.

Here is the diff of the test when I ran python -m pytest -vv

 Full diff:
E           [
E            {'api_data_url': None,
E             'api_url': 'https://formulae.brew.sh/api/formula/node.json',
E             'bug_tracking_url': None,
E             'code_view_url': None,
E             'contains_source_code': None,
E             'copyright': None,
E             'declared_license': 'MIT',
E             'dependencies': [],
E             'description': None,
E             'download_url': 'https://nodejs.org/dist/v14.13.1/node-v14.13.1.tar.gz',
E             'homepage_url': 'https://nodejs.org/',
E             'keywords': [],
E             'license_expression': None,
E             'md5': None,
E             'name': 'node',
E             'namespace': None,
E             'notice_text': None,
E             'parties': [],
E             'primary_language': None,
E             'purl': 'pkg:homebrew/node',
E         -   'qualifiers': {},
E         +   'qualifiers': OrderedDict(),
E             'release_date': None,
E             'repository_download_url': None,
E             'repository_homepage_url': None,
E             'root_path': None,
E             'sha1': None,
E             'sha256': None,
E             'sha512': None,
E             'size': None,
E             'source_packages': [],
E             'subpath': None,
E             'type': 'homebrew',
E             'vcs_url': None,
E         -   'version': '14.4.0'},
E         +   'version': None},
E           ]

I also tried to check the above code and see if I could implement it in a way it is implemented above, but did not understand that, I am really sorry for this.
I am really sorry to disturb you, appreciate all the help. Thank you

"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": null,
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": "https://nodejs.org/",
"download_url": "https://nodejs.org/dist/v14.13.1/node-v14.13.1.tar.gz",
"api_url": "https://formulae.brew.sh/api/formula/node.json",
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"license_expression": null,
"declared_license": "MIT",
"notice_text": null,
"root_path": null,
"dependencies": [],
"contains_source_code": null,
"source_packages": [],
"purl": "pkg:brew/node",
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": null
}
}
124 changes: 124 additions & 0 deletions tests/data/homebrew_mock_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"name": "node",
"full_name": "node",
"oldname": null,
"aliases": [
"node.js",
"node@14",
"nodejs",
"npm"
],
"versioned_formulae": [
"node@12",
"node@10"
],
"desc": "Platform built on V8 to build network applications",
"license": "MIT",
"homepage": "https://nodejs.org/",
"versions": {
"stable": "14.13.1",
"head": "HEAD",
"bottle": true
},
"urls": {
"stable": {
"url": "https://nodejs.org/dist/v14.13.1/node-v14.13.1.tar.gz",
"tag": null,
"revision": null
}
},
"revision": 0,
"version_scheme": 0,
"bottle": {
"stable": {
"rebuild": 0,
"cellar": ":any",
"prefix": "/usr/local",
"root_url": "https://homebrew.bintray.com/bottles",
"files": {
"catalina": {
"url": "https://homebrew.bintray.com/bottles/node-14.13.1.catalina.bottle.tar.gz",
"sha256": "c5574d926c10ecb8a18faa551f6a15c362512134577110c2678d52db3382ba42"
},
"mojave": {
"url": "https://homebrew.bintray.com/bottles/node-14.13.1.mojave.bottle.tar.gz",
"sha256": "3d42a543356788cb20a3cd91306e9e533c2939b7609c3dc91ffdd405fab1b25f"
},
"high_sierra": {
"url": "https://homebrew.bintray.com/bottles/node-14.13.1.high_sierra.bottle.tar.gz",
"sha256": "8c9d9dd8a341bd74aec4e8ba1a8abb8ba92e137d771290613676798f0b4a61ba"
}
}
}
},
"keg_only": false,
"bottle_disabled": false,
"options": [],
"build_dependencies": [
"pkg-config",
"python@3.8"
],
"dependencies": [
"icu4c"
],
"recommended_dependencies": [],
"optional_dependencies": [],
"uses_from_macos": [],
"requirements": [],
"conflicts_with": [],
"caveats": null,
"installed": [],
"linked_keg": null,
"pinned": false,
"outdated": false,
"deprecated": false,
"disabled": false,
"analytics": {
"install": {
"30d": {
"node": 405637,
"node --HEAD": 44,
"node --with-full-icu": 1,
"node --without-npm": 1
},
"90d": {
"node": 1074821,
"node --HEAD": 117,
"node --without-npm": 3,
"Node": 1,
"node --with-full-icu": 1
},
"365d": {
"node": 4314220,
"node --HEAD": 617,
"node --without-npm": 29,
"node --without-icu4c": 13,
"node --with-openssl@1.1": 6
}
},
"install_on_request": {
"30d": {
"node": 294250,
"node --HEAD": 15
},
"90d": {
"node": 787407,
"node --HEAD": 52,
"Node": 1
},
"365d": {
"node": 3134446,
"node --HEAD": 343,
"node --without-icu4c": 13,
"node --without-npm": 9,
"node --with-openssl@1.1": 6
}
},
"build_error": {
"30d": {
"node": 0
}
}
},
"generated_date": "2020-10-11"
}
10 changes: 10 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ def test_rubygems_packages(mock_get):
mock_get.side_effect = side_effect
packages = list(info(purl))
match_data(packages, expected_data)


@mock.patch("fetchcode.package.get_response")
def test_homebrew_packages(mock_get):
side_effect = [file_data("tests/data/homebrew_mock_data.json")]
purl = "pkg:brew/node"
expected_data = file_data("tests/data/homebrew.json")
mock_get.side_effect = side_effect
packages = list(info(purl))
match_data(packages, expected_data)