3030
3131@attr .s ()
3232class AboutPackage (models .Package ):
33- metafiles = ('*.ABOUT' ,)
34- default_type = 'about'
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,54 @@ 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+
52+ @classmethod
53+ def is_manifest (cls , location ):
54+ """
55+ Return True if the file at ``location`` is likely a manifest of this type.
56+ """
57+ return filetype .is_file (location ) and location .lower ().endswith (('.about' ,))
58+
59+ @classmethod
60+ def recognize (cls , location ):
61+ """
62+ Yield one or more Package manifest objects given a file ``location`` pointing to a
63+ package archive, manifest or similar.
64+ """
65+ with io .open (location , encoding = 'utf-8' ) as loc :
66+ package_data = saneyaml .load (loc .read ())
67+
68+ name = package_data .get ('name' )
69+ # FIXME: having no name may not be a problem See #1514
70+ if not name :
71+ return
72+
73+ version = package_data .get ('version' )
74+ homepage_url = package_data .get ('home_url' ) or package_data .get ('homepage_url' )
75+ download_url = package_data .get ('download_url' )
76+ declared_license = package_data .get ('license_expression' )
77+ copyright_statement = package_data .get ('copyright' )
78+
79+ owner = package_data .get ('owner' )
80+ if not isinstance (owner , str ):
81+ owner = repr (owner )
82+ parties = [models .Party (type = models .party_person , name = owner , role = 'owner' )]
83+
84+ about_package = cls (
85+ type = 'about' ,
86+ name = name ,
87+ version = version ,
88+ declared_license = declared_license ,
89+ copyright = copyright_statement ,
90+ parties = parties ,
91+ homepage_url = homepage_url ,
92+ download_url = download_url ,
93+ )
94+
95+ about_package .extra_data ['about_resource' ] = package_data .get ('about_resource' )
96+ yield about_package
0 commit comments