88from  packaging .version  import  Version 
99import  tomlkit 
1010
11+ from  .config  import  SubprojectConfig 
1112from  .ctx  import  Context 
1213
1314
1415@dataclasses .dataclass  
1516class  ProjectInfo :
1617    pyproject_toml : pathlib .Path 
18+     cfg : SubprojectConfig 
1719    data : tomlkit .TOMLDocument 
1820    changed : bool  =  False 
1921
@@ -32,15 +34,8 @@ def __init__(self, ctx: Context) -> None:
3234        # The required versions for everything 
3335        # - in theory projects could have different requirements, but in 
3436        #   practice this is simpler and we haven't had issues 
35-         # - .. and to make life easier, we only use this for build-system.requires, 
36-         #   which we happen to override in CI anyways 
3737        self .version_specs : typing .Dict [str , SpecifierSet ] =  {}
3838
39-         # robotpy-build is special 
40-         self .version_specs ["robotpy-build" ] =  SpecifierSet (
41-             self .cfg .params .robotpy_build_req 
42-         )
43- 
4439        # load all the pyproject.toml using tomlkit so we can make changes 
4540        # and retain all the comments 
4641        self .subprojects : typing .Dict [str , ProjectInfo ] =  {}
@@ -49,12 +44,17 @@ def __init__(self, ctx: Context) -> None:
4944                data  =  tomlkit .load (fp )
5045
5146            self .subprojects [name ] =  ProjectInfo (
52-                 pyproject_toml = project .pyproject_path , data = data 
47+                 pyproject_toml = project .pyproject_path ,
48+                 data = data ,
49+                 cfg = self .cfg .subprojects [name ],
5350            )
5451
55-             self .version_specs [project .pyproject_name ] =  SpecifierSet (
56-                 f"~={ project .cfg .min_version }  
57-             )
52+             version  =  self .cfg .py_versions [project .cfg .py_version ]
53+ 
54+             self .version_specs [project .pyproject_name ] =  SpecifierSet (f"=={ version }  )
55+ 
56+         for  name , spec  in  self .cfg .params .requirements .items ():
57+             self .version_specs [name ] =  SpecifierSet (spec )
5858
5959    @property  
6060    def  changed (self ) ->  bool :
@@ -105,7 +105,10 @@ def _update_requirements(
105105    def  update_requirements (self ):
106106        for  info  in  self .subprojects .values ():
107107            data  =  info .data 
108-             pypi_name  =  data ["tool" ]["robotpy-build" ]["metadata" ]["name" ]
108+             pypi_name  =  data ["project" ]["name" ]
109+ 
110+             # update project.version 
111+             self ._update_pyversion (info )
109112
110113            # update build-system 
111114            self ._update_requirements (
@@ -115,57 +118,69 @@ def update_requirements(self):
115118                data ["build-system" ]["requires" ],
116119            )
117120
118-             # update tool.robotpy-build.metadata: install_requires  
121+             # project.dependencies  
119122            self ._update_requirements (
120123                info ,
121124                pypi_name ,
122-                 "metadata.install_requires " ,
123-                 data ["tool " ]["robotpy-build"  ][ "metadata" ][ "install_requires "
125+                 "project.dependencies " ,
126+                 data ["project " ]["dependencies " ],
124127            )
125128
126129    def  _update_maven (self , info : ProjectInfo ):
127130        data  =  info .data 
128-         iter  =  list ( data [ "tool" ][ "robotpy-build" ][ "wrappers" ]. items ()) 
129-         if   "static_libs"   in   data ["tool" ]["robotpy- build" ]: 
130-             iter   +=   list ( data [ "tool" ][ " robotpy-build" ][ "static_libs" ]. items () )
131-         for   pkg ,  wrapper   in   iter : 
132-              if  ( 
133-                  "maven_lib_download"   not   in   wrapper 
134-                  or   wrapper [ "maven_lib_download" ][ "artifact_id" ] 
135-                  in   self . cfg . params . exclude_artifacts 
136-             ) :
131+         iter  =  ( 
132+              data ["tool" ]["hatch"  ][ " build"[ "hooks" ] 
133+             . get ( " robotpy" , {} )
134+             . get ( "maven_lib_download" , []) 
135+         ) 
136+ 
137+         for   dl   in   iter : 
138+ 
139+             if   dl [ "artifact_id" ]  in   self . cfg . params . exclude_artifacts :
137140                continue 
138141
139-             if  wrapper ["maven_lib_download" ]["repo_url" ] !=  self .wpilib_bin_url :
142+             artifact_id  =  dl ["artifact_id" ]
143+ 
144+             if  dl ["repo_url" ] !=  self .wpilib_bin_url :
140145                print (
141146                    "* " ,
142-                     pkg ,
147+                     artifact_id ,
143148                    "repo url:" ,
144-                     wrapper [ "maven_lib_download" ] ["repo_url" ],
149+                     dl ["repo_url" ],
145150                    "=>" ,
146151                    self .wpilib_bin_url ,
147152                )
148153                self .commit_changes .add (f"repo updated to { self .wpilib_bin_url }  )
149154                info .changed  =  True 
150-                 wrapper [ "maven_lib_download" ] ["repo_url" ] =  self .wpilib_bin_url 
155+                 dl ["repo_url" ] =  self .wpilib_bin_url 
151156
152-             if  wrapper [ "maven_lib_download" ] ["version" ] !=  self .wpilib_bin_version :
157+             if  dl ["version" ] !=  self .wpilib_bin_version :
153158                print (
154159                    "* " ,
155-                     pkg ,
160+                     artifact_id ,
156161                    "so version:" ,
157-                     wrapper [ "maven_lib_download" ] ["version" ],
162+                     dl ["version" ],
158163                    "=>" ,
159164                    self .wpilib_bin_version ,
160165                )
161166                self .commit_changes .add (f"lib updated to { self .wpilib_bin_version }  )
162167                info .changed  =  True 
163-                 wrapper [ "maven_lib_download" ] ["version" ] =  self .wpilib_bin_version 
168+                 dl ["version" ] =  self .wpilib_bin_version 
164169
165170    def  update_maven (self ):
166171        for  data  in  self .subprojects .values ():
167172            self ._update_maven (data )
168173
174+     def  _update_pyversion (self , info : ProjectInfo ):
175+         current_version  =  info .data ["project" ]["version" ]
176+         version  =  self .cfg .py_versions [info .cfg .py_version ]
177+ 
178+         if  current_version  !=  version :
179+             name  =  info .data ["project" ]["name" ]
180+             print (f"* { name } { current_version !r} { version !r}  )
181+             self .commit_changes .add (f"{ name } { version }  )
182+             info .changed  =  True 
183+ 
169184    def  update (self ):
170185        self .update_maven ()
171186        self .update_requirements ()
0 commit comments