Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» devxp: add editorconfig and copier answers (#25)
Browse files Browse the repository at this point in the history
* πŸ”§ config(pre-commit): update

* πŸ§‘β€πŸ’» devxp: add editorconfig and copier answers

* πŸ”§ config: update pyproject and sync

* πŸ”§ config(ruff): add back old ignores

* πŸ”§ config(mypy): add mypy paths

* βœ… test(utils): make sure client is always closed
  • Loading branch information
ljnsn authored Oct 17, 2024
1 parent 2ef7fba commit bcb0b1f
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 162 deletions.
25 changes: 25 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changes here will be overwritten by Copier
_commit: v0.0.3
_src_path: [email protected]:ljnsn/copier-python-poly.git
author_email: [email protected]
author_name: ljnsn
ci: true
ci_provider: github
commitizen: true
coverage: true
cz_gitmoji: true
description: CoinAPI Python REST Client
license: MIT
loguru: false
maximum_python_version: ''
minimum_python_version: '3.10'
mypy: true
package_manager: uv
pre_commit: true
project_name: coinapi-rest
project_snake: coinapi
pytest: true
ruff: true
sqlalchemy: false
structure: src
web_app: false
35 changes: 35 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
root = true

[*]
tab_width = 4
end_of_line = lf
max_line_length = 88
ij_visual_guides = 88,120
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,py,html}]
charset = utf-8

[*.{js,jsx,ts,tsx}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.{json,yml,yaml}]
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab

[.flake8]
indent_style = space
indent_size = 2

[*.py]
indent_style = space
indent_size = 4
ij_python_from_import_parentheses_force_if_multiline = true
18 changes: 10 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

default_install_hook_types: [commit-msg, pre-commit]
default_stages: [commit, manual]
default_stages: [pre-commit, manual]
fail_fast: true
minimum_pre_commit_version: "1.4.3"

repos:
- repo: meta
Expand All @@ -18,10 +16,10 @@ repos:
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
# - id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
args: [--assume-in-merge]
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
Expand All @@ -35,9 +33,6 @@ repos:
types: [python]
- id: fix-byte-order-marker
- id: mixed-line-ending
# - id: name-tests-test
# args: [--pytest-test-first]
# exclude: ^workspaces/.+/tests/(factories|fakes).py$
- id: trailing-whitespace
types: [python]

Expand Down Expand Up @@ -71,6 +66,13 @@ repos:

- repo: local
hooks:
# Prevent committing .rej files
- id: forbidden-files
name: forbidden files
entry: found Copier update rejection files; review and remove them before merging.
language: fail
files: "\\.rej$"

- id: ruff
name: Fix with ruff
entry: ruff check
Expand Down
144 changes: 77 additions & 67 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ name = "coinapi-rest"
version = "0.0.5"
description = "CoinAPI Python REST Client"
authors = [{ name = "ljnsn", email = "[email protected]" }]
dependencies = [
"httpx>=0.27.0",
"msgspec>=0.18.6",
"python-dotenv>=1.0.1",
"typing-inspect>=0.9.0",
]
requires-python = ">=3.10"
readme = "README.md"
license = { text = "MIT" }
license = "MIT"
urls = { repository = "https://github.com/ljnsn/coinapi-rest" }
keywords = ["cryptocurrency", "crypto", "prices", "coinapi"]
classifiers = [
Expand All @@ -38,18 +31,27 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
requires-python = ">=3.10"
dependencies = [
"httpx>=0.27.0",
"msgspec>=0.18.6",
"python-dotenv>=1.0.1",
"typing-inspect>=0.9.0",
]

[tool.uv]
dev-dependencies = [
"commitizen>=3.16.0",
"coverage>=7.4.3",
"cz-conventional-gitmoji>=0.2.4",
"ipython!=8.18.0",
"mypy>=1.8.0",
"pre-commit>=3.6.2",
"commitizen>=3.29.0",
"coverage>=7.6.1",
"cz-conventional-gitmoji>=0.3.3",
"ipdb>=0.13.13",
"ipython>=7.16.1,!=8.18.0",
"mypy>=0.1.8",
"pre-commit>=1.4.3",
"pytest-cov>=5.0.0",
"pytest-recording>=0.13.1",
"pytest>=8.0.0",
"ruff>=0.3.0",
"pytest>=8.3.2",
"ruff>=0.2.2",
"syrupy>=0.0.15",
]

Expand All @@ -59,49 +61,19 @@ version_provider = "pep621"
tag_format = "v$version"
bump_message = "πŸ”– bump(release): v$current_version β†’ v$new_version"
update_changelog_on_bump = true

[tool.mypy]
mypy_path = ["src", "tests"]
namespace_packages = true
explicit_package_bases = true
junit_xml = "reports/mypy.xml"
strict = true
disallow_subclassing_any = false
disallow_untyped_decorators = false
ignore_missing_imports = true
pretty = false
show_column_numbers = true
show_error_codes = true
show_error_context = true
warn_unreachable = true

[tool.coverage.run]
branch = true
command_line = "--module pytest"
data_file = "reports/.coverage"
include = ["src/*"]
omit = ["tests/*"]

[tool.coverage.paths]
source = ["src/"]

[tool.coverage.report]
fail_under = 50
precision = 1
show_missing = true
skip_covered = true
include = ["src/*"]
omit = ["tests/*"]

[tool.coverage.xml]
output = "reports/coverage.xml"

annotated_tag = true
allowed_prefixes = ["Squash", "Merge", "Revert"]
pre_bump_hooks = ["uv lock --upgrade-package coinapi-rest"]
[tool.ruff]
fix = true
target-version = "py310"
src = ["src", "test"]
src = ["src", "tests"]
line-length = 88

[tool.ruff.format]
line-ending = "lf"
indent-style = "space"

[tool.ruff.lint]
logger-objects = ["loguru"]
select = ["ALL"]
Expand Down Expand Up @@ -140,6 +112,12 @@ ignore = [
"TD001",
# Line contains FIXME, consider resolving the issue
"FIX001",
# from * used; unable to detect undefined names
"F403",
# may be undefined, or defined from star imports
"F405",
# Docstring contains ambiguous `’`
"RUF002",
#############################################################################
# Rules conflicting with `ruff format`
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
Expand Down Expand Up @@ -174,12 +152,6 @@ ignore = [
"ISC001",
# Multiline implicit string concatenation
"ISC002",
# from * used; unable to detect undefined names
"F403",
# may be undefined, or defined from star imports
"F405",
# Docstring contains ambiguous `’`
"RUF002",
]
unfixable = ["ERA001", "F401", "F841"]

Expand All @@ -189,20 +161,22 @@ unfixable = ["ERA001", "F401", "F841"]
"DTZ001",
# positional boolean args
"FBT001",
# part of an implicit namespace package
"INP001",
# usage of `assert` in tests
"S101",
# magic value used in comarison
"PLR2004",
# private member accessed
"SLF001",
]

[tool.ruff.format]
line-ending = "lf"
indent-style = "space"
"scripts/**/*.py" = [
# part of implicit namespace package
"INP001",
]

[tool.ruff.lint.isort]
known-first-party = ["coinapi"]
known-first-party = ["coinapi", "tests"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand All @@ -214,10 +188,46 @@ ban-relative-imports = "all"
[tool.ruff.lint.pep8-naming]
classmethod-decorators = ["classmethod"]

[tool.mypy]
mypy_path = ["src", "tests"]
namespace_packages = true
explicit_package_bases = true
junit_xml = "reports/mypy.xml"
strict = true
disallow_subclassing_any = false
disallow_untyped_decorators = false
ignore_missing_imports = true
pretty = false
show_column_numbers = true
show_error_codes = true
show_error_context = true
warn_unreachable = true

[tool.pytest.ini_options]
addopts = """--color=yes --doctest-modules --exitfirst --failed-first \
--strict-markers --strict-config --verbosity=2 \
--junitxml=reports/pytest.xml"""
filterwarnings = ["ignore::DeprecationWarning", "ignore::ResourceWarning"]
testpaths = ["src", "tests"]
filterwarnings = ["error"]
testpaths = ["tests"]
markers = ["network: mark a test as needing a network connection"]

[tool.coverage.run]
branch = true
command_line = "--module pytest"
data_file = "reports/.coverage"
include = ["src/*"]
omit = ["tests/*"]

[tool.coverage.report]
fail_under = 50
precision = 1
show_missing = true
skip_covered = true
include = ["src/*"]
omit = ["tests/*"]

[tool.coverage.paths]
source = ["src/"]

[tool.coverage.xml]
output = "reports/coverage.xml"
19 changes: 13 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import base64
import datetime as dt
import enum
from collections.abc import Iterator
from decimal import Decimal
from typing import Annotated, Any, Union

Expand All @@ -13,6 +14,14 @@
from coinapi.utils import utils


@pytest.fixture(name="http_client")
def http_client_fixture() -> Iterator[httpx.Client]:
"""Fixture for HTTP client."""
http_client = httpx.Client()
yield http_client
http_client.close()


class TestSecurityClient:
"""Tests for SecurityClient."""

Expand All @@ -23,10 +32,9 @@ def test_init(self) -> None:
assert client.timeout == 60
assert isinstance(client.limits, httpx.Limits)

def test_send_with_client(self) -> None:
def test_send_with_client(self, http_client: httpx.Client) -> None:
"""Test send method with a client."""
mock_client = httpx.Client()
client = utils.SecurityClient(client=mock_client)
client = utils.SecurityClient(client=http_client)
request = httpx.Request("GET", "https://example.com")
response = client.send(request)
assert isinstance(response, httpx.Response)
Expand Down Expand Up @@ -492,10 +500,9 @@ def test_init(self) -> None:
assert client.timeout == 60
assert isinstance(client.limits, httpx.Limits)

def test_send_with_client(self) -> None:
def test_send_with_client(self, http_client: httpx.Client) -> None:
"""Test send method with a client."""
mock_client = httpx.Client()
client = utils.SecurityClient(client=mock_client)
client = utils.SecurityClient(client=http_client)
request = httpx.Request("GET", "https://example.com")
response = client.send(request)
assert isinstance(response, httpx.Response)
Expand Down
Loading

0 comments on commit bcb0b1f

Please sign in to comment.