Skip to content

Commit

Permalink
Migrate to uv (#418)
Browse files Browse the repository at this point in the history
Lots of weird stuff in this repo.
  • Loading branch information
einarmo authored Jan 14, 2025
1 parent ab7b06e commit e70f7ba
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 76 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ jobs:
with:
python-version: "3.10"

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry lock
poetry install
uv sync
python3 -m pip install pre-commit==3.6.2
- name: Build package
run: poetry build
run: uv build

- name: Build docs
run: cd docs && make html
run: cd docs && make html SPHINXBUILD="uv run sphinx-build"

- name: Release to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload --verbose dist/* || echo 'Version exists'
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: uv publish || echo 'Version exists'
17 changes: 9 additions & 8 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry lock
poetry install
uv sync
python3 -m pip install pre-commit==3.6.2
- name: Check codestyle
run: pre-commit run --all
Expand All @@ -47,16 +48,16 @@ jobs:
COGNITE_DEV_BASE_URL: https://aws-dub-dev.cognitedata.com/
COGNITE_DEV_TOKEN_SCOPES: https://aws-dub-dev.cognitedata.com/.default
run: |
coverage run --source cognite.extractorutils -m pytest -v tests
coverage xml
uv run coverage run --source cognite.extractorutils -m pytest -v tests
uv run coverage xml
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml

- name: Build package
run: poetry build
run: uv build

- name: Build docs
run: cd docs && make html
run: cd docs && make html SPHINXBUILD="uv run sphinx-build"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

uv.lock
poetry.lock

# pyenv
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
name: mypy
types: [python]
language: system
entry: poetry run mypy --non-interactive --install-types cognite
entry: uv run mypy --non-interactive --install-types cognite
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ as a code of conduct.

### Development environment

We use [poetry](https://python-poetry.org) to manage dependencies and to administrate virtual environments. To develop
We use [uv](https://docs.astral.sh/uv/) to manage dependencies and to administrate virtual environments. To develop
`extractor-utils`, follow the following steps to set up your local environment:

1. [Install poetry](https://python-poetry.org/docs/#installation) if you haven't already.
1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/) if you haven't already.

2. Clone repository:
```
Expand All @@ -73,7 +73,7 @@ We use [poetry](https://python-poetry.org) to manage dependencies and to adminis
```
4. Create virtual environment and install dependencies:
```
$ poetry install
$ uv sync
```
Expand Down
2 changes: 1 addition & 1 deletion docs/source/uploader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function. This function is called from the ``__main__.py`` file, and is provided
of extraction state between runs to avoid duplicate work
* ``config`` is the config file the user have provided, which has been loaded and stored as an instance of the Config
class we made in the :ref:`Read CSV files` chapter.
* ``stop_event`` is an instance of the `CancellationToken class`_
* ``stop_event`` is an instance of the `CancellationToken <cognite.extractorutils.threading>` class
It will be set whenever the extractor is asked to stop (for example by a user
sending an interrupt signal), or you can set it yourself when a stopping condition is met. In our case, we will check
the status of this stop event in our main loop before submitting a file for extraction. This way, when a user e.g.
Expand Down
109 changes: 64 additions & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
[tool.poetry]
[project]
name = "cognite-extractor-utils"
version = "7.5.7"
description = "Utilities for easier development of extractors for CDF"
authors = ["Mathias Lohne <[email protected]>"]
license = "Apache-2.0"
authors = [
{name = "Mathias Lohne", email = "[email protected]"}
]
license = { text = "Apache-2.0" }
readme = "README.md"
requires-python = ">=3.9"

classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python"
]

dependencies = [
"cognite-sdk>=7.59.0",
"prometheus-client>=0.7.0,<=1.0.0",
"arrow>=1.0.0",
"pyyaml>=5.3.0,<7",
"dacite>=1.6.0",
"psutil>=6.0.0",
"decorator>=5.1.1",
"more-itertools>=10.0.0",
"typing-extensions>=3.7.4,<5",
"python-dotenv>=1.0.0",
"azure-identity>=1.14.0",
"azure-keyvault-secrets>=4.7.0",
"orjson>=3.10.3",
"httpx>=0.27.0,<1",
"pydantic>=2.8.2",
"pyhumps>=3.8.0",
"croniter>=6.0.0",
"jsonlines>=4.0.0",
]

[project.urls]
repository = "https://github.com/cognitedata/python-extractor-utils"

packages = [
{ include="cognite", from="." },
[project.optional-dependencies]
experimental = ["cognite-sdk-experimental"]

[tool.uv]
dev-dependencies = [
"mypy>=1.14.1",
"ruff>=0.9.0",
"pytest>=8.0.0",
"pytest-cov>=6.0.0",
"sphinx>=7.0.0",
"sphinx-rtd-theme>=3.0.0",
"pre-commit>=4.0.0",
"SecretStorage>=3.1.2",
"twine>=6.0.0",
"pytest-order>=1.0.1",
"parameterized",
"requests>=2.31.0",
"types-requests>=2.31.0.20240125",
"faker>=33.0.0",
"types-croniter>=5.0.1.20241205",
"types-pyyaml>=6.0.12.20241230",
"types-psutil>=6.1.0.20241221",
"types-decorator>=5.1.8.20240310",
]

[tool.ruff]
Expand Down Expand Up @@ -56,46 +108,13 @@ warn_redundant_casts = true
warn_unused_ignores = true
exclude = "tests/*"

[tool.poetry.dependencies]
python = "^3.9.0"
cognite-sdk = "^7.59.0"
prometheus-client = ">0.7.0, <=1.0.0"
arrow = "^1.0.0"
pyyaml = ">=5.3.0, <7"
dacite = "^1.6.0"
psutil = "^6.0.0"
decorator = "^5.1.1"
more-itertools = "^10.0.0"
typing-extensions = ">=3.7.4, <5"
python-dotenv = "^1.0.0"
azure-identity = "^1.14.0"
azure-keyvault-secrets = "^4.7.0"
orjson = "^3.10.3"
httpx = ">=0.27.0, <1"
pydantic = "^2.8.2"
pyhumps = "^3.8.0"
croniter = "^6.0.0"
jsonlines = "^4.0.0"

[tool.poetry.extras]
experimental = ["cognite-sdk-experimental"]
[tool.setuptools.packages.find]
where = ["."]
exclude = ["tests*", "docs*"]

[tool.poetry.group.dev.dependencies]
mypy = "1.14.1"
ruff = "^0.9.0"
pytest = "^8.0.0"
pytest-cov = "^6.0.0"
sphinx = "^7.0.0"
sphinx-rtd-theme = "^3.0.0"
pre-commit = "^4.0.0"
SecretStorage = "^3.1.2"
twine = "^6.0.0"
pytest-order = "^1.0.1"
parameterized = "*"
requests = "^2.31.0"
types-requests = "^2.31.0.20240125"
faker = "^33.0.0"
[tool.setuptools]
py-modules = ["cognite"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/bash
set -e
poetry run python -m pytest -v --show-capture=all --cov-report=term-missing --cov=cognite.extractorutils
uv run pytest -v --show-capture=all --cov-report=term-missing --cov=cognite.extractorutils
2 changes: 1 addition & 1 deletion tests/test_unstable/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cognite.extractorutils.unstable.core.base import FullConfig
from cognite.extractorutils.unstable.core.errors import ErrorLevel
from cognite.extractorutils.unstable.core.tasks import ScheduledTask
from tests.test_unstable.conftest import TestConfig, TestExtractor
from test_unstable.conftest import TestConfig, TestExtractor


def test_global_error(
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_assets_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import random

import pytest
from conftest import ETestType, ParamTest

from cognite.client import CogniteClient
from cognite.client.data_classes.assets import Asset
from cognite.extractorutils.uploader.assets import AssetUploadQueue
from tests.conftest import ETestType, ParamTest


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_data_modeling_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Tuple

import pytest
from conftest import NUM_EDGES, NUM_NODES, ETestType, ParamTest
from faker import Faker

from cognite.client import CogniteClient
Expand All @@ -13,7 +14,6 @@
ViewId,
)
from cognite.extractorutils.uploader.data_modeling import InstanceUploadQueue
from tests.conftest import NUM_EDGES, NUM_NODES, ETestType, ParamTest

fake = Faker()

Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_events_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from typing import Tuple

import pytest
from conftest import ETestType, ParamTest

from cognite.client import CogniteClient
from cognite.client.data_classes import Event
from cognite.extractorutils.uploader.events import EventUploadQueue
from tests.conftest import ETestType, ParamTest


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_file_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import jsonlines
import pytest
from conftest import ETestType, ParamTest

from cognite.client import CogniteClient
from cognite.client.data_classes import FileMetadata
Expand All @@ -34,7 +35,6 @@
FileUploadQueue,
IOFileUploadQueue,
)
from tests.conftest import ETestType, ParamTest


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_raw_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import time

import pytest
from conftest import ETestType, ParamTest

from cognite.client import CogniteClient
from cognite.client.data_classes import Row
from cognite.extractorutils.uploader import RawUploadQueue
from tests.conftest import ETestType, ParamTest


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_time_series_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from typing import Any

import pytest
from conftest import ETestType, ParamTest

from cognite.client import CogniteClient
from cognite.client.data_classes import StatusCode, TimeSeries
from cognite.extractorutils.uploader import TimeSeriesUploadQueue
from tests.conftest import ETestType, ParamTest


@pytest.fixture
Expand Down

0 comments on commit e70f7ba

Please sign in to comment.