Managing FastAPI Projects with Poetry: A Step-by-Step Guide

Image
This guide will walk you through how to use Poetry to manage dependencies and structure your project in FastAPI . It includes detailed explanations of Poetry's core concepts and commands to help prevent issues that can arise during team collaboration and deployment. 1. What is Poetry? Poetry is a dependency management and packaging tool for Python. It goes beyond simply installing libraries by allowing you to clearly declare the dependencies your project needs and ensuring that all developers on the project have the same library versions. Clarity in Dependency Management : Explicitly manage your project's basic information and required libraries through the pyproject.toml file. Reproducible Builds : By locking all dependency versions in the poetry.lock file, it fundamentally prevents "it works on my machine" problems. Integrated Development Environment : It automatically creates and manages isolated virtual environments for each project and handles mo...

Setting Up a Modern Vim 9.x IDE on Ubuntu or Linux

vim 9.1

This guide walks you through the process of transforming the terminal on a new Ubuntu or Linux server into a powerful, IDE-like environment. We will accomplish this by installing the latest Vim 9.x, setting up a plugin manager, and configuring essential plugins for a modern development workflow.

Step 1: Create Vim Directories

First, let's create the directories where Vim's settings will be stored. These folders will hold backup files, swap files, and a persistent undo history, which helps keep your project folders clean and improves data safety.

# Pre-create directories for Vim settings
mkdir -p ~/.vim/undodir ~/.vim/backupdir ~/.vim/swapdir

Step 2: Prepare the .vimrc File

Next, create Vim's configuration file, ~/.vimrc. Copy the content below and paste it into your ~/.vimrc file. This configuration includes a list of plugins, key mappings, UI settings, and more.

# Save the following content as your ~/.vimrc file.
" === Plugin Manager: vim-plug ===
" Initializes vim-plug, specifying the directory where plugins will be installed.
call plug#begin('~/.vim/plugged')

" === Plugin List ===
Plug 'vim-airline/vim-airline'         " Status line enhancement
Plug 'vim-airline/vim-airline-themes'   " Themes for vim-airline
Plug 'tpope/vim-sensible'               " Provides sensible default settings
Plug 'tpope/vim-commentary'             " Easy code commenting (gcc, gc)
Plug 'morhetz/gruvbox'                  " A color scheme (theme)
Plug 'sheerun/vim-polyglot'             " Syntax highlighting for many languages
" Add more plugins here: Plug '...'

" Finalizes the vim-plug section. All plugins must be listed before this.
call plug#end()

" === Basic Settings ===
syntax on                             " Enable syntax highlighting
filetype plugin indent on             " Enable filetype detection, plugins, and indentation
set hlsearch                          " Highlight all search matches
set number relativenumber             " Show hybrid line numbers (recommended)
set autoindent                        " Copy indent from current line when starting a new line
set scrolloff=2                       " Keep at least 2 lines visible above/below the cursor
set wildmode=longest,list             " Make command-line completion behave more like bash
set tabstop=4                         " Set tab width to 4 spaces
set shiftwidth=4                      " Set auto-indent width to 4 spaces
set expandtab                         " Use spaces instead of tab characters
set smartindent                       " Enable smart auto-indenting for C-like languages
set smartcase                         " Ignore case in search unless an uppercase letter is used
set incsearch                         " Show search matches as you type
set backspace=eol,start,indent        " Allow backspace over everything in insert mode
set history=256                       " Number of commands to remember in history
set laststatus=2                      " Always show the status line
set showmatch                         " Briefly jump to matching brackets: (), [], {}

" === File Encoding ===
set encoding=utf-8                    " Set Vim's internal text encoding to UTF-8
set fileencoding=utf-8                " Set the default encoding for new files to UTF-8
" Set the order of encodings to try when opening a file. Essential for handling legacy Korean (cp949) files.
set fileencodings=ucs-bom,utf-8,cp949,latin1

" === UI ===
set ruler                             " Always show cursor position (line, column) in the status bar

" --- Gruvbox Theme Settings ---
" Set the contrast for the gruvbox theme. Options: 'soft', 'medium', 'hard'.
let g:gruvbox_contrast_dark = 'medium'
set background=dark                   " Inform Vim that a dark terminal background is used
set termguicolors                     " Enable true color support in the terminal for better colors
colorscheme gruvbox                   " Apply the gruvbox color scheme

" === Backup and Undo Settings ===
set backup                            " Keep a backup copy of the file after overwriting
set undofile                          " Save undo history to a file
set backupdir=~/.vim/backupdir        " Set directory for backup files
set directory=~/.vim/swapdir          " Set directory for swap files
set undodir=~/.vim/undodir            " Set directory for persistent undo files

" === Language Setting ===
" Force Vim's UI messages to Korean. (Unnecessary if the system locale is already set correctly).
" let $LANG = 'ko_KR.UTF-8'

" === Airline Plugin Settings ===
" Enable airline's tabline extension to manage the list of open buffers/tabs.
let g:airline#extensions#tabline#enabled = 1
" Format the tabline to show unique filenames if paths are long and similar.
let g:airline#extensions#tabline#formatter = 'unique_tail'

Step 3: Install the Latest Vim 9.x

Ubuntu 24.04 already provides Vim 9.1 from its default repositories, but Ubuntu 22.04 defaults to providing Vim version 8.2.3995. In this case, you need to add a PPA to install Vim 9.x.

# 1. Install prerequisite packages for adding a PPA.
sudo apt update
sudo apt install software-properties-common -y

# 2. Add the Vim PPA to your system.
sudo add-apt-repository ppa:jonathonf/vim -y

# 3. Update the package list again.
sudo apt update

# 4. Install Vim. It will now be installed from the PPA.
sudo apt install vim -y

# 5. Verify the installed version to confirm it is 9.x.
vim --version

Step 4: Install the Plugin Manager vim-plug

Our .vimrc uses a plugin manager called vim-plug. You must install it by running the command below for your .vimrc to work correctly.

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

This command downloads the vim-plug executable file from GitHub and saves it to the correct path (~/.vim/autoload/) that Vim can recognize.

Step 5: Install the Plugins (:PlugInstall)

All preparations are complete. The final step is to install the plugins listed in your .vimrc.

On the first run, you may see errors about missing plugins. This is normal, so don't worry and just press Enter to proceed.

Launch Vim, and from within the editor in Normal Mode, type the following command and press Enter:

:PlugInstall

This command will cause vim-plug to read the list of plugins from your .vimrc and begin installing them automatically. A new window will open showing the installation progress, and you will see a "Finished!" message upon completion.

Once the installation is done, close the status window with the :q command, and then exit Vim completely with :q again. When you restart Vim, you will see that all the plugins, including the Gruvbox theme and the Airline status bar, have been beautifully applied.

Comments

Popular posts from this blog

Resolving Key Exchange Failure When Connecting with SecureCRT to OpenSSH

SecureCRT] How to Back Up and Restore SecureCRT Settings on Windows

How to Set Up Vaultwarden (Bitwarden) on Synology NAS (Best Free Alternative to LastPass)