Skip to content

Commit

Permalink
Check namespace before creating URLs aboutcode-org#1850
Browse files Browse the repository at this point in the history
    * Add test for composer.lock parsing
    * Update tests

Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang authored and viragumathe5 committed Mar 12, 2020
1 parent 1565362 commit 8f44a3a
Show file tree
Hide file tree
Showing 6 changed files with 1,837 additions and 16 deletions.
16 changes: 10 additions & 6 deletions src/packagedcode/phpcomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class PHPComposerPackage(models.Package):
metafiles = (
'composer.json',
'composer.lock',
'installed.json',
)
filetypes = ('.json', '.lock')
mimetypes = ('application/json',)
Expand All @@ -93,10 +92,16 @@ def get_package_root(cls, manifest_resource, codebase):
return manifest_resource.parent(codebase)

def repository_homepage_url(self, baseurl=default_web_baseurl):
return '{}/packages/{}/{}'.format(baseurl, self.namespace, self.name)
if self.namespace:
return '{}/packages/{}/{}'.format(baseurl, self.namespace, self.name)
else:
return '{}/packages/{}'.format(baseurl, self.name)

def api_data_url(self, baseurl=default_api_baseurl):
return '{}/packages/{}/{}.json'.format(baseurl, self.namespace, self.name)
if self.namespace:
return '{}/packages/{}/{}.json'.format(baseurl, self.namespace, self.name)
else:
return '{}/packages/{}.json'.format(baseurl, self.name)

def compute_normalized_license(self):
"""
Expand Down Expand Up @@ -356,9 +361,8 @@ def build_package_from_lock(package_data):
Yield a composer Package object from a package data mapping that originated
from a composer.lock file
"""
packages = package_data.get('packages', [])
packages_dev = package_data.get('packages-dev', [])
for package in packages + packages_dev:
packages = package_data.get('packages', []) + package_data.get('packages-dev', [])
for package in packages:
dependencies = []
for dep, req in package.get('require', {}).items():
dependencies.append(
Expand Down
Loading

0 comments on commit 8f44a3a

Please sign in to comment.