Skip to content

Commit 205a86a

Browse files
authored
Cleanup and lint codebase (#447)
1 parent 00b7fdd commit 205a86a

File tree

108 files changed

+904
-390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+904
-390
lines changed

.flake8

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[flake8]
2+
max-line-length = 88
3+
ignore = E501, E203, W503
4+
per-file-ignores =
5+
__init__.py:F401
6+
pendulum/tz/timezone.py:F811
7+
exclude =
8+
.git
9+
__pycache__
10+
setup.py
11+
build
12+
dist
13+
releases
14+
.idea
15+
.venv
16+
.tox
17+
.mypy_cache
18+
.pytest_cache
19+
.vscode
20+
.github

.pre-commit-config.yaml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
repos:
2-
- repo: https://github.com/ambv/black
2+
- repo: https://github.com/psf/black
33
rev: stable
44
hooks:
5-
- id: black
6-
python_version: python3.6
5+
- id: black
6+
7+
- repo: https://gitlab.com/pycqa/flake8
8+
rev: 3.7.8
9+
hooks:
10+
- id: flake8
11+
12+
- repo: https://github.com/timothycrosley/isort
13+
rev: 4.3.21
14+
hooks:
15+
- id: isort
16+
additional_dependencies: [toml]
17+
exclude: ^.*/?setup\.py$
18+
19+
- repo: https://github.com/pre-commit/pre-commit-hooks
20+
rev: v2.3.0
21+
hooks:
22+
- id: trailing-whitespace
23+
exclude: ^tests/.*/fixtures/.*
24+
- id: end-of-file-fixer
25+
exclude: ^tests/.*/fixtures/.*
26+
- id: debug-statements

build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import os
22
import sys
33

4-
5-
from distutils.core import Extension
6-
7-
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
84
from distutils.command.build_ext import build_ext
5+
from distutils.core import Extension
6+
from distutils.errors import CCompilerError
7+
from distutils.errors import DistutilsExecError
8+
from distutils.errors import DistutilsPlatformError
99

1010

1111
# C Extensions

clock

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ import json
66
import os
77

88
from babel.core import get_global
9-
from babel.plural import (
10-
PluralRule,
11-
compile_zero,
12-
_GettextCompiler,
13-
_binary_compiler,
14-
_unary_compiler,
15-
)
16-
from babel.dates import tokenize_pattern, PATTERN_CHARS
17-
from babel.localedata import load, normalize_locale, LocaleDataDict
18-
19-
from cleo import Application, Command
9+
from babel.dates import PATTERN_CHARS
10+
from babel.dates import tokenize_pattern
11+
from babel.localedata import LocaleDataDict
12+
from babel.localedata import load
13+
from babel.localedata import normalize_locale
14+
from babel.plural import PluralRule
15+
from babel.plural import _binary_compiler
16+
from babel.plural import _GettextCompiler
17+
from babel.plural import _unary_compiler
18+
from babel.plural import compile_zero
19+
from cleo import Application
20+
from cleo import Command
2021
from cleo import argument
22+
2123
from pendulum import __version__
2224

2325

@@ -52,14 +54,16 @@ class LocaleCreate(Command):
5254

5355
TEMPLATE = """# -*- coding: utf-8 -*-
5456
from __future__ import unicode_literals
57+
58+
from .custom import translations as custom_translations
59+
60+
5561
\"\"\"
5662
{locale} locale file.
5763
5864
It has been generated automatically and must not be modified directly.
5965
\"\"\"
6066
61-
from .custom import translations as custom_translations
62-
6367
6468
locale = {{
6569
'plural': {plural},
@@ -71,6 +75,8 @@ locale = {{
7175

7276
CUSTOM_TEMPLATE = """# -*- coding: utf-8 -*-
7377
from __future__ import unicode_literals
78+
79+
7480
\"\"\"
7581
{locale} custom locale file.
7682
\"\"\"

docs/docs/index.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
{!installation.md!}
2-
{!introduction.md!}
3-
{!instantiation.md!}
4-
{!parsing.md!}
5-
{!localization.md!}
6-
{!attributes_properties.md!}
7-
{!fluent_helpers.md!}
8-
{!string_formatting.md!}
9-
{!comparison.md!}
10-
{!addition_subtraction.md!}
11-
{!difference.md!}
12-
{!modifiers.md!}
13-
{!timezones.md!}
14-
{!duration.md!}
15-
{!period.md!}
16-
{!testing.md!}
17-
{!limitations.md!}
1+
{!docs/installation.md!}
2+
{!docs/introduction.md!}
3+
{!docs/instantiation.md!}
4+
{!docs/parsing.md!}
5+
{!docs/localization.md!}
6+
{!docs/attributes_properties.md!}
7+
{!docs/fluent_helpers.md!}
8+
{!docs/string_formatting.md!}
9+
{!docs/comparison.md!}
10+
{!docs/addition_subtraction.md!}
11+
{!docs/difference.md!}
12+
{!docs/modifiers.md!}
13+
{!docs/timezones.md!}
14+
{!docs/duration.md!}
15+
{!docs/period.md!}
16+
{!docs/testing.md!}
17+
{!docs/limitations.md!}

docs/docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Installing `pendulum` is quite simple:
66
$ pip install pendulum
77
```
88

9-
or, if you are using [poetry](https://poetry.eustace.io):
9+
or, if you are using [poetry](https://python-poetry.org):
1010

1111
```bash
1212
$ poetry add pendulum

docs/docs/testing.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ The provided instance will be returned specifically under the following conditio
3030

3131
Related methods will also return values mocked according to the **now** instance.
3232

33-
```python
3433
>>> print(pendulum.today())
3534
'2001-05-21T00:00:00+00:00'
3635

docs/docs/timezones.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ with the `in_timezone()` method.
102102
!!!warning
103103

104104
**You should avoid using the timezone library in Python < 3.6.**
105-
105+
106106
This is due to the fact that Pendulum relies heavily on the presence
107107
of the `fold` attribute which was introduced in Python 3.6.
108-
108+
109109
The reason it works inside the Pendulum ecosystem is that it
110110
backports the `fold` attribute in the `DateTime` class.
111111

pendulum/__init__.py

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,57 @@
11
from __future__ import absolute_import
22

33
import datetime as _datetime
4-
from typing import Union, Optional
54

6-
from .__version__ import __version__
5+
from typing import Optional
6+
from typing import Union
77

8-
# Types
9-
from .datetime import DateTime
8+
from .__version__ import __version__
9+
from .constants import DAYS_PER_WEEK
10+
from .constants import FRIDAY
11+
from .constants import HOURS_PER_DAY
12+
from .constants import MINUTES_PER_HOUR
13+
from .constants import MONDAY
14+
from .constants import MONTHS_PER_YEAR
15+
from .constants import SATURDAY
16+
from .constants import SECONDS_PER_DAY
17+
from .constants import SECONDS_PER_HOUR
18+
from .constants import SECONDS_PER_MINUTE
19+
from .constants import SUNDAY
20+
from .constants import THURSDAY
21+
from .constants import TUESDAY
22+
from .constants import WEDNESDAY
23+
from .constants import WEEKS_PER_YEAR
24+
from .constants import YEARS_PER_CENTURY
25+
from .constants import YEARS_PER_DECADE
1026
from .date import Date
11-
from .time import Time
27+
from .datetime import DateTime
1228
from .duration import Duration
29+
from .formatting import Formatter
30+
from .helpers import format_diff
31+
from .helpers import get_locale
32+
from .helpers import get_test_now
33+
from .helpers import has_test_now
34+
from .helpers import locale
35+
from .helpers import set_locale
36+
from .helpers import set_test_now
37+
from .helpers import test
38+
from .helpers import week_ends_at
39+
from .helpers import week_starts_at
40+
from .parser import parse
1341
from .period import Period
14-
42+
from .time import Time
43+
from .tz import POST_TRANSITION
44+
from .tz import PRE_TRANSITION
45+
from .tz import TRANSITION_ERROR
46+
from .tz import UTC
47+
from .tz import local_timezone
48+
from .tz import set_local_timezone
49+
from .tz import test_local_timezone
1550
from .tz import timezone
16-
from .tz import PRE_TRANSITION, POST_TRANSITION, TRANSITION_ERROR
51+
from .tz import timezones
1752
from .tz.timezone import Timezone as _Timezone
18-
19-
from .formatting import Formatter
20-
21-
# Helpers
22-
from .helpers import (
23-
test,
24-
set_test_now,
25-
has_test_now,
26-
get_test_now,
27-
set_locale,
28-
get_locale,
29-
locale,
30-
format_diff,
31-
week_starts_at,
32-
week_ends_at,
33-
)
34-
3553
from .utils._compat import _HAS_FOLD
3654

37-
from .tz import timezones, local_timezone, test_local_timezone, set_local_timezone, UTC
38-
39-
from .parser import parse
40-
41-
# Constants
42-
from .constants import (
43-
MONDAY,
44-
TUESDAY,
45-
WEDNESDAY,
46-
THURSDAY,
47-
FRIDAY,
48-
SATURDAY,
49-
SUNDAY,
50-
YEARS_PER_CENTURY,
51-
YEARS_PER_DECADE,
52-
MONTHS_PER_YEAR,
53-
WEEKS_PER_YEAR,
54-
DAYS_PER_WEEK,
55-
HOURS_PER_DAY,
56-
MINUTES_PER_HOUR,
57-
SECONDS_PER_MINUTE,
58-
SECONDS_PER_HOUR,
59-
SECONDS_PER_DAY,
60-
)
6155

6256
_TEST_NOW = None # type: Optional[DateTime]
6357
_LOCALE = "en"
@@ -245,11 +239,8 @@ def yesterday(tz="local"): # type: (Union[str, _Timezone]) -> DateTime
245239

246240

247241
def from_format(
248-
string, # type: str
249-
fmt, # type: str
250-
tz=UTC, # type: Union[str, _Timezone]
251-
locale=None, # type: Optional[str]
252-
): # type: (...) -> DateTime
242+
string, fmt, tz=UTC, locale=None, # noqa
243+
): # type: (str, str, Union[str, _Timezone], Optional[str]) -> DateTime
253244
"""
254245
Creates a DateTime instance from a specific format.
255246
"""

pendulum/_extensions/_helpers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ PyObject* precise_diff(PyObject *self, PyObject *args) {
609609
dt1_minute -= dt1_offset / SECS_PER_MIN;
610610
dt1_offset %= SECS_PER_MIN;
611611
dt1_second -= dt1_offset;
612-
612+
613613
if (dt1_second < 0) {
614614
dt1_second += 60;
615615
dt1_minute -= 1;
@@ -634,7 +634,7 @@ PyObject* precise_diff(PyObject *self, PyObject *args) {
634634
dt1_day += 1;
635635
}
636636
}
637-
637+
638638
dt1_total_seconds = (
639639
dt1_hour * SECS_PER_HOUR
640640
+ dt1_minute * SECS_PER_MIN
@@ -713,7 +713,7 @@ PyObject* precise_diff(PyObject *self, PyObject *args) {
713713
);
714714

715715
if (dt1_gt_dt2) {
716-
PyObject* temp;
716+
PyObject* temp;
717717
temp = dt1;
718718
dt1 = dt2;
719719
dt2 = temp;

pendulum/_extensions/helpers.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
import math
2-
from collections import namedtuple
3-
41
import datetime
2+
import math
53
import typing
64

7-
from ..constants import (
8-
EPOCH_YEAR,
9-
SECS_PER_DAY,
10-
SECS_PER_400_YEARS,
11-
SECS_PER_100_YEARS,
12-
SECS_PER_4_YEARS,
13-
SECS_PER_YEAR,
14-
SECS_PER_HOUR,
15-
SECS_PER_MIN,
16-
DAYS_PER_MONTHS,
17-
MONTHS_OFFSETS,
18-
TM_DECEMBER,
19-
TM_JANUARY,
20-
DAY_OF_WEEK_TABLE,
21-
DAYS_PER_L_YEAR,
22-
DAYS_PER_N_YEAR,
23-
)
5+
from collections import namedtuple
6+
7+
from ..constants import DAY_OF_WEEK_TABLE
8+
from ..constants import DAYS_PER_L_YEAR
9+
from ..constants import DAYS_PER_MONTHS
10+
from ..constants import DAYS_PER_N_YEAR
11+
from ..constants import EPOCH_YEAR
12+
from ..constants import MONTHS_OFFSETS
13+
from ..constants import SECS_PER_4_YEARS
14+
from ..constants import SECS_PER_100_YEARS
15+
from ..constants import SECS_PER_400_YEARS
16+
from ..constants import SECS_PER_DAY
17+
from ..constants import SECS_PER_HOUR
18+
from ..constants import SECS_PER_MIN
19+
from ..constants import SECS_PER_YEAR
20+
from ..constants import TM_DECEMBER
21+
from ..constants import TM_JANUARY
2422

2523

2624
class PreciseDiff(

0 commit comments

Comments
 (0)