Add pyinstaller step
	
		
			
	
		
	
	
		
			
				
	
				deploy 
				
					Details
				
			
		
	
				
					
				
			
				
	
				deploy 
				
					Details
				
			
		
	This commit is contained in:
		
							parent
							
								
									b0cc18dc8e
								
							
						
					
					
						commit
						0682ac8961
					
				|  | @ -72,7 +72,7 @@ COMMANDS | |||
|          A method for getting kernel version | ||||
| ``` | ||||
| 
 | ||||
| ## Making the tool more complex | ||||
| ## Step 3. Making the tool more complex | ||||
| For example, we also want our tool to be able to print the kernel version in short form, like this: `6.2.2`. | ||||
| We rewrite the code as follows: | ||||
| ```python | ||||
|  | @ -124,4 +124,17 @@ FLAGS | |||
|     -f, --format=FORMAT | ||||
|         Type: ('short', 'full') | ||||
|         Default: 'full' | ||||
| ``` | ||||
| ``` | ||||
| 
 | ||||
| ## Step 4. Create a binary file | ||||
| 
 | ||||
| First install `pyinstaller`: | ||||
| ```bash | ||||
| pip install pytinstaller | ||||
| ``` | ||||
| Then we run the command: | ||||
| ``` | ||||
| pyinstaller my-cli-tool --onefile | ||||
| ``` | ||||
| A folder `dist` shoud appear, and a binary file `my-cli-tool` inside it with all dependencies, which can be used even on servers, | ||||
| which do not have python or fire installed. Just put this file in the path `/usr/local/bin` and `my-cli-tool` can be used! | ||||
|  | @ -72,7 +72,7 @@ COMMANDS | |||
|         A method for getting kernel version | ||||
| ``` | ||||
| 
 | ||||
| ## Усложняем инструмент | ||||
| ## Шаг 3. Усложняем инструмент | ||||
| Например, мы хотим также, чтобы наш инструмент мог выводить версию ядра в коротком варианте, то есть так: `6.2.2`. | ||||
| Переписываем код следующим образом: | ||||
| ```python | ||||
|  | @ -124,4 +124,17 @@ FLAGS | |||
|     -f, --format=FORMAT | ||||
|         Type: ('short', 'full') | ||||
|         Default: 'full' | ||||
| ``` | ||||
| ``` | ||||
| 
 | ||||
| ## Шаг 4. Создаём бинарный файл | ||||
| 
 | ||||
| Сначала устанавливаем `pyinstaller`: | ||||
| ```bash | ||||
| pip install pytinstaller | ||||
| ``` | ||||
| Затем запускаем команду: | ||||
| ``` | ||||
| pyinstaller my-cli-tool --onefile | ||||
| ``` | ||||
| У вас должна появиться папка `dist`, а в ней файл бинарный `my-cli-tool` со всеми зависимостями, который можно использовать даже на серверах, | ||||
| на которых не установлен python или fire. Просто кладём этот файл по пути `/usr/local/bin` и `my-cli-tool` можно использовать! | ||||
		Loading…
	
		Reference in New Issue