44
55from setuptools import Command , setup
66from setuptools .command .build_py import build_py
7- from setuptools .command .develop import develop as develop_cmd
7+ from setuptools .command .develop import develop
88
99
1010class BaseCommand (Command ):
1111 """A valid no-op command for setuptools & distutils."""
1212
13- description = "A no-op command."
14- user_options = []
13+ description : str = "A no-op command."
14+ editable_mode : bool = True
15+ user_options : list = []
1516
1617 def initialize_options (self ):
1718 pass
@@ -23,6 +24,10 @@ def run(self):
2324 pass
2425
2526
27+ class DevelopCommand (develop ):
28+ editable_mode : bool = True
29+
30+
2631def copy_copyright (cmd , directory ):
2732 # Copy the COPYRIGHT information into the package root
2833 iris_build_dir = os .path .join (directory , "iris" )
@@ -40,41 +45,45 @@ def build_std_names(cmd, directory):
4045 cmd .spawn (args )
4146
4247
43- def custom_cmd (command_to_override , functions , help_doc = "" ):
48+ def custom_cmd (klass , functions , help = "" ):
4449 """
4550 Allows command specialisation to include calls to the given functions.
4651
4752 """
4853
49- class ExtendedCommand ( command_to_override ):
50- description = help_doc or command_to_override .description
54+ class CustomCommand ( klass ):
55+ description = help or klass .description
5156
5257 def run (self ):
53- # Run the original command first to make sure all the target
54- # directories are in place.
55- command_to_override .run (self )
58+ # Run the original command to perform associated behaviour.
59+ klass .run (self )
5660
61+ # Determine the target root directory
5762 if self .editable_mode :
58- print (" [Running in-place]" )
5963 # Pick the source dir instead (currently in the sub-dir "lib").
60- dest = "lib"
64+ target = "lib"
65+ msg = "in-place"
6166 else :
6267 # Not editable - must be building.
63- dest = self .build_lib
68+ target = self .build_lib
69+ msg = "as-build"
70+
71+ print (f"\n [Running { msg } ]" )
6472
73+ # Run the custom command functions.
6574 for func in functions :
66- func (self , dest )
75+ func (self , target )
6776
68- return ExtendedCommand
77+ return CustomCommand
6978
7079
7180custom_commands = {
72- "develop" : custom_cmd (develop_cmd , [build_std_names ]),
81+ "develop" : custom_cmd (DevelopCommand , [build_std_names ]),
7382 "build_py" : custom_cmd (build_py , [build_std_names , copy_copyright ]),
7483 "std_names" : custom_cmd (
7584 BaseCommand ,
7685 [build_std_names ],
77- help_doc = "generate CF standard name module" ,
86+ help = "generate CF standard names module" ,
7887 ),
7988}
8089
0 commit comments