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
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

40 changes: 24 additions & 16 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
[flake8]
max-line-length = 88
ignore = E501, E203, W503
per-file-ignores =
__init__.py:F401
# F401: Module imported but unused
# TC001: Move import into type checking block
__init__.py:F401, TC001
# F811: Redefinition of unused name from line n
pendulum/tz/timezone.py:F811
exclude =
.git
__pycache__
setup.py
build
dist
releases
.idea
.venv
.tox
.mypy_cache
.pytest_cache
.vscode
.github
min_python_version = 3.7.0
ban-relative-imports = true
# flake8-use-fstring: https://github.com/MichaelKim0407/flake8-use-fstring#--percent-greedy-and---format-greedy
format-greedy = 1
inline-quotes = double
enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions
eradicate-whitelist-extend = ^-.*;
extend-ignore =
# E501: Line too long
E501,
# E203: Whitespace before ':'
E203,
# SIM106: Handle error-cases first
SIM106,
extend-exclude =
# External to the project's coding standards:
docs/*,
# Machine-generated, too many false-positives
pendulum/locales/*,
62 changes: 49 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,68 @@ ci:
autofix_prs: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
exclude: ^tests/.*/fixtures/.*
- id: end-of-file-fixer
exclude: ^tests/.*/fixtures/.*
- id: debug-statements

- repo: https://github.com/hadialqattan/pycln
rev: v2.1.1
hooks:
- id: pycln
args: [--all]

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [--add-import, from __future__ import annotations]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: &flake8_deps
- flake8-broken-line==0.4.0
- flake8-bugbear==22.7.1
- flake8-comprehensions==3.10.0
- flake8-eradicate==1.2.1
- flake8-quotes==3.3.1
- flake8-simplify==0.19.2
- flake8-tidy-imports==4.8.0
- flake8-type-checking==2.0.3
- flake8-typing-imports==1.12.0
- flake8-use-fstring==1.3
- pep8-naming==0.13.1

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: isort
exclude: ^.*/?setup\.py$
- id: yesqa
additional_dependencies: *flake8_deps

- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
rev: v2.37.3
hooks:
- id: pyupgrade
exclude: ^build\.py$
args:
- --py37-plus

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
- id: trailing-whitespace
exclude: ^tests/.*/fixtures/.*
- id: end-of-file-fixer
exclude: ^tests/.*/fixtures/.*
- id: debug-statements
- id: mypy
pass_filenames: false
exclude: ^build\.py$
additional_dependencies:
- pytest>=7.1.2
6 changes: 2 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ def build_extension(self, ext):
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError):
print(
' Unable to build the "{}" C extension, '
"Pendulum will use the pure python version of the extension.".format(
ext.name
)
f' Unable to build the "{ext.name}" C extension, '
"Pendulum will use the pure python version of the extension."
)


Expand Down
19 changes: 10 additions & 9 deletions clock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import annotations

import glob
import json
import os
Expand Down Expand Up @@ -191,16 +193,16 @@ translations = {{}}
else:
v = repr(v)

s.append("{}{!r}: {},\n".format(" " * tab, k, v))
s.append("%s}" % (" " * (tab - 1)))
s.append(f"{' ' * tab}{k!r}: {v},\n")
s.append(f'{" " * (tab - 1)}}}')

return "".join(s)

def plural_rule_to_lambda(self, rule):
to_py = _LambdaCompiler().compile
result = ["lambda n: "]
for tag, ast in PluralRule.parse(rule).abstract:
result.append("'{}' if {} else ".format(tag, to_py(ast)))
result.append(f"'{tag}' if {to_py(ast)} else ")
result.append("'other'")
return "".join(result)

Expand All @@ -215,13 +217,13 @@ translations = {{}}
limit = PATTERN_CHARS[fieldchar]
if limit and fieldnum not in limit:
raise ValueError(
"Invalid length for field: %r" % (fieldchar * fieldnum)
f"Invalid length for field: {(fieldchar * fieldnum)!r}"
)
result.append(
self.TOKENS_MAP.get(fieldchar * fieldnum, fieldchar * fieldnum)
)
else:
raise NotImplementedError("Unknown token type: %s" % tok_type)
raise NotImplementedError(f"Unknown token type: {tok_type}")

return "".join(result)

Expand Down Expand Up @@ -250,17 +252,16 @@ class WindowsTzDump(Command):

def handle(self):
raw_tznames = get_global("windows_zone_mapping")
sorted_names = sorted(list(raw_tznames.keys()))
sorted_names = sorted(raw_tznames.keys())

tznames = {}
for name in sorted_names:
tznames[name] = raw_tznames[name]

mapping = json.dumps(tznames, indent=4)
mapping = "windows_timezones = " + mapping.replace('"', "'") + "\n"
mapping = json.dumps(tznames, indent=4).replace('"', "'")

with open(os.path.join(self.MAPPING_DIR, "windows.py"), "w") as f:
f.write(mapping)
f.write(f"windows_timezones = {mapping}\n")


app = Application("clock", __version__)
Expand Down
Loading