Skip to content

Commit b39c64e

Browse files
authored
Merge pull request #143 from treasure-data/uv
Migrate to uv
2 parents 716f2ea + 8dba388 commit b39c64e

File tree

13 files changed

+1117
-80
lines changed

13 files changed

+1117
-80
lines changed

.github/workflows/pythontest.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
name: Python testing
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
create:
49

510
jobs:
611
lint:
712
runs-on: ubuntu-latest
813
steps:
914
- uses: actions/checkout@v4
10-
- name: Set up Python
11-
uses: actions/setup-python@v6
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v7
1217
with:
1318
python-version: "3.13"
1419
- name: Install dependencies
15-
run: |
16-
python -m pip install --upgrade pip
17-
pip install ".[dev]"
20+
run: uv sync --extra dev
1821
- name: lint with ruff
1922
run: |
20-
ruff format tdclient --diff --exit-non-zero-on-fix
21-
ruff check tdclient
23+
uv run ruff format tdclient --diff --exit-non-zero-on-fix
24+
uv run ruff check tdclient
2225
- name: Run pyright
23-
run: |
24-
pyright tdclient
26+
run: uv run pyright tdclient
2527

2628
test:
2729
runs-on: ${{ matrix.os }}
@@ -33,19 +35,15 @@ jobs:
3335

3436
steps:
3537
- uses: actions/checkout@v5
36-
- name: Set up Python ${{ matrix.python-version }}
37-
uses: actions/setup-python@v6
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v7
3840
with:
3941
python-version: ${{ matrix.python-version }}
4042
- name: Install dependencies
41-
run: |
42-
python -m pip install --upgrade pip
43-
pip install ".[dev]"
44-
pip install -r requirements.txt -r test-requirements.txt
45-
pip install -U coveralls pyyaml
43+
run: uv sync --extra test
4644
- name: Run test
4745
run: |
48-
coverage run --source=tdclient -m pytest tdclient/test
46+
uv run coverage run --source=tdclient -m pytest tdclient/test
4947
5048
#
5149
# Disable coverage submission to avoid

.python-version

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
3.8.1
2-
3.7.6
3-
3.6.10
4-
3.5.9
5-
pypy2.7-7.1.0
1+
3.10.19
2+
3.11.14
3+
3.12.12
4+
3.13.9
5+
3.14.0

MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,34 +301,58 @@ Development
301301
Running tests
302302
^^^^^^^^^^^^^
303303

304-
Run tests.
304+
Install the project dependencies with `uv <https://docs.astral.sh/uv/>`_ (runtime
305+
and test extras) and execute pytest via ``uv run``.
305306

306307
.. code-block:: sh
307308
308-
$ pytest tdclient
309+
$ uv sync --extra test
310+
$ uv run pytest tdclient/test
311+
312+
To run the coverage suite locally, use:
313+
314+
.. code-block:: sh
315+
316+
$ uv run coverage run --source=tdclient -m pytest tdclient/test
317+
$ uv run coverage report
318+
319+
Linting and type checking
320+
^^^^^^^^^^^^^^^^^^^^^^^^^
321+
322+
Install the development extras and invoke ``ruff`` and ``pyright`` using
323+
``uv run``.
324+
325+
.. code-block:: sh
326+
327+
$ uv sync --extra dev
328+
$ uv run ruff format tdclient --diff --exit-non-zero-on-fix
329+
$ uv run ruff check tdclient
330+
$ uv run pyright tdclient
309331
310332
Running tests (tox)
311333
^^^^^^^^^^^^^^^^^^^
312334

313-
You can run tests against all supported Python versions. I'd recommend you to install `pyenv <https://github.com/yyuu/pyenv>`_ to manage Pythons.
335+
You can run tests against all supported Python versions with ``tox``. I'd
336+
recommend you to install `pyenv <https://github.com/yyuu/pyenv>`_ to manage
337+
additional interpreters.
314338

315339
.. code-block:: sh
316340
317341
$ pyenv shell system
318342
$ for version in $(cat .python-version); do [ -d "$(pyenv root)/versions/${version}" ] || pyenv install "${version}"; done
319343
$ pyenv shell --unset
320344
321-
Install `tox <https://pypi.python.org/pypi/tox>`_.
345+
Install the development extras (which include ``tox``) with ``uv``.
322346

323347
.. code-block:: sh
324348
325-
$ pip install tox
349+
$ uv sync --extra dev
326350
327-
Then, run ``tox``.
351+
Then, run ``tox`` via ``uv``.
328352

329353
.. code-block:: sh
330354
331-
$ tox
355+
$ uv run tox
332356
333357
Release
334358
^^^^^^^

pyproject.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,21 @@ dependencies = [
3434
]
3535

3636
[project.optional-dependencies]
37-
dev = ["ruff", "pyright"]
38-
docs = ["sphinx", "sphinx_rtd_theme"]
37+
dev = [
38+
"ruff",
39+
"pyright",
40+
"tox>=4",
41+
]
42+
docs = [
43+
"sphinx",
44+
"sphinx_rtd_theme",
45+
]
46+
test = [
47+
"coverage[toml]",
48+
"pytest>=8.3",
49+
"coveralls>=1.1,<5.0",
50+
"pyyaml",
51+
]
3952

4053
[tool.setuptools]
4154
packages = ["tdclient"]

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

tdclient/api.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,6 @@ def send_request(
541541
method, url, fields=fields, headers=headers, **kwargs
542542
)
543543

544-
if urllib3.util.IS_PYOPENSSL and isinstance(body, bytearray):
545-
# workaround for https://github.com/pyca/pyopenssl/issues/621
546-
body = memoryview(body)
547-
if urllib3.util.IS_PYOPENSSL and isinstance(body, array):
548-
# workaround for https://github.com/pyca/pyopenssl/issues/621
549-
body = body.tobytes()
550544
return self.http.urlopen(method, url, body=body, headers=headers, **kwargs)
551545

552546
def raise_error(

tdclient/bulk_import_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def raise_error(
5050
) -> None: ...
5151
def checked_json(self, body: bytes, required: list[str]) -> dict[str, Any]: ...
5252
def _prepare_file(
53-
self, file: FileLike, format: str, **kwargs: Any
53+
self, file_like: FileLike, fmt: str, **kwargs: Any
5454
) -> IO[bytes]: ...
5555

5656
def create_bulk_import(

tdclient/import_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def raise_error(
3131
) -> None: ...
3232
def checked_json(self, body: bytes, required: list[str]) -> dict[str, Any]: ...
3333
def _prepare_file(
34-
self, file: FileLike, format: str, **kwargs: Any
34+
self, file_like: FileLike, fmt: str, **kwargs: Any
3535
) -> IO[bytes]: ...
3636

3737
def import_data(

tdclient/test/api_test.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,7 @@ def test_post_bytearray_success():
305305
args, kwargs = td.http.urlopen.call_args
306306
assert args == ("POST", "https://api.treasuredata.com/foo")
307307
assert kwargs["body"] == bytes_or_stream
308-
if urllib3.util.IS_PYOPENSSL:
309-
assert isinstance(kwargs["body"], memoryview)
310-
else:
311-
assert isinstance(kwargs["body"], bytearray)
308+
assert isinstance(kwargs["body"], bytearray)
312309
assert sorted(kwargs["headers"].keys()) == [
313310
"authorization",
314311
"date",
@@ -404,10 +401,7 @@ def test_put_bytes_success():
404401
with td.put("/foo", bytes_or_stream, 12) as response:
405402
args, kwargs = td.http.urlopen.call_args
406403
assert args == ("PUT", "https://api.treasuredata.com/foo")
407-
if urllib3.util.IS_PYOPENSSL:
408-
assert kwargs["body"] == b"request body"
409-
else:
410-
assert kwargs["body"] == array(str("b"), bytes_or_stream)
404+
assert kwargs["body"] == array(str("b"), bytes_or_stream)
411405
assert sorted(kwargs["headers"].keys()) == [
412406
"authorization",
413407
"content-length",
@@ -431,10 +425,7 @@ def test_put_bytes_unicode_success():
431425
with td.put("/hoge", bytes_or_stream, 12) as response:
432426
args, kwargs = td.http.urlopen.call_args
433427
assert args == ("PUT", "https://api.treasuredata.com/hoge")
434-
if urllib3.util.IS_PYOPENSSL:
435-
assert kwargs["body"] == "リクエストボディー".encode("utf-8")
436-
else:
437-
assert kwargs["body"] == array(str("b"), bytes_or_stream)
428+
assert kwargs["body"] == array(str("b"), bytes_or_stream)
438429
assert sorted(kwargs["headers"].keys()) == [
439430
"authorization",
440431
"content-length",
@@ -510,10 +501,7 @@ def test_put_file_without_fileno_success():
510501
with td.put("/foo", bytes_or_stream, 12) as response:
511502
args, kwargs = td.http.urlopen.call_args
512503
assert args == ("PUT", "https://api.treasuredata.com/foo")
513-
if urllib3.util.IS_PYOPENSSL:
514-
assert kwargs["body"] == b"request body"
515-
else:
516-
assert kwargs["body"] == array(str("b"), bytes_or_stream.getvalue())
504+
assert kwargs["body"] == array(str("b"), bytes_or_stream.getvalue())
517505
assert sorted(kwargs["headers"].keys()) == [
518506
"authorization",
519507
"content-length",
@@ -537,10 +525,7 @@ def test_put_file_without_fileno_unicode_success():
537525
with td.put("/hoge", bytes_or_stream, 12) as response:
538526
args, kwargs = td.http.urlopen.call_args
539527
assert args == ("PUT", "https://api.treasuredata.com/hoge")
540-
if urllib3.util.IS_PYOPENSSL:
541-
assert kwargs["body"] == "リクエストボディー".encode("utf-8")
542-
else:
543-
assert kwargs["body"] == array(str("b"), bytes_or_stream.getvalue())
528+
assert kwargs["body"] == array(str("b"), bytes_or_stream.getvalue())
544529
assert sorted(kwargs["headers"].keys()) == [
545530
"authorization",
546531
"content-length",

0 commit comments

Comments
 (0)