Skip to content

Commit 2ab8558

Browse files
Create PackageManifest class for Haxe
Creates PackageManifest classes for haxe manifests and overrides the methods for detection and PackageManifest creation. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent a0d0010 commit 2ab8558

8 files changed

Lines changed: 353 additions & 342 deletions

File tree

src/packagedcode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
npm.NPMYarnLockJSON,
5757
phpcomposer.PHPComposerJSON,
5858
phpcomposer.PHPComposerLock,
59-
haxe.HaxePackage,
59+
haxe.HaxelibJSON,
6060
cargo.RustCargoCrate,
6161
cocoapods.CocoapodsPodspec,
6262
cocoapods.CocoapodsPodfileLock,

src/packagedcode/haxe.py

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,15 @@
4848

4949

5050
@attr.s()
51-
class HaxePackage(models.Package, models.PackageManifest):
52-
file_patterns = ('haxelib.json',)
51+
class HaxePackage(models.Package):
52+
5353
filetypes = tuple()
5454
mimetypes = tuple()
5555
default_type = 'haxe'
5656
default_primary_language = 'Haxe'
5757
default_web_baseurl = 'https://lib.haxe.org/p/'
5858
default_download_baseurl = 'https://lib.haxe.org/p/'
5959

60-
@classmethod
61-
def recognize(cls, location):
62-
yield parse(location)
63-
6460
@classmethod
6561
def get_package_root(cls, manifest_resource, codebase):
6662
return manifest_resource.parent(codebase)
@@ -72,6 +68,75 @@ def repository_download_url(self, baseurl=default_download_baseurl):
7268
return haxelib_download_url(self.name, self.version, baseurl=baseurl)
7369

7470

71+
@attr.s()
72+
class HaxelibJSON(HaxePackage, models.PackageManifest):
73+
74+
file_patterns = ('haxelib.json',)
75+
extensions = ('.json',)
76+
manifest_type = 'haxlibjson'
77+
78+
@classmethod
79+
def is_manifest(cls, location):
80+
"""
81+
Return True if the file at ``location`` is likely a manifest of this type.
82+
"""
83+
return (filetype.is_file(location)
84+
and fileutils.file_name(location).lower() == 'haxelib.json')
85+
86+
@classmethod
87+
def recognize(cls, location):
88+
"""
89+
Yield one or more Package manifest objects given a file ``location`` pointing to a
90+
package archive, manifest or similar.
91+
92+
{
93+
"name": "haxelib",
94+
"url" : "https://lib.haxe.org/documentation/",
95+
"license": "GPL",
96+
"tags": ["haxelib", "core"],
97+
"description": "The haxelib client",
98+
"classPath": "src",
99+
"version": "3.4.0",
100+
"releasenote": " * Fix password input issue in Windows (#421).\n * ....",
101+
"contributors": ["back2dos", "ncannasse", "jason", "Simn", "nadako", "andyli"]
102+
}
103+
"""
104+
with io.open(location, encoding='utf-8') as loc:
105+
package_data = json.load(loc)
106+
107+
package = HaxePackage(
108+
name=package_data.get('name'),
109+
version=package_data.get('version'),
110+
homepage_url=package_data.get('url'),
111+
declared_license=package_data.get('license'),
112+
keywords=package_data.get('tags'),
113+
description=package_data.get('description'),
114+
)
115+
116+
package.download_url = package.repository_download_url()
117+
118+
for contrib in package_data.get('contributors', []):
119+
party = models.Party(
120+
type=models.party_person,
121+
name=contrib,
122+
role='contributor',
123+
url='https://lib.haxe.org/u/{}'.format(contrib))
124+
package.parties.append(party)
125+
126+
for dep_name, dep_version in package_data.get('dependencies', {}).items():
127+
dep_version = dep_version and dep_version.strip()
128+
is_resolved = bool(dep_version)
129+
dep_purl = PackageURL(
130+
type='haxe',
131+
name=dep_name,
132+
version=dep_version
133+
).to_string()
134+
dep = models.DependentPackage(purl=dep_purl, is_resolved=is_resolved,)
135+
package.dependencies.append(dep)
136+
137+
yield package
138+
139+
75140
def haxelib_homepage_url(name, baseurl='https://lib.haxe.org/p/'):
76141
"""
77142
Return an haxelib package homepage URL given a name and a base registry web
@@ -97,73 +162,6 @@ def haxelib_download_url(name, version, baseurl='https://lib.haxe.org/p'):
97162
return '{baseurl}/{name}/{version}/download/'.format(**locals())
98163

99164

100-
def is_haxelib_json(location):
101-
return (filetype.is_file(location)
102-
and fileutils.file_name(location).lower() == 'haxelib.json')
103-
104-
105-
def parse(location):
106-
"""
107-
Return a Package object from a haxelib.json file or None.
108-
"""
109-
if not is_haxelib_json(location):
110-
return
111-
112-
with io.open(location, encoding='utf-8') as loc:
113-
package_data = json.load(loc)
114-
return build_package(package_data)
115-
116-
117-
def build_package(package_data):
118-
"""
119-
Return a Package object from a package_data mapping (from a
120-
haxelib.json or similar) or None.
121-
{
122-
"name": "haxelib",
123-
"url" : "https://lib.haxe.org/documentation/",
124-
"license": "GPL",
125-
"tags": ["haxelib", "core"],
126-
"description": "The haxelib client",
127-
"classPath": "src",
128-
"version": "3.4.0",
129-
"releasenote": " * Fix password input issue in Windows (#421).\n * ....",
130-
"contributors": ["back2dos", "ncannasse", "jason", "Simn", "nadako", "andyli"]
131-
}
132-
133-
"""
134-
package = HaxePackage(
135-
name=package_data.get('name'),
136-
version=package_data.get('version'),
137-
homepage_url=package_data.get('url'),
138-
declared_license=package_data.get('license'),
139-
keywords=package_data.get('tags'),
140-
description=package_data.get('description'),
141-
)
142-
143-
package.download_url = package.repository_download_url()
144-
145-
for contrib in package_data.get('contributors', []):
146-
party = models.Party(
147-
type=models.party_person,
148-
name=contrib,
149-
role='contributor',
150-
url='https://lib.haxe.org/u/{}'.format(contrib))
151-
package.parties.append(party)
152-
153-
for dep_name, dep_version in package_data.get('dependencies', {}).items():
154-
dep_version = dep_version and dep_version.strip()
155-
is_resolved = bool(dep_version)
156-
dep_purl = PackageURL(
157-
type='haxe',
158-
name=dep_name,
159-
version=dep_version
160-
).to_string()
161-
dep = models.DependentPackage(purl=dep_purl, is_resolved=is_resolved,)
162-
package.dependencies.append(dep)
163-
164-
return package
165-
166-
167165
def map_license(package):
168166
"""
169167
Update the license based on a mapping:
Lines changed: 84 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,84 @@
1-
{
2-
"type": "haxe",
3-
"namespace": null,
4-
"name": "haxelib",
5-
"version": "3.4.0",
6-
"qualifiers": {},
7-
"subpath": null,
8-
"primary_language": "Haxe",
9-
"description": "The haxelib client",
10-
"release_date": null,
11-
"parties": [
12-
{
13-
"type": "person",
14-
"role": "contributor",
15-
"name": "back2dos",
16-
"email": null,
17-
"url": "https://lib.haxe.org/u/back2dos"
18-
},
19-
{
20-
"type": "person",
21-
"role": "contributor",
22-
"name": "ncannasse",
23-
"email": null,
24-
"url": "https://lib.haxe.org/u/ncannasse"
25-
},
26-
{
27-
"type": "person",
28-
"role": "contributor",
29-
"name": "jason",
30-
"email": null,
31-
"url": "https://lib.haxe.org/u/jason"
32-
},
33-
{
34-
"type": "person",
35-
"role": "contributor",
36-
"name": "Simn",
37-
"email": null,
38-
"url": "https://lib.haxe.org/u/Simn"
39-
},
40-
{
41-
"type": "person",
42-
"role": "contributor",
43-
"name": "nadako",
44-
"email": null,
45-
"url": "https://lib.haxe.org/u/nadako"
46-
},
47-
{
48-
"type": "person",
49-
"role": "contributor",
50-
"name": "andyli",
51-
"email": null,
52-
"url": "https://lib.haxe.org/u/andyli"
53-
}
54-
],
55-
"keywords": [
56-
"haxelib",
57-
"core"
58-
],
59-
"homepage_url": "https://lib.haxe.org/documentation/",
60-
"download_url": "https://lib.haxe.org/p/haxelib/3.4.0/download/",
61-
"size": null,
62-
"sha1": null,
63-
"md5": null,
64-
"sha256": null,
65-
"sha512": null,
66-
"bug_tracking_url": null,
67-
"code_view_url": null,
68-
"vcs_url": null,
69-
"copyright": null,
70-
"license_expression": "gpl-1.0-plus",
71-
"declared_license": "GPL",
72-
"notice_text": null,
73-
"root_path": null,
74-
"dependencies": [],
75-
"contains_source_code": null,
76-
"source_packages": [],
77-
"extra_data": {},
78-
"purl": "pkg:haxe/haxelib@3.4.0",
79-
"repository_homepage_url": "https://lib.haxe.org/p/haxelib",
80-
"repository_download_url": "https://lib.haxe.org/p/haxelib/3.4.0/download/",
81-
"api_data_url": null
82-
}
1+
[
2+
{
3+
"type": "haxe",
4+
"namespace": null,
5+
"name": "haxelib",
6+
"version": "3.4.0",
7+
"qualifiers": {},
8+
"subpath": null,
9+
"primary_language": "Haxe",
10+
"description": "The haxelib client",
11+
"release_date": null,
12+
"parties": [
13+
{
14+
"type": "person",
15+
"role": "contributor",
16+
"name": "back2dos",
17+
"email": null,
18+
"url": "https://lib.haxe.org/u/back2dos"
19+
},
20+
{
21+
"type": "person",
22+
"role": "contributor",
23+
"name": "ncannasse",
24+
"email": null,
25+
"url": "https://lib.haxe.org/u/ncannasse"
26+
},
27+
{
28+
"type": "person",
29+
"role": "contributor",
30+
"name": "jason",
31+
"email": null,
32+
"url": "https://lib.haxe.org/u/jason"
33+
},
34+
{
35+
"type": "person",
36+
"role": "contributor",
37+
"name": "Simn",
38+
"email": null,
39+
"url": "https://lib.haxe.org/u/Simn"
40+
},
41+
{
42+
"type": "person",
43+
"role": "contributor",
44+
"name": "nadako",
45+
"email": null,
46+
"url": "https://lib.haxe.org/u/nadako"
47+
},
48+
{
49+
"type": "person",
50+
"role": "contributor",
51+
"name": "andyli",
52+
"email": null,
53+
"url": "https://lib.haxe.org/u/andyli"
54+
}
55+
],
56+
"keywords": [
57+
"haxelib",
58+
"core"
59+
],
60+
"homepage_url": "https://lib.haxe.org/documentation/",
61+
"download_url": "https://lib.haxe.org/p/haxelib/3.4.0/download/",
62+
"size": null,
63+
"sha1": null,
64+
"md5": null,
65+
"sha256": null,
66+
"sha512": null,
67+
"bug_tracking_url": null,
68+
"code_view_url": null,
69+
"vcs_url": null,
70+
"copyright": null,
71+
"license_expression": "gpl-1.0-plus",
72+
"declared_license": "GPL",
73+
"notice_text": null,
74+
"root_path": null,
75+
"dependencies": [],
76+
"contains_source_code": null,
77+
"source_packages": [],
78+
"extra_data": {},
79+
"purl": "pkg:haxe/haxelib@3.4.0",
80+
"repository_homepage_url": "https://lib.haxe.org/p/haxelib",
81+
"repository_download_url": "https://lib.haxe.org/p/haxelib/3.4.0/download/",
82+
"api_data_url": null
83+
}
84+
]

0 commit comments

Comments
 (0)