Skip to content

Commit 10ae36a

Browse files
committed
Replace poetry by uv
1 parent f785745 commit 10ae36a

30 files changed

+248
-197
lines changed

docs/0. Overview/0.6. Resources.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To propose a new project resource, please forward your suggestions to the course
2121
## Additional vendor resources
2222

2323
- **[MLOps Python Package](https://github.com/fmind/mlops-python-package)**
24+
- **[LLMOps Python Package](https://github.com/callmesora/llmops-python-package/)**
2425
- **[Cookiecutter MLOps Package](https://github.com/fmind/cookiecutter-mlops-package)**
2526
- [MLOps: Continuous delivery and automation pipelines in machine learning](https://cloud.google.com/architecture/mlops-continuous-delivery-and-automation-pipelines-in-machine-learning)
2627
- [The Big Book of MLOps](https://www.databricks.com/sites/default/files/2023-10/2023-10-eb-big-book-of-mlops-2nd-edition-v2-102723-final.pdf)

docs/1. Initializing/1.0. System.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ While [JupyterLab](https://jupyterlab.readthedocs.io/en/latest/) is an acceptabl
1414

1515
## Are additional software installations required?
1616

17-
Engaging with this course material necessitates installing several key software packages, including Python, Poetry, git, and VS Code. These tools form the backbone of your development workflow:
17+
Engaging with this course material necessitates installing several key software packages, including Python, uv, git, and VS Code. These tools form the backbone of your development workflow:
1818

1919
- **Python** is indispensable for all course-related coding activities.
20-
- **Poetry** offers an efficient way to manage Python package dependencies.
20+
- **uv** offers an efficient way to manage Python package dependencies.
2121
- **Git** is crucial for version control and collaboration.
2222
- **VS Code** is recommended for its integrated development environment (IDE) capabilities, although alternatives may be used based on personal preference or specific needs.
2323

docs/1. Initializing/1.3. Poetry.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ These configurations ensure that Poetry creates virtual environments directly wi
126126

127127
## How can you install dependencies for your project with Poetry?
128128

129-
Poetry differentiates between main (production) and development dependencies, offering an organized approach to dependency management. To add dependencies, use the following commands:
129+
Uv differentiates between main (production) and development dependencies, offering an organized approach to dependency management. To add dependencies, use the following commands:
130130

131131
```bash
132132
# For main dependencies
133-
$ poetry add pandas scikit-learn
133+
$ uv add pandas scikit-learn
134134

135135
# For development dependencies
136-
$ poetry add -G dev ipykernel
136+
$ uv add --group dev ipykernel
137137
```
138138

139139
Executing these commands updates the `pyproject.toml` file, accurately managing and versioning your project's dependencies.
@@ -144,9 +144,9 @@ In production, you can decide to install only the main dependencies using [this
144144
poetry install --only main
145145
```
146146

147-
## What is the difference between main and dev dependencies in Poetry?
147+
## What is the difference between main and dev dependencies in uv?
148148

149-
In Poetry, dependencies are divided into two types: main dependencies and development (dev) dependencies.
149+
In uv, dependencies are divided into two types: main dependencies and development (dev) dependencies.
150150

151151
**Main Dependencies**: These are essential for your project's production environment—your application can't run without them. For example, libraries like Pandas or XGBoost would be main dependencies for an MLOps project.
152152

docs/1. Initializing/1.4. git.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ When using Git, it's important to selectively track files. Consider the followin
4949

5050
- **Exclude Secrets**: Sensitive data, such as API keys and passwords, should never be committed to your repository.
5151
- **Manage Large Files**: For files exceeding 100MB (e.g., dataset files), use Git Large File Storage ([git-lfs](https://git-lfs.github.com/)) instead of directly committing them to your Git repository.
52-
- **Omit Cache Files**: Do not track temporary or environment-specific files (e.g., `.venv`, `poetry.lock`, log files) that don't contribute to the project's primary function.
52+
- **Omit Cache Files**: Do not track temporary or environment-specific files (e.g., `.venv`, `mlruns`, log files) that don't contribute to the project's primary function.
5353

5454
To exclude certain files and directories from being tracked, create a `.gitignore` file in your project's root directory. This file should list patterns to match filenames you wish to exclude, for example:
5555

docs/1. Initializing/1.6. VS Code.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,19 @@ You can find below some settings for configuring VS Code. Each setting is annota
238238
}
239239
```
240240

241-
## How to configure VS Code for using the [Jupyter Extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) with [Poetry](https://python-poetry.org/)?
241+
## How to configure VS Code for using the [Jupyter Extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) with [uv](https://docs.astral.sh/uv/)?
242242

243-
To configure VS Code for using the [Jupyter Extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) with [Poetry](https://python-poetry.org/), follow these steps to ensure that your Poetry-managed virtual environment is recognized within VS Code. This allows you to use the Jupyter Extension seamlessly with the Python interpreter provided by Poetry.
243+
To configure VS Code for using the [Jupyter Extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) with [uv](https://docs.astral.sh/uv/), follow these steps to ensure that your uv-managed virtual environment is recognized within VS Code. This allows you to use the Jupyter Extension seamlessly with the Python interpreter provided by uv.
244244

245245
1. **Install the Jupyter Extension**: First, ensure that the [Jupyter Extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) is installed in VS Code. You can find and install this extension from the [VS Code Marketplace](https://marketplace.visualstudio.com/VSCode).
246-
2. **Open Your Project in VS Code**: Open your project folder in VS Code. If you've just created a new Poetry project, this will be the directory containing your `pyproject.toml` file.
247-
3. **Select Python Interpreter**: To make VS Code use the Python interpreter from your Poetry environment:
246+
2. **Open Your Project in VS Code**: Open your project folder in VS Code. If you've just created a new uv project, this will be the directory containing your `pyproject.toml` file.
247+
3. **Select Python Interpreter**: To make VS Code use the Python interpreter from your uv environment:
248248
- Open the Command Palette (`Ctrl+Shift+P` on Windows/Linux, `Cmd+Shift+P` on macOS).
249249
- Type `Python: Select Interpreter` and select it.
250-
- Look for the interpreter that corresponds to your Poetry environment. It will typically be located under the `.venv` path within your project directory or listed as a virtual environment with your project's name.
250+
- Look for the interpreter that corresponds to your uv environment. It will typically be located under the `.venv` path within your project directory or listed as a virtual environment with your project's name.
251251
- Select the appropriate interpreter.
252-
4. **Verify Jupyter Notebook Configuration**: Create a new Jupyter notebook in VS Code (`*.ipynb` file) and verify that the cells execute using the Python interpreter from your Poetry environment. You can check the upper-right corner of the notebook interface to see which interpreter is currently active.
253-
5. **Install Necessary Libraries**: If you need additional Python libraries that are not yet part of your Poetry project, you can add them by running `poetry add <library-name>` in your terminal or command prompt. This ensures that all dependencies are managed by Poetry and available in the notebook.
252+
4. **Verify Jupyter Notebook Configuration**: Create a new Jupyter notebook in VS Code (`*.ipynb` file) and verify that the cells execute using the Python interpreter from your uv environment. You can check the upper-right corner of the notebook interface to see which interpreter is currently active.
253+
5. **Install Necessary Libraries**: If you need additional Python libraries that are not yet part of your uv project, you can add them by running `uv add <library-name>` in your terminal or command prompt. This ensures that all dependencies are managed by uv and available in the notebook.
254254

255255
## VS Code additional resources
256256

docs/2. Prototyping/2.0. Notebooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ As an alternative to notebooks, consider using the [Python Interactive Window](h
2828

2929
Using notebooks in the early stages of development offers many advantages; however, they are not well-suited for production environments due to several limitations:
3030

31-
- **Lack of Integration**: Notebooks often do not integrate seamlessly with tools commonly used in the Python software development ecosystem, such as testing frameworks (pytest), linting tools (ruff), and package managers (poetry).
31+
- **Lack of Integration**: Notebooks often do not integrate seamlessly with tools commonly used in the Python software development ecosystem, such as testing frameworks (pytest), linting tools (ruff), and package managers (uv).
3232
- **Mixed Content**: The intermingling of code, output, and narrative in a single document can complicate version control and maintenance, especially with complex projects.
3333
- **Non-Sequential Flow**: Notebooks do not enforce a linear execution order, which can lead to confusion and errors if cells are run out of sequence.
3434
- **Lack of Reusability**: The format of notebooks does not naturally encourage the development of reusable and modular code, such as functions, classes, or packages.

docs/2. Prototyping/2.1. Imports.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ In the realm of data science, a few key Python packages form the backbone of mos
3333
- **[Matplotlib](https://matplotlib.org/) or [Plotly](https://plotly.com/)**: For creating static, interactive, and animated visualizations.
3434
- **[Scikit-learn](https://scikit-learn.org/stable/)**: For machine learning, providing simple and efficient tools for data analysis and modeling.
3535

36-
To integrate these packages into your project using poetry, you can execute the following command in your terminal:
36+
To integrate these packages into your project using uv, you can execute the following command in your terminal:
3737

3838
```bash
39-
poetry add pandas numpy matplotlib scikit-learn plotly
39+
uv add pandas numpy matplotlib scikit-learn plotly
4040
```
4141

42-
This command tells poetry to download and install these packages, along with their dependencies, into your project environment, ensuring version compatibility and easy package management.
42+
This command tells uv to download and install these packages, along with their dependencies, into your project environment, ensuring version compatibility and easy package management.
4343

4444
## How should you organize your imports to facilitate your work?
4545

docs/2. Prototyping/2.2. Configs.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ Here's a practical illustration of configs within a notebook context:
1212

1313
```python
1414
# Define paths for caching and training data
15-
CACHE_PATH = '../.cache/'
16-
TRAIN_DATA_PATH = '../data/train.csv'
15+
ROOT = Path("../")
16+
DATA = str(ROOT / "data")
17+
CACHE = str(ROOT / ".cache")
18+
HOUR = str(DATA / "hour.csv")
1719
# Configure random state for reproducibility
18-
RANDOM_STATE = 0
20+
RANDOM = 42
21+
# Define dataset columns for feature engineering
22+
INDEX = "instant"
23+
TARGET = "cnt"
1924
# Setup dataset parameters for testing and shuffling
20-
SHUFFLE = True
21-
TEST_SIZE = 0.2
22-
TARGET = "SalePrice"
25+
SPLITS = 4
26+
SHUFFLE = False # required (time sensitive)
27+
TEST_SIZE = 24 * 30 * 2 # use 2 months for backtesting
2328
# Parameters for pipeline configurations
24-
CV = 5
2529
SCORING = "neg_mean_squared_error"
2630
PARAM_GRID = {
2731
"regressor__max_depth": [12, 15, 18, 21],

docs/2. Prototyping/2.4. Analysis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ For instance, [Plotly Express's `scatter_matrix`](https://plotly.com/python/splo
4646
import plotly.express as px
4747
df = pd.read_csv('your_dataset.csv')
4848
px.scatter_matrix(
49-
df, dimensions=["feature1", "feature2", "feature3"], color="target_variable",
50-
height=800, title="Scatter Matrix of Features"
49+
df, dimensions=["feature1", "feature2", "feature3"], color="target_variable",
50+
height=800, title="Scatter Matrix of Features"
5151
)
5252
```
5353

docs/2. Prototyping/2.5. Modeling.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ PARAM_GRID = {
135135
"regressor__max_depth": [15, 20, 25],
136136
"regressor__n_estimators": [150, 200, 250],
137137
}
138-
RANDOM_STATE = 0
139138

140139
splitter = model_selection.TimeSeriesSplit(n_splits=CV)
141140

docs/3. Productionizing/3.0. Package.md

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ Additionally, creating a package can enhance the maintainability of your code, e
1919

2020
## Which tool should you use to create a Python package?
2121

22-
The Python ecosystem provides several tools for packaging, each with its unique features and advantages. While the choice can seem overwhelming, as humorously depicted in the [xkcd comic on Python environments](https://xkcd.com/1987/), [Poetry](https://python-poetry.org/) emerges as a standout option. Poetry simplifies dependency management and packaging, offering an intuitive interface for developers.
22+
The Python ecosystem provides several tools for packaging, each with its unique features and advantages. While the choice can seem overwhelming, as humorously depicted in the [xkcd comic on Python environments](https://xkcd.com/1987/), [uv](https://docs.astral.sh/uv/) emerges as a standout option. Uv simplifies dependency management and packaging, offering an intuitive interface for developers.
2323

24-
To get started with Poetry for packaging, you can use the following commands:
24+
To get started with uv for packaging, you can use the following commands:
2525

26-
- **Initiate a Poetry package**:
26+
- **Initiate an uv package**:
2727

2828
```bash
29-
poetry init
29+
uv sync
3030
```
3131

3232
- **Start developing the package**:
3333

3434
```bash
35-
poetry install
35+
uv sync --all-groups
3636
```
3737

38-
- **Build a package with Poetry**:
38+
- **Build a package with uv**:
3939

4040
```bash
41-
poetry build --format wheel
41+
uv build --wheel
4242
```
4343

4444
At the end of the build process, a `.whl` file is generated in the `dist` folder with the name and version of the project from `pyproject.toml`.
@@ -49,35 +49,46 @@ For those seeking alternatives, tools like [PDM](https://pdm-project.org/en/late
4949

5050
Although [Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html) is a popular choice among data scientists for its ability to manage complex dependencies, it's important to be aware of its limitations. Challenges such as slow performance, a complex dependency resolver, and confusing channel management can hinder productivity. Moreover, Conda's integration with the Python ecosystem, especially with new standards like `pyproject.toml`, is limited. For managing complex dependencies in AI/ML projects, Docker containers present a robust alternative, offering better isolation and compatibility across environments.
5151

52-
## How can you install new dependencies with Poetry?
52+
## How can you install new dependencies with uv?
5353

54-
Please refer to [this section of the course](../1. Initializing/1.3. Poetry.md).
54+
Please refer to [this section of the course](../1. Initializing/1.3. uv.md).
5555

5656
## Which metadata should you provide to your Python package?
5757

58-
Including detailed metadata in your [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file is crucial for defining your package's identity and dependencies. This file should contain essential information such as the package name, version, authors, and dependencies. Here's an example that outlines the basic structure and content for your package's metadata:
58+
Including detailed metadata in your [`pyproject.toml`](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) file is crucial for defining your package's identity and dependencies. This file should contain essential information such as the package name, version, authors, and dependencies. Here's an example that outlines the basic structure and content for your package's metadata:
5959

6060
```toml
61-
# Example metadata for a Python package
61+
# https://docs.astral.sh/uv/reference/settings/
62+
# https://packaging.python.org/en/latest/guides/writing-pyproject-toml/
6263

63-
[tool.poetry]
64+
[project]
6465
name = "bikes"
65-
version = "1.0.0"
66+
version = "3.0.0"
6667
description = "Predict the number of bikes available."
67-
repository = "https://github.com/yourusername/mlops-python-package"
68-
documentation = "https://yourusername.github.io/mlops-python-package/"
69-
authors = ["Your Name <[email protected]>"]
68+
authors = [{ name = "Médéric HURIER", email = "[email protected]" }]
7069
readme = "README.md"
71-
license = "CC BY"
70+
requires-python = ">=3.12"
71+
dependencies = []
72+
license = { file = "LICENSE.txt" }
7273
keywords = ["mlops", "python", "package"]
73-
packages = [{ include = "bikes", from = "src" }]
7474

75-
[tool.poetry.dependencies]
76-
python = "^3.10"
75+
[project.urls]
76+
Homepage = "https://github.com/fmind/bikes"
77+
Documentation = "https://fmind.github.io/bikes"
78+
Repository = "https://github.com/fmind/bikes"
79+
"Bug Tracker" = "https://github.com/fmind/bikes/issues"
80+
Changelog = "https://github.com/fmind/bikes/blob/main/CHANGELOG.md"
81+
82+
[project.scripts]
83+
bikes = 'bikes.scripts:main'
84+
85+
[tool.uv]
86+
default-groups = ["checks", "commits", "dev", "docs", "notebooks"]
7787

7888
[build-system]
79-
requires = ["poetry-core"]
80-
build-backend = "poetry.core.masonry.api"
89+
requires = ["hatchling"]
90+
build-backend = "hatchling.build"
91+
8192
```
8293

8394
This information not only aids users in understanding what your package does but also facilitates its discovery and integration into other projects.
@@ -101,10 +112,10 @@ Deciding whether to publish your Python package depends on your goals. If you ai
101112

102113
For private packages or when sharing within a limited group or organization, platforms like [AWS CodeArtifact](https://aws.amazon.com/codeartifact/) or [GCP Artifact Registry](https://cloud.google.com/artifact-registry) offer secure hosting and management of your packages.
103114

104-
To publish a package using Poetry, you can use the command:
115+
To publish a package using uv, you can use the command:
105116

106117
```bash
107-
poetry publish
118+
uv publish
108119
```
109120

110121
This will upload your package to PyPI, making it available for installation via `pip` by the Python community.

docs/3. Productionizing/3.1. Modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import sys
5252
print(sys.path)
5353
```
5454

55-
After installing your package locally (e.g., using `poetry install`), your package's directory will be added to `sys.path`, allowing you to import its modules without specifying their full path.
55+
After installing your package locally (e.g., using `uv sync`), your package's directory will be added to `sys.path`, allowing you to import its modules without specifying their full path.
5656

5757
## How should you organize your Python modules?
5858

0 commit comments

Comments
 (0)