Skip to content

Commit

Permalink
Poetry setup and brief documentation about my switch from pip install (
Browse files Browse the repository at this point in the history
…#1)

Poetry setup and brief documentation about my switch from pip install
and custom scripts to Poetry usage

Files created:
- poetry.lock
- pyproject.toml
- streamlit_30days_learning/__init__.py
- tests/__init__.py
  • Loading branch information
disouzam authored Oct 12, 2024
2 parents 073a043 + ee4f153 commit 4c3ff8a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Custom files
README.html
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# streamlit-30days-learning
Repository to play with streamlit, loosely following the 30 days challenge at https://30days.streamlit.app/
# About
Repository to play with streamlit, loosely following the 30 days challenge at https://30days.streamlit.app/

# Dependency management

In my previous projects (open and closed source ones), I've been playing with virtual environments using pip and some custom designed bash scripts to run pip install and also to freeze the dependencies (especially the indirect or transitive ones) in requirements.txt files with the following hierarchy:
- `requirements.in`: manually edited, with the package that is required for some new functionality
- `requirements.txt`: after compilation of `requirements.in` using the following command
> ```bash
> pip-compile --generate-hashes --rebuild --no-strip-extras --emit-find-links ./../../requirements.in
> ```
a `requirements.txt` is generated and then used afterwards to run all necessary `pip install` instances
- `requirementsALL.txt`: installation of dependencies is done using
>```bash
>python -m pip install -r ./../../requirements.txt
>```
and after installation is complete, all dependencies (direct, indirect and tooling of Python) is frozen as a file in source control system using the following command:
>```bash
>python -m pip freeze --all > ./../../requirementsALL.txt
>```
All these steps are performed after the virtual environment is created so that dependencies are properly installed in virtual environment rather than on global Python environment. The detailed configuration can be seen in my sample-python-repo ([setup.sh](https://github.com/disouzam/sample-python-repo/blob/main/setup.sh))
While this process works well, I decided to understand the Poetry tool and the following resources were indeed useful:
- [Gerenciando pacotes e ambientes com Poetry - Live de Python #179 - por Eduardo Mendes](https://www.youtube.com/watch?v=ZOSWdktsKf0)
- [Python Poetry in 8 Minutes by ArjanCodes](https://www.youtube.com/watch?v=Ji2XDxmXSOM)
- [How to Create and Use Virtual Environments in Python With Poetry by ArjanCodes](https://www.youtube.com/watch?v=0f3moPe_bhk)
So this repository represents my first experience with Poetry.
## Installing Poetry
There are at least two ways to install Poetry: using pip to install in global Python environment or using PowerShell to install it (in Windows) using the following command:
```PowerShell
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
```
For more details, see official documentation: [Python-Poetry website](https://python-poetry.org/docs/#installing-with-the-official-installer)
## Initialization of project
To start using Poetry, it is enough to run (https://python-poetry.org/docs/basic-usage/#project-setup)
```bash
poetry new [name_of-the-project]
```
This command will prepare a folder structure for the project and also to create tests and also create a `pyproject.toml` file with project's metadata and its requirements.
7 changes: 7 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "streamlit_30days_learning"
version = "0.1.0"
description = "A project where I will follow streamlit 30-days challenge"
authors = ["Dickson Souza <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file.
Empty file added tests/__init__.py
Empty file.

0 comments on commit 4c3ff8a

Please sign in to comment.