File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 ` s:softwareVersion ` (#90 )
77* Allow creation of EOAP-only and xcube-server-only images, omitting
88 unnecessary dependencies (#56 )
9+ * Add a utility function to read annotations from notebook code (#91 )
910
1011## Changes in 0.1.2
1112
Original file line number Diff line number Diff line change @@ -377,3 +377,16 @@ def test_read_datasets_from_product_missing_items(
377377 params .read_datasets_from_product (tmp_path , {})
378378 for substring in "missing" , "foo" , "bar" :
379379 assert substring in str (error )
380+
381+
382+ def test_read_annotations_from_code ():
383+ import textwrap
384+
385+ annotated_code = textwrap .dedent ("""
386+ my_int: int = 42
387+ eoproduct: "EOInput" = None
388+ """ )
389+ assert NotebookParameters .read_annotations (annotated_code ) == {
390+ "my_int" : "int" ,
391+ "eoproduct" : "'EOInput'" ,
392+ }
Original file line number Diff line number Diff line change @@ -234,3 +234,13 @@ def cwl_type(type_: type) -> str:
234234 }[type_ ]
235235 except KeyError :
236236 raise ValueError (f"Unhandled type { type_ } " )
237+
238+ @staticmethod
239+ def read_annotations (code : str ) -> dict [str , str ]:
240+ import ast
241+
242+ return {
243+ ast .unparse (node .target ): ast .unparse (node .annotation )
244+ for node in ast .walk (ast .parse (code ))
245+ if isinstance (node , ast .AnnAssign )
246+ }
You can’t perform that action at this time.
0 commit comments