Skip to content

Commit

Permalink
3.2.4 - IndentedFileWriter linesep control
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Apr 21, 2024
1 parent 8afd501 commit a80124d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=vcorelib version=3.2.3
repo=vcorelib version=3.2.4
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[DESIGN]
max-args=10
max-attributes=8

[SIMILARITIES]
ignore-imports=yes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=f8b97332b3af92a47a234fed499d57a3
hash=bc0b27e02d365bc98f792016fb5c40a1
=====================================
-->

# vcorelib ([3.2.3](https://pypi.org/project/vcorelib/))
# vcorelib ([3.2.4](https://pypi.org/project/vcorelib/))

[![python](https://img.shields.io/pypi/pyversions/vcorelib.svg)](https://pypi.org/project/vcorelib/)
![Build Status](https://github.com/vkottler/vcorelib/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion config
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
major: 3
minor: 2
patch: 3
patch: 4
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "vcorelib"
version = "3.2.3"
version = "3.2.4"
description = "A collection of core Python utilities."
readme = "README.md"
requires-python = ">=3.11"
Expand Down
4 changes: 2 additions & 2 deletions vcorelib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=fc6cd8303d817a213ff66471838bb02b
# hash=72f33cb7eb34d1a8b0e94f5741c13762
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A collection of core Python utilities."
PKG_NAME = "vcorelib"
VERSION = "3.2.3"
VERSION = "3.2.4"

# vcorelib-specific content.
DEFAULT_INDENT = 2
Expand Down
15 changes: 9 additions & 6 deletions vcorelib/io/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from contextlib import contextmanager
from enum import Enum, auto
from io import StringIO
from os import linesep
import os
from pathlib import Path
from typing import Iterator, List, Optional, TextIO, Tuple

Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(
per_indent: int = 1,
prefix: str = "",
suffix: str = "",
linesep: str = os.linesep,
) -> None:
"""Initialize this instance."""

Expand All @@ -61,6 +62,8 @@ def __init__(
self._prefix = prefix
self._suffix = suffix

self.linesep = linesep

@contextmanager
def prefix(self, prefix: str) -> Iterator[None]:
"""Set a new line prefix as a managed context."""
Expand Down Expand Up @@ -93,13 +96,13 @@ def ends(self, prefix: str = "", suffix: str = "") -> Iterator[None]:
@staticmethod
@contextmanager
def from_path(
path: Path, space: str = " ", per_indent: int = 1
path: Path, space: str = " ", per_indent: int = 1, **kwargs
) -> Iterator["IndentedFileWriter"]:
"""Create an instance from a path as a managed context."""

with path.open("w", encoding=DEFAULT_ENCODING) as stream:
yield IndentedFileWriter(
stream, space=space, per_indent=per_indent
stream, space=space, per_indent=per_indent, **kwargs
)

@staticmethod
Expand All @@ -117,13 +120,13 @@ def string(
@staticmethod
@contextmanager
def temporary(
space: str = " ", per_indent: int = 1
space: str = " ", per_indent: int = 1, **kwargs
) -> Iterator["IndentedFileWriter"]:
"""Create an instance from a temporary file as a managed context."""

with tempfile() as tmp:
with IndentedFileWriter.from_path(
tmp, space=space, per_indent=per_indent
tmp, space=space, per_indent=per_indent, **kwargs
) as writer:
yield writer

Expand All @@ -144,7 +147,7 @@ def write(self, data: str) -> int:
self.space * self.depth * self.per_indent if line_data else ""
)

line = (indent + line_data).rstrip() + linesep
line = (indent + line_data).rstrip() + self.linesep

self.stream.write(line)
count += len(line)
Expand Down

0 comments on commit a80124d

Please sign in to comment.