2929# TODO: Override get_package_resource so it returns the Resource that the ABOUT file is describing
3030
3131@attr .s ()
32- class AboutPackage (models .Package , models .PackageManifest ):
33- file_patterns = ('*.ABOUT' ,)
34- default_type = 'about'
32+ class AboutPackage (models .Package ):
3533
36- @classmethod
37- def recognize (cls , location ):
38- yield parse (location )
34+ default_type = 'about'
3935
4036 def get_package_root (self , manifest_resource , codebase ):
4137 about_resource = self .extra_data .get ('about_resource' )
@@ -47,53 +43,55 @@ def get_package_root(self, manifest_resource, codebase):
4743 return manifest_resource
4844
4945
50- def is_about_file (location ):
51- return (filetype .is_file (location )
52- and location .lower ().endswith (('.about' ,)))
53-
54-
55- def parse (location ):
56- """
57- Return a Package object from an ABOUT file or None.
58- """
59- if not is_about_file (location ):
60- return
61-
62- with io .open (location , encoding = 'utf-8' ) as loc :
63- package_data = saneyaml .load (loc .read ())
64-
65- return build_package (package_data )
66-
67-
68- def build_package (package_data ):
69- """
70- Return a Package built from `package_data` obtained by an ABOUT file.
71- """
72- name = package_data .get ('name' )
73- # FIXME: having no name may not be a problem See #1514
74- if not name :
75- return
76-
77- version = package_data .get ('version' )
78- homepage_url = package_data .get ('home_url' ) or package_data .get ('homepage_url' )
79- download_url = package_data .get ('download_url' )
80- declared_license = package_data .get ('license_expression' )
81- copyright_statement = package_data .get ('copyright' )
82-
83- owner = package_data .get ('owner' )
84- if not isinstance (owner , str ):
85- owner = repr (owner )
86- parties = [models .Party (type = models .party_person , name = owner , role = 'owner' )]
87-
88- about_package = AboutPackage (
89- type = 'about' ,
90- name = name ,
91- version = version ,
92- declared_license = declared_license ,
93- copyright = copyright_statement ,
94- parties = parties ,
95- homepage_url = homepage_url ,
96- download_url = download_url ,
97- )
98- about_package .extra_data ['about_resource' ] = package_data .get ('about_resource' )
99- return about_package
46+ @attr .s ()
47+ class Aboutfile (AboutPackage , models .PackageManifest ):
48+
49+ file_patterns = ('*.ABOUT' ,)
50+ extensions = ('.ABOUT' ,)
51+ manifest_type = 'aboutfile'
52+
53+ @classmethod
54+ def is_manifest (cls , location ):
55+ """
56+ Return True if the file at ``location`` is likely a manifest of this type.
57+ """
58+ return (filetype .is_file (location ) and location .lower ().endswith (('.about' ,)))
59+
60+ @classmethod
61+ def recognize (cls , location ):
62+ """
63+ Yield one or more Package manifest objects given a file ``location`` pointing to a
64+ package archive, manifest or similar.
65+ """
66+ with io .open (location , encoding = 'utf-8' ) as loc :
67+ package_data = saneyaml .load (loc .read ())
68+
69+ name = package_data .get ('name' )
70+ # FIXME: having no name may not be a problem See #1514
71+ if not name :
72+ return
73+
74+ version = package_data .get ('version' )
75+ homepage_url = package_data .get ('home_url' ) or package_data .get ('homepage_url' )
76+ download_url = package_data .get ('download_url' )
77+ declared_license = package_data .get ('license_expression' )
78+ copyright_statement = package_data .get ('copyright' )
79+
80+ owner = package_data .get ('owner' )
81+ if not isinstance (owner , str ):
82+ owner = repr (owner )
83+ parties = [models .Party (type = models .party_person , name = owner , role = 'owner' )]
84+
85+ about_package = cls (
86+ type = 'about' ,
87+ name = name ,
88+ version = version ,
89+ declared_license = declared_license ,
90+ copyright = copyright_statement ,
91+ parties = parties ,
92+ homepage_url = homepage_url ,
93+ download_url = download_url ,
94+ )
95+
96+ about_package .extra_data ['about_resource' ] = package_data .get ('about_resource' )
97+ yield about_package
0 commit comments