JeffYang52415 commited on
Commit
c0f13ae
·
unverified ·
1 Parent(s): 82a8eb3

docs: add poetry docs

Browse files
Files changed (2) hide show
  1. docs/POETRY_JUPYTER_SETUP.md +51 -0
  2. docs/POETRY_USAGE.md +158 -0
docs/POETRY_JUPYTER_SETUP.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Connecting Poetry Environment with Jupyter Notebook
2
+
3
+ This guide provides simple steps to connect a Poetry-managed environment to Jupyter Notebook.
4
+
5
+ ## Steps
6
+
7
+ 1. **Activate the Poetry Environment**
8
+
9
+ First, navigate to your project directory and activate the Poetry shell:
10
+
11
+ ```bash
12
+ poetry shell
13
+ ```
14
+
15
+ 2. **Install Jupyter as a Development Dependency**
16
+
17
+ If Jupyter is not already installed, add it as a development dependency:
18
+
19
+ ```bash
20
+ poetry add --group dev jupyter
21
+ ```
22
+
23
+ 3. **Register the Poetry Environment as a Jupyter Kernel**
24
+
25
+ Run this command to make the Poetry environment available as a Jupyter kernel:
26
+
27
+ ```bash
28
+ python -m ipykernel install --user --name=llmdataparser-env --display-name "Python (LLMDataParser)"
29
+ ```
30
+
31
+ - `--name=llmdataparser-env`: Assigns a name to the kernel.
32
+ - `--display-name "Python (LLMDataParser)"`: Sets the display name seen in Jupyter.
33
+
34
+ 4. **Start Jupyter Notebook**
35
+
36
+ Launch Jupyter Notebook from the Poetry shell:
37
+
38
+ ```bash
39
+ jupyter notebook
40
+ ```
41
+
42
+ 5. **Select the Poetry Kernel in Jupyter**
43
+
44
+ - Open a notebook in Jupyter.
45
+ - Go to "Kernel" > "Change kernel" and select **Python (LLMDataParser)** from the list.
46
+
47
+ This connects the notebook to your Poetry environment.
48
+
49
+ ---
50
+
51
+ You’re now set up to use your Poetry environment within Jupyter Notebook!
docs/POETRY_USAGE.md ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Poetry Usage Guide
2
+
3
+ This guide provides instructions on how to use [Poetry](https://python-poetry.org/) to manage dependencies, install packages, and prepare your project for both development and production environments.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Installing Poetry](#installing-poetry)
9
+ - [Using Poetry in Development](#using-poetry-in-development)
10
+ - [Installing Dependencies](#installing-dependencies)
11
+ - [Updating Dependencies](#updating-dependencies)
12
+ - [Adding and Removing Dependencies](#adding-and-removing-dependencies)
13
+ - [Synchronizing Dependencies](#synchronizing-dependencies)
14
+ - [Using Poetry in Production](#using-poetry-in-production)
15
+ - [Locking Dependencies](#locking-dependencies)
16
+ - [Installing from `poetry.lock`](#installing-from-poetrylock)
17
+ - [Poetry Commands Summary](#poetry-commands-summary)
18
+
19
+ ---
20
+
21
+ ## Overview
22
+
23
+ Poetry is a dependency manager and build tool for Python projects. It simplifies managing dependencies, creating virtual environments, and ensuring version consistency between development and production environments. Poetry relies on two files:
24
+
25
+ - **`pyproject.toml`**: Defines the dependencies and configuration.
26
+ - **`poetry.lock`**: Locks dependencies to specific versions to ensure consistency.
27
+
28
+ ---
29
+
30
+ ## Installing Poetry(macOS only)
31
+
32
+ To install Poetry, use the following command:
33
+
34
+ ```bash
35
+ brew install poetry
36
+ ```
37
+
38
+ Refer to the [Poetry documentation](https://python-poetry.org/docs/#installation) for more options and OS-specific installation instructions.
39
+
40
+ ---
41
+
42
+ ## Using Poetry in Development
43
+
44
+ ### Installing Dependencies
45
+
46
+ In development, install dependencies specified in `pyproject.toml`:
47
+
48
+ 1. Navigate to the project directory:
49
+
50
+ ```bash
51
+ cd path/to/project
52
+ ```
53
+
54
+ 2. Run:
55
+ ```bash
56
+ poetry install
57
+ ```
58
+
59
+ This command creates a virtual environment, installs all dependencies, and ensures they are compatible with the Python version specified.
60
+
61
+ ### Updating Dependencies
62
+
63
+ During development, you can update dependencies by editing `pyproject.toml` directly and then running:
64
+
65
+ ```bash
66
+ poetry install
67
+ ```
68
+
69
+ This will apply any changes and update the environment without manually adding each dependency.
70
+
71
+ ### Adding and Removing Dependencies
72
+
73
+ - **Add a New Dependency**:
74
+
75
+ ```bash
76
+ poetry add <package-name>
77
+ ```
78
+
79
+ Example:
80
+
81
+ ```bash
82
+ poetry add requests
83
+ ```
84
+
85
+ - **Add a Development Dependency** (only used for development/testing):
86
+
87
+ ```bash
88
+ poetry add --group dev <package-name>
89
+ ```
90
+
91
+ Example:
92
+
93
+ ```bash
94
+ poetry add --group dev pytest
95
+ ```
96
+
97
+ - **Remove a Dependency**:
98
+ ```bash
99
+ poetry remove <package-name>
100
+ ```
101
+
102
+ ### Synchronizing Dependencies
103
+
104
+ If the `pyproject.toml` or `poetry.lock` files are updated (e.g., after pulling changes), run:
105
+
106
+ ```bash
107
+ poetry install
108
+ ```
109
+
110
+ This keeps your environment synchronized with any updates made to the dependency files.
111
+
112
+ ---
113
+
114
+ ## Using Poetry in Production
115
+
116
+ ### Locking Dependencies
117
+
118
+ To lock dependencies for production use, run:
119
+
120
+ ```bash
121
+ poetry lock
122
+ ```
123
+
124
+ This creates or updates `poetry.lock`, which pins each dependency to a specific version. This lock file should be used to maintain consistency in production.
125
+
126
+ ### Installing from `poetry.lock`
127
+
128
+ In production, use `poetry.lock` to ensure exact dependency versions:
129
+
130
+ 1. Install only the required (non-development) dependencies:
131
+ ```bash
132
+ poetry install --no-dev
133
+ ```
134
+
135
+ This ensures that dependencies are installed exactly as defined in `poetry.lock`.
136
+
137
+ ---
138
+
139
+ ## Poetry Commands Summary
140
+
141
+ | Command | Description |
142
+ | ------------------------------ | ------------------------------------------------------------- |
143
+ | `poetry install` | Installs dependencies from `pyproject.toml` or `poetry.lock`. |
144
+ | `poetry add <package-name>` | Adds a new dependency and updates `pyproject.toml`. |
145
+ | `poetry add --group dev <pkg>` | Adds a development-only dependency. |
146
+ | `poetry remove <package-name>` | Removes a dependency and updates `pyproject.toml`. |
147
+ | `poetry update` | Updates all dependencies to their latest compatible versions. |
148
+ | `poetry lock` | Locks dependencies to specific versions for production. |
149
+ | `poetry shell` | Activates the Poetry-managed virtual environment. |
150
+
151
+ ---
152
+
153
+ ## Additional Resources
154
+
155
+ - **Poetry Documentation**: [https://python-poetry.org/docs/](https://python-poetry.org/docs/)
156
+ - **GitHub Repository**: [https://github.com/python-poetry/poetry](https://github.com/python-poetry/poetry)
157
+
158
+ For further help, please refer to the [Poetry documentation](https://python-poetry.org/docs/).