Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
matrix:
env:
- build
- format
- generate-integration-files
- lint
- type
Expand Down
4 changes: 0 additions & 4 deletions .isort.cfg

This file was deleted.

7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"ms-python.python"
]
}
9 changes: 5 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
".eggs": true,
"**/*.egg-info": true,
".coverage": true,
".mypy_cache": true,
".pytest_cache": true,
".ruff_cache": true,
".tox": true
},
"editor.detectIndentation": false,
Expand All @@ -23,17 +25,16 @@
"editor.wordWrapColumn": 88
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
}
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},
"python.envFile": "${workspaceFolder}/.vscode/env",
"python.formatting.provider": "black",
"python.linting.pylintEnabled": true,
"python.testing.pytestEnabled": true,
"python.sortImports.args": ["-sp .isort.cfg"]
"python.testing.pytestEnabled": true
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ adheres to [Semantic Versioning](https://semver.org/).
- Update GitHub actions dependencies
- Add tests for PyPy 3.10 and 3.11
- Improve tox & CI pipelines
- Use ruff as formatter

## [0.5.0] - 2023-02-27

Expand Down
5 changes: 1 addition & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
# build
build==1.3.0

# format
black==23.1.0
isort==5.12.0

# lint
pylint==2.16.2
ruff==0.13.1

# typing
mypy==1.0.1
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# ruff
#

[tool.ruff]
src = ["src"]
target-version = "py39"
9 changes: 3 additions & 6 deletions src/xz/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def xz_open(
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
) -> XZFile:
... # pragma: no cover
) -> XZFile: ... # pragma: no cover


@overload
Expand All @@ -97,8 +96,7 @@ def xz_open(
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
) -> _XZFileText:
... # pragma: no cover
) -> _XZFileText: ... # pragma: no cover


@overload
Expand All @@ -115,8 +113,7 @@ def xz_open(
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
) -> Union[XZFile, _XZFileText]:
... # pragma: no cover
) -> Union[XZFile, _XZFileText]: ... # pragma: no cover


def xz_open(
Expand Down
9 changes: 3 additions & 6 deletions src/xz/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@


class _BlockReadStrategyType(Protocol):
def on_create(self, block: "XZBlock") -> None:
... # pragma: no cover
def on_create(self, block: "XZBlock") -> None: ... # pragma: no cover

def on_delete(self, block: "XZBlock") -> None:
... # pragma: no cover
def on_delete(self, block: "XZBlock") -> None: ... # pragma: no cover

def on_read(self, block: "XZBlock") -> None:
... # pragma: no cover
def on_read(self, block: "XZBlock") -> None: ... # pragma: no cover
13 changes: 6 additions & 7 deletions tests/integration/test_ram_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def test_read_linear(
while xz_file.read(DEFAULT_BUFFER_SIZE):
assert (
# should not use much more memory, take 2 as error margin
ram_usage()
< one_block_memory * 2
ram_usage() < one_block_memory * 2
), f"Consumes too much RAM (at {100 * xz_file.tell() / len(xz_file):.0f}%)"


Expand All @@ -89,9 +88,10 @@ def test_partial_read_each_block(
else:
assert (
# default strategy is max 8 blocks, take 10 as error margin
ram_usage()
< one_block_memory * 10
), f"Consumes too much RAM (at {100 * xz_file.tell() / len(xz_file):.0f}%)"
ram_usage() < one_block_memory * 10
), (
f"Consumes too much RAM (at {100 * xz_file.tell() / len(xz_file):.0f}%)"
)


def test_write(
Expand All @@ -115,6 +115,5 @@ def test_write(
else:
assert (
# should not use much more memory, take 2 as error margin
ram_usage()
< one_block_memory * 2
ram_usage() < one_block_memory * 2
), f"Consumes too much RAM (at {i / nb_blocks:.0f}%)"
4 changes: 1 addition & 3 deletions tests/integration/test_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def _parse_readme() -> List[Tuple[int, str]]:
for line_no, code_block in _README_CODE_BLOCKS
],
)
def test_readme(
code_block: str, tmp_path: Path
) -> None: # pylint: disable=redefined-outer-name
def test_readme(code_block: str, tmp_path: Path) -> None: # pylint: disable=redefined-outer-name
path = tmp_path / "block.txt"
path.write_text(code_block)
failure_count, test_count = doctest.testfile(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_read_wrong_uncompressed_size_too_big(


def test_read_wrong_block_padding(
data_pattern_locate: Callable[[bytes], Tuple[int, int]]
data_pattern_locate: Callable[[bytes], Tuple[int, int]],
) -> None:
fileobj = IOStatic(BLOCK_BYTES[:-5] + b"\xff" + BLOCK_BYTES[-4:])
block = XZBlock(fileobj, 1, 89, 100)
Expand All @@ -228,7 +228,7 @@ def test_read_wrong_block_padding(


def test_read_wrong_check(
data_pattern_locate: Callable[[bytes], Tuple[int, int]]
data_pattern_locate: Callable[[bytes], Tuple[int, int]],
) -> None:
fileobj = IOStatic(BLOCK_BYTES[:-4] + b"\xff" * 4)

Expand Down Expand Up @@ -261,7 +261,7 @@ def test_read_truncated_data() -> None:


def test_read_decompressor_eof(
data_pattern_locate: Callable[[bytes], Tuple[int, int]]
data_pattern_locate: Callable[[bytes], Tuple[int, int]],
) -> None:
fileobj = IOStatic(
bytes.fromhex(
Expand Down
14 changes: 3 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[tox]
envlist =
py, py39, py310, py311, pypy3
build, format, generate-integration-files, lint, type
build, generate-integration-files, lint, type

[testenv]
package = wheel
Expand All @@ -27,16 +27,6 @@ deps =
commands =
python -m build

[testenv:format]
basepython = python3.11
skip_install = true
deps =
black==23.1.0
isort==5.12.0
commands =
black {posargs:--check --diff} src tests
isort {posargs:--check --diff} src tests

[testenv:generate-integration-files]
basepython = python3.11
deps =
Expand All @@ -53,7 +43,9 @@ basepython = python3.11
deps =
pylint==2.16.2
pytest==7.2.1 # to avoid import errors
ruff==0.13.1
commands =
ruff format --check src tests
pylint src
pylint -d duplicate-code,too-many-statements,use-implicit-booleaness-not-comparison tests

Expand Down