1111
1212Notably, does not read nontrivial setup.py or attempt to emulate anything that can't be read staticly.
1313"""
14+
1415import ast
1516import re
17+ from dataclasses import asdict
1618from pathlib import Path
1719
1820try :
@@ -81,6 +83,54 @@ def from_pep621_checkout(path: Path) -> bytes:
8183 for i in v :
8284 buf .append ("Requires-Dist: " + merge_extra_marker (extra_name , i ) + "\n " )
8385
86+ name = doc .get ("project" , {}).get ("name" )
87+ if name :
88+ buf .append (f"Name: { name } \n " )
89+
90+ # Version
91+ version = doc .get ("project" , {}).get ("version" )
92+ if version :
93+ buf .append (f"Version: { version } \n " )
94+
95+ # Requires-Python
96+ requires_python = doc .get ("project" , {}).get ("requires-python" )
97+ if requires_python :
98+ buf .append (f"Requires-Python: { requires_python } \n " )
99+
100+ # Project-URL
101+ urls = doc .get ("project" , {}).get ("urls" )
102+ if urls :
103+ for k , v in urls .items ():
104+ buf .append (f"Project-URL: { k } ={ v } \n " )
105+
106+ # Author
107+ authors = doc .get ("project" , {}).get ("authors" )
108+ if authors :
109+ for author in authors :
110+ try :
111+ buf .append (f"Author: { author .get ('name' )} \n " )
112+ except AttributeError :
113+ pass
114+ try :
115+ buf .append (f"Author-Email: { author .get ('email' )} \n " )
116+ except AttributeError :
117+ pass
118+
119+ # Summary
120+ summary = doc .get ("project" , {}).get ("description" )
121+ if summary :
122+ buf .append (f"Summary: { summary } \n " )
123+
124+ # Description
125+ description = doc .get ("project" , {}).get ("readme" )
126+ if description :
127+ buf .append (f"Description: { description } \n " )
128+
129+ # Keywords
130+ keywords = doc .get ("project" , {}).get ("keywords" )
131+ if keywords :
132+ buf .append (f"Keywords: { keywords } \n " )
133+
84134 return "" .join (buf ).encode ("utf-8" )
85135
86136
@@ -193,6 +243,45 @@ def from_poetry_checkout(path: Path) -> bytes:
193243 f"Requires-Dist: { vi } { constraints } { merge_extra_marker (k , markers )} "
194244 )
195245
246+ name = doc .get ("tool" , {}).get ("poetry" , {}).get ("name" )
247+ if name :
248+ buf .append (f"Name: { name } \n " )
249+
250+ # Version
251+ version = doc .get ("tool" , {}).get ("poetry" , {}).get ("version" )
252+ if version :
253+ buf .append (f"Version: { version } \n " )
254+
255+ # Requires-Python
256+ requires_python = doc .get ("tool" , {}).get ("poetry" , {}).get ("requires-python" )
257+ if requires_python :
258+ buf .append (f"Requires-Python: { requires_python } \n " )
259+
260+ # Project-URL
261+ url = doc .get ("tool" , {}).get ("poetry" , {}).get ("homepage" )
262+ if url :
263+ buf .append (f"Home-Page: { url } \n " )
264+
265+ # Author
266+ authors = doc .get ("tool" , {}).get ("poetry" , {}).get ("authors" )
267+ if authors :
268+ buf .append (f"Author: { authors } \n " )
269+
270+ # Summary
271+ summary = doc .get ("tool" , {}).get ("poetry" , {}).get ("description" )
272+ if summary :
273+ buf .append (f"Summary: { summary } \n " )
274+
275+ # Description
276+ description = doc .get ("tool" , {}).get ("poetry" , {}).get ("readme" )
277+ if description :
278+ buf .append (f"Description: { description } \n " )
279+
280+ # Keywords
281+ keywords = doc .get ("tool" , {}).get ("poetry" , {}).get ("keywords" )
282+ if keywords :
283+ buf .append (f"Keywords: { keywords } \n " )
284+
196285 return "" .join (buf ).encode ("utf-8" )
197286
198287
@@ -206,6 +295,55 @@ def from_setup_cfg_checkout(path: Path) -> bytes:
206295 rc .read_string (data )
207296
208297 buf : list [str ] = []
298+ try :
299+ buf .append (f"Name: { rc .get ('metadata' , 'name' )} \n " )
300+ except (NoOptionError , NoSectionError ):
301+ pass
302+
303+ # Requires-Python
304+ try :
305+ buf .append (f"Requires-Python: { rc .get ('options' , 'python_requires' )} \n " )
306+ except (NoOptionError , NoSectionError ):
307+ pass
308+
309+ # Home-Page
310+ try :
311+ buf .append (f"Home-Page: { rc .get ('metadata' , 'url' )} \n " )
312+ except (NoOptionError , NoSectionError ):
313+ pass
314+
315+ # Author
316+ try :
317+ buf .append (f"Author: { rc .get ('metadata' , 'author' )} \n " )
318+ except (NoOptionError , NoSectionError ):
319+ pass
320+
321+ # Author-Email
322+ try :
323+ buf .append (f"Author-Email: { rc .get ('metadata' , 'author_email' )} \n " )
324+ except (NoOptionError , NoSectionError ):
325+ pass
326+
327+ # Summary
328+ try :
329+ buf .append (f"Summary: { rc .get ('metadata' , 'description' )} \n " )
330+ except (NoOptionError , NoSectionError ):
331+ pass
332+
333+ # Description
334+ try :
335+ buf .append (f"Description: { rc .get ('metadata' , 'long_description' )} \n " )
336+ except (NoOptionError , NoSectionError ):
337+ pass
338+
339+ # Description-Content-Type
340+ try :
341+ buf .append (
342+ f"Description-Content-Type: { rc .get ('metadata' , 'long_description_content_type' )} \n "
343+ )
344+ except (NoOptionError , NoSectionError ):
345+ pass
346+
209347 try :
210348 for dep in rc .get ("options" , "install_requires" ).splitlines ():
211349 dep = dep .strip ()
@@ -229,6 +367,8 @@ def from_setup_cfg_checkout(path: Path) -> bytes:
229367 "Requires-Dist: " + merge_extra_marker (extra_name , i ) + "\n "
230368 )
231369
370+ # TODO name requires_python url project_urls
371+
232372 return "" .join (buf ).encode ("utf-8" )
233373
234374
@@ -252,6 +392,7 @@ def from_setup_py_checkout(path: Path) -> bytes:
252392 raise ValueError ("Complex setup call can't extract reqs" )
253393 for dep in r :
254394 buf .append (f"Requires-Dist: { dep } \n " )
395+
255396 er = v .setup_call_args .get ("extras_require" )
256397 if er :
257398 if er is UNKNOWN :
@@ -262,6 +403,31 @@ def from_setup_py_checkout(path: Path) -> bytes:
262403 for i in deps :
263404 buf .append ("Requires-Dist: " + merge_extra_marker (extra_name , i ) + "\n " )
264405
406+ n = v .setup_call_args .get ("name" )
407+ if n :
408+ if n is UNKNOWN :
409+ raise ValueError ("Complex setup call can't extract name" )
410+ buf .append (f"Name: { n } \n " )
411+
412+ n = v .setup_call_args .get ("python_requires" )
413+ if n :
414+ if n is UNKNOWN :
415+ raise ValueError ("Complex setup call can't extract python_requires" )
416+ buf .append (f"Requires-Python: { n } \n " )
417+
418+ n = v .setup_call_args .get ("url" )
419+ if n :
420+ if n is UNKNOWN :
421+ raise ValueError ("Complex setup call can't extract url" )
422+ buf .append (f"Home-Page: { n } \n " )
423+
424+ n = v .setup_call_args .get ("project_urls" )
425+ if n :
426+ if n is UNKNOWN :
427+ raise ValueError ("Complex setup call can't extract project_urls" )
428+ for k , v in n .items ():
429+ buf .append (f"Project-URL: { k } ={ v } \n " )
430+
265431 return "" .join (buf ).encode ("utf-8" )
266432
267433
@@ -270,6 +436,11 @@ def basic_metadata_from_source_checkout(path: Path) -> BasicMetadata:
270436
271437
272438if __name__ == "__main__" : # pragma: no cover
439+ import json
273440 import sys
274441
275- print (basic_metadata_from_source_checkout (Path (sys .argv [1 ])))
442+ md = basic_metadata_from_source_checkout (Path (sys .argv [1 ]))
443+ if md .reqs or md .name :
444+ print (json .dumps (asdict (md ), default = list ))
445+ else :
446+ sys .exit (1 )
0 commit comments