@@ -83,6 +83,40 @@ def _get_package_name(toml_file: str) -> str:
8383 return name
8484
8585
86+ def _sanitize_dependency (dep : str ) -> str :
87+ # Remove upper bound constraints (e.g., ", <3" or ",<3") as Rhino doesn't support them
88+ sanitized = re .split (r"\s*,\s*[<>=]" , dep )[0 ]
89+ sanitized = sanitized .split ("#" )[0 ].strip () # Remove inline comments
90+ return sanitized
91+
92+
93+ def _get_deps_from_requirements (req_filepath : str ) -> str :
94+ with open (req_filepath , "r" ) as req_file :
95+ dependencies = []
96+ for line in req_file :
97+ line = line .strip ()
98+ if line and not line .startswith ("#" ):
99+ dependencies .append (_sanitize_dependency (line ))
100+ return dependencies
101+
102+
103+ def _get_dependencies (base_folder : str ) -> str :
104+ toml_filepath = os .path .join (base_folder , "pyproject.toml" )
105+ with open (toml_filepath , "r" ) as f :
106+ toml = tomlkit .load (f )
107+
108+ dependencies = toml .get ("project" ).get ("dependencies" )
109+ if dependencies :
110+ return [_sanitize_dependency (dep ) for dep in dependencies ]
111+
112+ dynamic_deps = toml .get ("tool" ).get ("setuptools" ).get ("dynamic" ).get ("dependencies" )
113+ if dynamic_deps and "file" in dynamic_deps :
114+ req_filepath = os .path .join (base_folder , dynamic_deps ["file" ])
115+ return _get_deps_from_requirements (req_filepath )
116+
117+ return []
118+
119+
86120def _get_user_object_path (context ):
87121 if hasattr (context , "ghuser_cpython" ):
88122 print ("checking ghuser_cpython" )
@@ -239,6 +273,8 @@ def update_gh_header(ctx, version: str = None, venv: str = None, dev: bool = Fal
239273 for env in envs .split (";" ):
240274 new_header .append (f"# env: { env .strip ()} \n " )
241275 if dev :
276+ dependencies = _get_dependencies (ctx .base_folder )
277+ new_header .append (f"# r: { ', ' .join (dependencies )} \n " )
242278 new_header .append (f"# env: { os .path .join (ctx .base_folder , 'src' )} \n " )
243279
244280 for file in Path (ctx .ghuser_cpython .source_dir ).glob ("**/code.py" ):
0 commit comments