11import argparse
2- import inspect
32import logging
43import pathlib
4+ import typing as T
55
6+ from packaging .version import Version
7+
8+ from . import installer
69from . import pyproject
10+ from .errors import Error
711from .utils import handle_cli_error
812
913
@@ -16,10 +20,29 @@ class Init:
1620 """
1721
1822 def __init__ (self , parser : argparse .ArgumentParser ):
19- pass
23+ parser .add_argument (
24+ "version" ,
25+ nargs = "?" ,
26+ help = "Manually specify the RobotPy package version to use instead of autodetecting it" ,
27+ type = Version ,
28+ )
2029
2130 @handle_cli_error
22- def run (self , main_file : pathlib .Path , project_path : pathlib .Path ):
31+ def run (
32+ self ,
33+ main_file : pathlib .Path ,
34+ project_path : pathlib .Path ,
35+ version : T .Optional [Version ],
36+ ):
37+
38+ supported_year = int (installer ._WPILIB_YEAR )
39+ if version is not None and version .major != int (installer ._WPILIB_YEAR ):
40+ msg = (
41+ f"Only RobotPy { supported_year } .x is supported by this version "
42+ f"of robotpy-installer (specified { version } )"
43+ )
44+ raise Error (msg )
45+
2346 project_path .mkdir (parents = True , exist_ok = True )
2447
2548 # Create robot.py if it doesn't already exist
@@ -33,7 +56,9 @@ def run(self, main_file: pathlib.Path, project_path: pathlib.Path):
3356 # Create pyproject.toml if it doesn't already exist
3457 pyproject_path = pyproject .toml_path (project_path )
3558 if not pyproject_path .exists ():
36- pyproject .write_default_pyproject (project_path )
59+ pyproject .write_default_pyproject (
60+ project_path , str (version ) if version is not None else None
61+ )
3762
3863 logger .info ("Created %s" , pyproject_path )
3964
0 commit comments