Skip to content

Commit

Permalink
Merge pull request #136 from callowayproject/encoding
Browse files Browse the repository at this point in the history
Fix encoding when reading text.
  • Loading branch information
coordt authored Feb 10, 2024
2 parents 0c3e7e8 + 9515afc commit a5b13bb
Show file tree
Hide file tree
Showing 41 changed files with 70 additions and 32 deletions.
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.1.14'
rev: 'v0.2.1'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: test.*
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -45,7 +45,7 @@ repos:
args: [--no-strict-optional, --ignore-missing-imports]
additional_dependencies: ["pydantic>2.0", "toml", "types-all"]
- repo: https://github.com/jsh9/pydoclint
rev: 0.3.9
rev: 0.4.0
hooks:
- id: pydoclint
args:
Expand All @@ -55,9 +55,6 @@ repos:
hooks:
- id: interrogate
exclude: test.*
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
hooks:
- id: check-azure-pipelines

ci:
autofix_prs: false
1 change: 1 addition & 0 deletions bumpversion/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main entrypoint for module."""

from bumpversion.cli import cli

cli()
1 change: 1 addition & 0 deletions bumpversion/aliases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for handling command aliases."""

from typing import List, Optional

import rich_click as click
Expand Down
1 change: 1 addition & 0 deletions bumpversion/bump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Version changing methods."""

import shlex
from pathlib import Path
from typing import TYPE_CHECKING, ChainMap, List, Optional
Expand Down
1 change: 1 addition & 0 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""bump-my-version Command line interface."""

from pathlib import Path
from typing import List, Optional

Expand Down
1 change: 1 addition & 0 deletions bumpversion/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration management."""

from __future__ import annotations

from typing import TYPE_CHECKING, Union
Expand Down
3 changes: 2 additions & 1 deletion bumpversion/config/create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for creating a new config file."""

from pathlib import Path
from typing import Tuple

Expand Down Expand Up @@ -57,7 +58,7 @@ def get_defaults_from_dest(destination: str) -> Tuple[dict, TOMLDocument]:

config = DEFAULTS.copy()
if Path(destination).exists():
destination_config = parse(Path(destination).read_text())
destination_config = parse(Path(destination).read_text(encoding="utf-8"))
else:
destination_config = document()

Expand Down
8 changes: 6 additions & 2 deletions bumpversion/config/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def find_config_file(explicit_file: Union[str, Path, None] = None) -> Union[Path
[Path(explicit_file)] if explicit_file else [Path.cwd().joinpath(path) for path in CONFIG_FILE_SEARCH_ORDER]
)
return next(
(cfg_file for cfg_file in search_paths if cfg_file.exists() and "bumpversion]" in cfg_file.read_text()),
(
cfg_file
for cfg_file in search_paths
if cfg_file.exists() and "bumpversion]" in cfg_file.read_text(encoding="utf-8")
),
None,
)

Expand Down Expand Up @@ -91,7 +95,7 @@ def read_toml_file(file_path: Path) -> Dict[str, Any]:
import tomlkit

# Load the TOML file
toml_data = tomlkit.parse(file_path.read_text()).unwrap()
toml_data = tomlkit.parse(file_path.read_text(encoding="utf-8")).unwrap()

return toml_data.get("tool", {}).get("bumpversion", {})

Expand Down
3 changes: 2 additions & 1 deletion bumpversion/config/files_legacy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module handles the legacy config file format."""

from __future__ import annotations

import re
Expand Down Expand Up @@ -102,7 +103,7 @@ def update_ini_config_file(
)

config_path = Path(config_file)
existing_config = config_path.read_text()
existing_config = config_path.read_text(encoding="utf-8")
if config_path.suffix == ".cfg" and cfg_current_version_regex.search(existing_config):
sub_str = f"\\g<section_prefix>{new_version}"
new_config = cfg_current_version_regex.sub(sub_str, existing_config)
Expand Down
1 change: 1 addition & 0 deletions bumpversion/config/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bump My Version configuration models."""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions bumpversion/config/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions for the config module."""

from __future__ import annotations

import glob
Expand Down
1 change: 1 addition & 0 deletions bumpversion/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Custom exceptions for BumpVersion."""

from typing import Optional

from click import Context, UsageError
Expand Down
3 changes: 2 additions & 1 deletion bumpversion/files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Methods for changing files."""

import os.path
import re
from copy import deepcopy
Expand Down Expand Up @@ -331,7 +332,7 @@ def _update_toml_file(
"""Update a TOML file."""
import tomlkit

toml_data = tomlkit.parse(self.path.read_text())
toml_data = tomlkit.parse(self.path.read_text(encoding="utf-8"))
value_before = get_nested_value(toml_data, self.file_change.key_path)

if value_before is None:
Expand Down
1 change: 1 addition & 0 deletions bumpversion/indented_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A logger adapter that adds an indent to the beginning of each message."""

import logging
from contextvars import ContextVar
from typing import Any, MutableMapping, Optional, Tuple
Expand Down
1 change: 1 addition & 0 deletions bumpversion/show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for displaying information about the version."""

import dataclasses
from io import StringIO
from pprint import pprint
Expand Down
1 change: 1 addition & 0 deletions bumpversion/ui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for user interface."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions bumpversion/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""General utilities."""

import datetime
import string
from collections import ChainMap
Expand Down
1 change: 1 addition & 0 deletions bumpversion/version_part.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for managing Versions and their internal parts."""

import re
from typing import Any, Dict, List, MutableMapping, Optional, Tuple

Expand Down
1 change: 1 addition & 0 deletions bumpversion/versioning/conventions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Standard version conventions."""

from bumpversion.versioning.models import VersionComponentSpec, VersionSpec

# Adapted from https://packaging.python.org/en/latest/specifications/version-specifiers/
Expand Down
1 change: 1 addition & 0 deletions bumpversion/versioning/functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generators for version parts."""

import re
from typing import List, Optional, Union

Expand Down
1 change: 1 addition & 0 deletions bumpversion/versioning/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Models for managing versioning of software projects."""

from __future__ import annotations

from collections import defaultdict, deque
Expand Down
1 change: 1 addition & 0 deletions bumpversion/versioning/serialization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for serializing and deserializing version objects."""

import re
from copy import copy
from operator import itemgetter
Expand Down
1 change: 1 addition & 0 deletions bumpversion/visualize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Visualize the bumpversion process."""

from dataclasses import dataclass
from typing import List, Optional

Expand Down
1 change: 1 addition & 0 deletions bumpversion/yaml_dump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A simple YAML dumper to avoid extra dependencies."""

import datetime
from collections import UserDict
from io import StringIO
Expand Down
1 change: 1 addition & 0 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Sphinx configuration.
"""

# flake8: noqa
import os
import sys
Expand Down
39 changes: 19 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,6 @@ color = true
line-length = 119

[tool.ruff]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
# "UP" "TRY" "PLR"
select = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PLC", "PLE", "PLW", "TCH"]
ignore = [
"ANN002", "ANN003", "ANN101", "ANN102", "ANN204", "ANN401",
"S101", "S104",
"D105", "D106", "D107", "D200", "D212",
"PD011",
"PLW1510",
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PL", "PLC", "PLE", "PLW", "TCH"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
Expand All @@ -189,22 +173,37 @@ exclude = [
# Same as Black.
line-length = 119

[tool.ruff.lint]
select = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PLC", "PLE", "PLW", "TCH"]
ignore = [
"ANN002", "ANN003", "ANN101", "ANN102", "ANN204", "ANN401",
"S101", "S104",
"D105", "D106", "D107", "D200", "D212",
"PD011",
"PLW1510",
]

fixable = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PL", "PLC", "PLE", "PLW", "TCH"]
unfixable = []

# Exclude a variety of commonly ignored directories.

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

typing-modules = ["typing", "types", "typing_extensions", "mypy", "mypy_extensions"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101", "PLR0913", "PLR0915", "PGH003", "ANN001", "ANN202", "ANN201", "PLR0912", "TRY301", "PLW0603", "PLR2004", "ANN101", "S106", "TRY201", "ANN003", "ANN002", "S105", "TRY003"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10

[tool.ruff.isort]
[tool.ruff.lint.isort]
order-by-type = true

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.bumpversion]
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing fixtures for Pytest."""

import subprocess
from contextlib import contextmanager
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/test_autocast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the autocast module."""

import pytest
from pytest import param

Expand Down
1 change: 1 addition & 0 deletions tests/test_bump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the bump module."""

from pathlib import Path
from textwrap import dedent
from unittest.mock import MagicMock, patch
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_bump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the bump CLI subcommand."""

import shutil
import subprocess
from datetime import datetime
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_replace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for `bumpversion` package."""

import shutil
import traceback
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_show_bump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the show_bump command."""

import shutil
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions tests/test_config/test_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the create function in the config module."""

from pathlib import Path
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_config/test_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test configuration parsing."""

import difflib
import json
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/test_configuredfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the ConfiguredFile class."""

from bumpversion.files import ConfiguredFile, FileChange
from bumpversion.version_part import VersionConfig
from bumpversion.versioning.models import VersionComponentSpec
Expand Down
1 change: 1 addition & 0 deletions tests/test_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""File processing tests."""

import os
import shutil
from datetime import datetime, timezone
Expand Down
1 change: 1 addition & 0 deletions tests/test_scm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests of the VCS module."""

import subprocess
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the utils module."""

from itertools import combinations

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_versioning/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the serialization of versioned objects."""

from bumpversion.versioning.serialization import parse_version, serialize
from bumpversion.versioning.conventions import semver_spec, SEMVER_PATTERN
from bumpversion.versioning.models import Version, VersionSpec, VersionComponentSpec
Expand Down
1 change: 1 addition & 0 deletions tests/test_visualize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests of the visualize module."""

from pathlib import Path

from bumpversion.visualize import Border, BOX_CHARS, connection_str, lead_string, labeled_line, visualize
Expand Down
1 change: 1 addition & 0 deletions tests/test_yaml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the yaml serialization module."""

from pathlib import Path

from bumpversion import yaml_dump
Expand Down

0 comments on commit a5b13bb

Please sign in to comment.