Poetry
In this tutorial, we’ll walk through the process of creating a new repository on GitHub and setting up Poetry for dependency management in a Python project. This combination offers a robust solution for version control and package management, making it ideal for modern Python development.
Step 1: Create a New Repository on GitHub
First, let’s start by creating a new repository on GitHub:
- Log into GitHub - Visit GitHub and sign in with your account.
- Create a Repository:
- Click the “+” icon at the top right and select “New repository”.
- Provide a repository name and an optional description.
- Choose the repository visibility (public or private).
- You can initialize the repository with a README, .gitignore, or a license if needed.
- Click “Create repository”.
Step 2: Clone the Repository Locally
Once your repository is ready, clone it to your local machine:
# Open your terminal and navigate to the directory where you want to clone the repository
cd path_to_your_directory
# Clone the repository
git clone https://github.com/your_username/your_repository_name.git
# Navigate into the repository
cd your_repository_name
Step 3: Set Up Poetry for Dependency Management
Poetry helps manage dependencies and virtual environments. Here’s how to set it up:
- Install Poetry:
Run the following command in your terminal:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
Follow the on-screen instructions to complete the installation.
- Initialize Poetry:
In your project directory, start the Poetry configuration:
poetry init
This will guide you through creating the
pyproject.toml
file.
Step 4: Add Dependencies with Poetry
To add a dependency using Poetry, use the add
command:
poetry add package_name
Poetry will update your pyproject.toml
and poetry.lock
files accordingly.
Step 5: Commit Changes and Push to GitHub
Finally, commit your changes and push them to GitHub:
# Add changes to staging area
git add .
# Commit the changes
git commit -m "Initialize project with Poetry"
# Push the changes to GitHub
git push origin main
Conclusion
By following these steps, you’ve set up a new GitHub repository and configured Poetry for dependency management in your Python project. This setup not only simplifies dependency management but also leverages the power of Git for version control, making your development process more efficient and organized.
Feel free to explore more about Poetry and its features to fully utilize its capabilities in your projects.