@@ -116,12 +116,16 @@ def name(cls):
116116 return cls .__name__
117117
118118 @classproperty
119- def cli_name (cls ):
120- """Package manager's CLI name.
119+ def cli_names (cls ):
120+ """List of CLI names the package manager is known as.
121+
122+ The supported CLI names are ordered by priority. This is used for example to
123+ help out the search of the right binary in the case of the python3/python2
124+ transition.
121125
122126 Is derived by default from the manager's ID.
123127 """
124- return cls .id
128+ return [ cls .id ]
125129
126130 @classproperty
127131 def virtual (cls ):
@@ -130,23 +134,31 @@ def virtual(cls):
130134 Virtual package manager are just skeleton classes used to factorize
131135 code among managers of the same family.
132136 """
133- return cls .__name__ == "PackageManager" or not cls .cli_name
137+ return cls .__name__ == "PackageManager" or not cls .cli_names
134138
135139 @cachedproperty
136140 def cli_path (self ):
137141 """Fully qualified path to the package manager CLI.
138142
139- Automaticaly search the location of the CLI in the system. Only checks
140- if the file exists. Its executability will be assessed later. See the
141- ``self.executable`` method below.
143+ Automaticaly search the location of the CLI in the system. Try multiple CLI
144+ names within several system path.
145+
146+ Only checks if the file exists. Its executability will be assessed later. See
147+ the ``self.executable`` method below.
142148
143- Returns `None` if CLI is not found or is not a file.
149+ Returns `None` if no CLI was found or those found were not a file.
144150 """
145151 # Check if the path exist in any of the environment locations.
146152 env_path = ":" .join (self .cli_search_path + [os .getenv ("PATH" )])
147- cli_path = which (self .cli_name , mode = os .F_OK , path = env_path )
153+
154+ # Search for multiple CLI names.
155+ for name in self .cli_names :
156+ cli_path = which (name , mode = os .F_OK , path = env_path )
157+ if cli_path :
158+ break
159+ logger .debug (f"{ name !r} CLI not found." )
160+
148161 if not cli_path :
149- logger .debug (f"{ self .cli_name } CLI not found." )
150162 return
151163
152164 # Check if path exist and is a file.
@@ -158,7 +170,7 @@ def cli_path(self):
158170 elif not cli_path .is_file ():
159171 logger .warning (f"{ cli_path } is not a file." )
160172 else :
161- logger .debug (f"CLI found at { cli_path } " )
173+ logger .debug (f"{ name !r } CLI found at { cli_path } " )
162174
163175 return cli_path
164176
0 commit comments