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 = cls (
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+
75140def 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-
167165def map_license (package ):
168166 """
169167 Update the license based on a mapping:
0 commit comments