Skip to content

Commit 2450943

Browse files
emdnetoxrmx
andauthored
introducing uv in core (open-telemetry#4451)
* introduce uv Signed-off-by: emdneto <[email protected]> * remove ruff workflow Signed-off-by: emdneto <[email protected]> * move to workspaces Signed-off-by: emdneto <[email protected]> * make contributing commands copyable Signed-off-by: emdneto <[email protected]> * add opencensus e zipkin-proto-http to exclude list Signed-off-by: emdneto <[email protected]> --------- Signed-off-by: emdneto <[email protected]> Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent 6754bd2 commit 2450943

File tree

6 files changed

+803
-29
lines changed

6 files changed

+803
-29
lines changed

.github/workflows/misc_0.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ jobs:
236236
- name: Check github workflows are up to date
237237
run: git diff --exit-code || (echo 'Generated workflows are out of date, run "tox -e generate-workflows" and commit the changes in this PR.' && exit 1)
238238

239-
ruff:
240-
name: ruff
239+
precommit:
240+
name: precommit
241241
runs-on: ubuntu-latest
242242
steps:
243243
- name: Checkout repo @ SHA - ${{ github.sha }}
@@ -252,4 +252,4 @@ jobs:
252252
run: pip install tox
253253

254254
- name: Run tests
255-
run: tox -e ruff
255+
run: tox -e precommit

.pre-commit-config.yaml

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
repos:
2-
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
# Ruff version.
4-
rev: v0.6.9
5-
hooks:
6-
# Run the linter.
7-
- id: ruff
8-
args: ["--fix", "--show-fixes"]
9-
# Run the formatter.
10-
- id: ruff-format
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.6.9
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: ["--fix", "--show-fixes"]
9+
# Run the formatter.
10+
- id: ruff-format
11+
- repo: https://github.com/astral-sh/uv-pre-commit
12+
# uv version.
13+
rev: 0.6.0
14+
hooks:
15+
- id: uv-lock

CONTRIBUTING.md

+46-15
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ some aspects of development, including testing against multiple Python versions.
4545
To install `tox`, run:
4646

4747
```console
48-
$ pip install tox
48+
pip install tox
4949
```
5050

5151
You can run `tox` with the following arguments:
@@ -60,19 +60,36 @@ You can run `tox` with the following arguments:
6060
- `tox -e lint-some-package` to run lint checks on `some-package`
6161
- `tox -e generate-workflows` to run creation of new CI workflows if tox environments have been updated
6262
- `tox -e ruff` to run ruff linter and formatter checks against the entire codebase
63+
- `tox -e precommit` to run all `pre-commit` actions
6364

6465
`ruff check` and `ruff format` are executed when `tox -e ruff` is run. We strongly recommend you to configure [pre-commit](https://pre-commit.com/) locally to run `ruff` automatically before each commit by installing it as git hooks. You just need to [install pre-commit](https://pre-commit.com/#install) in your environment:
6566

6667
```console
67-
$ pip install pre-commit -c dev-requirements.txt
68+
pip install pre-commit -c dev-requirements.txt
6869
```
6970

7071
and run this command inside the git repository:
7172

7273
```console
73-
$ pre-commit install
74+
pre-commit install
7475
```
7576

77+
### Virtual Environment
78+
79+
You can also create a single virtual environment to make it easier to run local tests.
80+
81+
For that, you'll need to install [`uv`](https://docs.astral.sh/uv/getting-started/installation/).
82+
83+
After installing `uv`, you can run the following command:
84+
85+
```sh
86+
uv sync
87+
```
88+
89+
This will create a virtual environment in the `.venv` directory and install all the necessary dependencies.
90+
91+
### Public Symbols
92+
7693
We try to keep the amount of _public symbols_ in our code minimal. A public symbol is any Python identifier that does not start with an underscore.
7794
Every public symbol is something that has to be kept in order to maintain backwards compatibility, so we try to have as few as possible.
7895

@@ -107,7 +124,7 @@ See
107124
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python/blob/main/tox.ini)
108125
for more detail on available tox commands.
109126

110-
#### Contrib repo
127+
### Contrib repo
111128

112129
Some of the `tox` targets install packages from the [OpenTelemetry Python Contrib Repository](https://github.com/open-telemetry/opentelemetry-python.git) via
113130
pip. The version of the packages installed defaults to the `main` branch in that repository when `tox` is run locally. It is possible to install packages tagged
@@ -153,31 +170,45 @@ pull requests (PRs).
153170
To create a new PR, fork the project in GitHub and clone the upstream repo:
154171

155172
```console
156-
$ git clone https://github.com/open-telemetry/opentelemetry-python.git
157-
$ cd opentelemetry-python
173+
git clone https://github.com/open-telemetry/opentelemetry-python.git
174+
cd opentelemetry-python
158175
```
159176

160177
Add your fork as an origin:
161178

162179
```console
163-
$ git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-python.git
180+
git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-python.git
164181
```
165182

166-
Run tests:
183+
Make sure you have all supported versions of Python installed, install tox only for the first time:
167184

168185
```sh
169-
# make sure you have all supported versions of Python installed
170-
$ pip install tox # only first time.
171-
$ tox # execute in the root of the repository
186+
pip install tox
187+
```
188+
189+
Run tests in the root of the repository (this will run all tox environments and may take some time):
190+
191+
```sh
192+
tox
172193
```
173194

174195
Check out a new branch, make modifications and push the branch to your fork:
175196

176197
```sh
177-
$ git checkout -b feature
178-
# edit files
179-
$ git commit
180-
$ git push fork feature
198+
git checkout -b feature
199+
```
200+
201+
After you edit the files, stage changes in the current directory:
202+
203+
```sh
204+
git add .
205+
```
206+
207+
Then run the following to commit the changes:
208+
209+
```sh
210+
git commit
211+
git push fork feature
181212
```
182213

183214
Open a pull request against the main `opentelemetry-python` repo.

pyproject.toml

+55
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
[project]
2+
name = "opentelemetry-python"
3+
version = "0.0.0" # This is not used.
4+
requires-python = ">=3.8"
5+
dependencies = [
6+
"opentelemetry-api",
7+
"opentelemetry-sdk",
8+
"opentelemetry-semantic-conventions",
9+
"opentelemetry-proto",
10+
"opentelemetry-test-utils",
11+
"opentelemetry-exporter-otlp-proto-grpc",
12+
"opentelemetry-exporter-otlp-proto-http",
13+
"opentelemetry-exporter-otlp-proto-common",
14+
"opentelemetry-exporter-zipkin-json",
15+
"opentelemetry-exporter-prometheus",
16+
"opentelemetry-propagator-jaeger",
17+
"opentelemetry-propagator-b3",
18+
]
19+
20+
# https://docs.astral.sh/uv/reference/settings/
21+
[tool.uv]
22+
package = false # https://docs.astral.sh/uv/reference/settings/#package
23+
required-version = ">=0.6.0"
24+
25+
[tool.uv.sources]
26+
opentelemetry-api = { workspace = true}
27+
opentelemetry-sdk = { workspace = true }
28+
opentelemetry-proto = { workspace = true }
29+
opentelemetry-semantic-conventions = { workspace = true }
30+
opentelemetry-test-utils = { workspace = true }
31+
opentelemetry-exporter-otlp-proto-grpc = { workspace = true }
32+
opentelemetry-exporter-otlp-proto-http = { workspace = true }
33+
opentelemetry-exporter-otlp-proto-common = { workspace = true }
34+
opentelemetry-exporter-zipkin-json = { workspace = true }
35+
opentelemetry-exporter-prometheus = {workspace = true }
36+
opentelemetry-propagator-jaeger = { workspace = true }
37+
opentelemetry-propagator-b3 = { workspace = true }
38+
39+
[tool.uv.workspace]
40+
members = [
41+
"opentelemetry-api",
42+
"opentelemetry-sdk",
43+
"opentelemetry-semantic-conventions",
44+
"opentelemetry-proto",
45+
"exporter/*",
46+
"propagator/*",
47+
"tests/opentelemetry-test-utils",
48+
]
49+
50+
exclude = [
51+
"exporter/opentelemetry-exporter-opencensus",
52+
"exporter/opentelemetry-exporter-zipkin",
53+
"exporter/opentelemetry-exporter-zipkin-proto-http",
54+
]
55+
156
[tool.pytest.ini_options]
257
addopts = "-rs -v"
358
log_cli = true

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ envlist =
9595
public-symbols-check
9696
shellcheck
9797
generate-workflows
98-
ruff
98+
precommit
9999

100100
[testenv]
101101
deps =
@@ -358,7 +358,7 @@ commands =
358358
pyright --version
359359
pyright
360360

361-
[testenv:ruff]
361+
[testenv:{precommit,ruff}]
362362
basepython: python3
363363
deps =
364364
-c {toxinidir}/dev-requirements.txt

0 commit comments

Comments
 (0)