Skip to content

Commit a3799e3

Browse files
authored
python migration from 3.9 to 3.12 (#178)
* python migration from 3.9 to 3.12 * github workflow updated * pre-commit updated * README updated based on UV changes * build system updated in each and every pyproject.toml fiel * add pyproject.toml * build related changes reverted back * build system commented on azure_open_ai * reverted build change * RC Version updated * Version updated
1 parent 499f8e0 commit a3799e3

File tree

41 files changed

+5115
-5180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5115
-5180
lines changed

.github/workflows/pypi-publish.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name: Publish Python Package
33
on:
44
release:
55
types:
6-
- published
6+
- published
77

88
jobs:
99
pypi-publish:
1010
name: upload release to PyPI
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
permissions:
1313
contents: read
1414
id-token: write
@@ -19,13 +19,16 @@ jobs:
1919

2020
- uses: actions/setup-python@v5
2121
with:
22-
python-version: '3.9.6'
22+
python-version: "3.12.9"
2323

24-
- name: Setup PDM
25-
uses: pdm-project/setup-pdm@v4
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v5
2626
with:
27-
python-version: 3.9.6
28-
version: 2.12.3
27+
# Install a specific version of uv.
28+
version: "0.6.11"
2929

30-
- name: Publish package distributions to PyPI
31-
run: pdm publish
30+
- name: Build package
31+
run: uv build
32+
33+
- name: Publish to PyPI
34+
run: uv publish

.pre-commit-config.yaml

Lines changed: 33 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
---
2-
# See https://pre-commit.com for more information
3-
# See https://pre-commit.com/hooks.html for more hooks
4-
# - Added pkgs feature flag auto generated code to flake8 exclude list
5-
# Force all unspecified python hooks to run python 3.10
61
default_language_version:
7-
python: python3.9
2+
python: python3.12
83
default_stages:
9-
- commit
4+
- pre-commit
105
repos:
116
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v4.5.0
7+
rev: v5.0.0
138
hooks:
149
- id: trailing-whitespace
1510
exclude_types:
@@ -34,125 +29,58 @@ repos:
3429
- id: destroyed-symlinks
3530
- id: forbid-new-submodules
3631
- id: mixed-line-ending
37-
- id: no-commit-to-branch
38-
- repo: https://github.com/adrienverge/yamllint
39-
rev: v1.35.1
32+
33+
- repo: https://github.com/astral-sh/ruff-pre-commit
34+
rev: v0.3.4
4035
hooks:
41-
- id: yamllint
42-
args: ["-d", "relaxed"]
43-
language: system
44-
- repo: https://github.com/rhysd/actionlint
45-
rev: v1.6.26
46-
hooks:
47-
- id: actionlint-docker
48-
args: [-ignore, 'label ".+" is unknown']
49-
- repo: https://github.com/psf/black
50-
rev: 24.2.0
51-
hooks:
52-
- id: black
53-
args: [--config=pyproject.toml, -l 88]
54-
language: system
55-
exclude: |
56-
(?x)^(
57-
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
58-
)$
59-
- repo: https://github.com/pycqa/flake8
60-
rev: 7.0.0
61-
hooks:
62-
- id: flake8
63-
args: [--max-line-length=88]
64-
exclude: |
65-
(?x)^(
66-
.*migrations/.*\.py|
67-
unstract-core/tests/.*|
68-
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
69-
)$
70-
- repo: https://github.com/pycqa/isort
71-
rev: 5.13.2
72-
hooks:
73-
- id: isort
74-
files: "\\.(py)$"
75-
args:
76-
[
77-
"--profile",
78-
"black",
79-
"--filter-files",
80-
--settings-path=pyproject.toml,
81-
]
36+
- id: ruff
37+
args: [--fix]
38+
- id: ruff-format
39+
8240
- repo: https://github.com/hadialqattan/pycln
8341
rev: v2.4.0
8442
hooks:
8543
- id: pycln
44+
entry: uv run pycln
8645
args: [--config=pyproject.toml]
46+
8747
- repo: https://github.com/pycqa/docformatter
8848
rev: v1.7.5
8949
hooks:
9050
- id: docformatter
91-
# - repo: https://github.com/MarcoGorelli/absolufy-imports
92-
# rev: v0.3.1
93-
# hooks:
94-
# - id: absolufy-imports
51+
language: python
52+
9553
- repo: https://github.com/asottile/pyupgrade
96-
rev: v3.15.0
54+
rev: v3.17.0
9755
hooks:
9856
- id: pyupgrade
9957
entry: pyupgrade --py39-plus --keep-runtime-typing
10058
types:
10159
- python
102-
- repo: https://github.com/gitleaks/gitleaks
103-
rev: v8.18.2
60+
61+
- repo: https://github.com/astral-sh/uv-pre-commit
62+
rev: 0.6.11
10463
hooks:
105-
- id: gitleaks
106-
- repo: https://github.com/asottile/yesqa
107-
rev: v1.5.0
64+
- id: uv-lock
65+
66+
- repo: https://github.com/pre-commit/mirrors-mypy
67+
rev: v1.11.2
10868
hooks:
109-
- id: yesqa
110-
# TODO: Uncomment after typing the SDK
111-
# - repo: https://github.com/pre-commit/mirrors-mypy
112-
# rev: v1.8.0
113-
# hooks:
114-
# - id: mypy
115-
# language: system
116-
# entry: mypy .
117-
# pass_filenames: false
118-
# # IMPORTANT!
119-
# # Keep args same as tool.mypy section in pyproject.toml
120-
# args:
121-
# [
122-
# --allow-subclassing-any,
123-
# --allow-untyped-decorators,
124-
# --check-untyped-defs,
125-
# --exclude, ".*migrations/.*.py",
126-
# --exclude, "backend/prompt/.*",
127-
# --exclude, "document_display_service/.*",
128-
# --exclude, "pkgs/unstract-connectors/tests/.*",
129-
# --exclude, "pkgs/unstract-core/.*",
130-
# --exclude, "pkgs/unstract-flags/src/unstract/flags/.*",
131-
# --exclude, "sdks/.*",
132-
# --exclude, "unstract-document-service/.*",
133-
# --exclude, "__pypackages__/.*",
134-
# --follow-imports, "silent",
135-
# --ignore-missing-imports,
136-
# --implicit-reexport,
137-
# --pretty,
138-
# --python-version=3.9,
139-
# --show-column-numbers,
140-
# --show-error-codes,
141-
# --strict,
142-
# --warn-redundant-casts,
143-
# --warn-return-any,
144-
# --warn-unreachable,
145-
# --warn-unused-configs,
146-
# --warn-unused-ignores,
147-
# ]
69+
- id: mypy
70+
language: system
71+
entry: uv run mypy .
72+
pass_filenames: false
73+
additional_dependencies: []
74+
14875
- repo: https://github.com/igorshubovych/markdownlint-cli
149-
rev: v0.39.0
76+
rev: v0.42.0
15077
hooks:
15178
- id: markdownlint
15279
args: [--disable, MD013]
15380
- id: markdownlint-fix
15481
args: [--disable, MD013]
155-
- repo: https://github.com/pdm-project/pdm
156-
rev: 2.12.3
82+
83+
- repo: https://github.com/gitleaks/gitleaks
84+
rev: v8.18.2
15785
hooks:
158-
- id: pdm-lock-check
86+
- id: gitleaks

README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,27 @@ Index Version **0.9.28** as on January 14th, 2024
6161

6262
Ensure that you have all the required dependencies and pre-commit hooks installed
6363
```shell
64-
pdm install
64+
uv sync
6565
pre-commit install
6666
```
6767

6868
Once the changes have been made, it can be tested with [Unstract](https://github.com/Zipstack/unstract) through the following means.
6969

70-
#### With PDM
71-
Specify the SDK as a dependency to a project using a tool like `pdm` by adding the following to your `pyproject.toml`
70+
#### With UV
71+
Specify the SDK as a dependency to a project using a tool like `uv` by adding the following to your `pyproject.toml`
7272

7373
```toml
74-
[tool.pdm.dev-dependencies]
75-
local_copies = [
76-
"-e unstract-adapters @ file:///${UNSTRACT_ADAPTERS_PATH}",
77-
"-e unstract-sdk @ file:///${UNSTRACT_SDK_PATH}",
74+
dependencies = [
75+
"unstract-sdk"
7876
]
79-
```
80-
Or by running the below command
81-
```shell
82-
pdm add -e /path/to/unstract-sdk --dev
77+
78+
[dependency-groups]
79+
dev = [
80+
"unstract-sdk"
81+
]
82+
83+
[tool.uv.sources]
84+
unstract-sdk = { path = "${UNSTRACT_SDK_PATH", editable = true }
8385
```
8486

8587
#### With pip
@@ -90,23 +92,24 @@ pdm add -e /path/to/unstract-sdk --dev
9092
NOTE: Building locally might require the below section to be replaced in the `unstract-sdk`'s build system configuration
9193
```
9294
[build-system]
93-
requires = ["setuptools", "wheel"]
94-
build-backend = "setuptools.build_meta"
95+
requires = ["hatchling"]
96+
build-backend = "hatchling.build"
9597
```
9698
- Another option is to provide a git URL in `requirements.txt`, this can come in handy while building tool
9799
docker images. Don't forget to run `apt install git` within the `Dockerfile` for this
98100
```shell
99-
unstract-sdk @ git+https://github.com/Zipstack/unstract-sdk@feature-branch
101+
[tool.uv.sources]
102+
unstract-sdk = { git = "git+https://github.com/Zipstack/unstract-sdk@feature-branch" }
100103
```
101104
102105
- Or try installing a [local PyPI server](https://pypi.org/project/pypiserver/) and upload / download your package from this server
103106
104107
#### Additonal dependencies for tool
105-
Tools may need to be backed up by a file storage. unstract.sdk.file_storage contains the required interfaces for the
106-
same. fssepc is being used underneath to implement these interfaces. Hence, one can choose to use a file_system
107-
supported by fsspec for this. However, the required dependencies need to be added in the tool dependency manager.
108-
Eg. If the tool is using Minio as the underlying file storage, then s3fs can be added to support it.
109-
Similarly, for Google Cloud Storage, gcsfs is to be added.
108+
Tools may need to be backed up by a file storage. unstract.sdk.file_storage contains the required interfaces for the
109+
same. fssepc is being used underneath to implement these interfaces. Hence, one can choose to use a file_system
110+
supported by fsspec for this. However, the required dependencies need to be added in the tool dependency manager.
111+
Eg. If the tool is using Minio as the underlying file storage, then s3fs can be added to support it.
112+
Similarly, for Google Cloud Storage, gcsfs is to be added.
110113
The following versions are tested in the SDK using unit test cases for the above package.
111114
gcsfs==2024.10.0
112115
s3fs==2024.10.0

0 commit comments

Comments
 (0)