Skip to content

Commit 3173d73

Browse files
authored
Apply black (#1158)
1 parent 9234be3 commit 3173d73

Some content is hidden

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

64 files changed

+12830
-9235
lines changed

.flake8

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[flake8]
2+
3+
max-line-length = 119
4+
ignore = W503, E203, E501, E722, F401
5+
6+
exclude =
7+
docs/conf.py

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Apply the auto-formatter black
2+
24c1637dcc77aac006db8ebcfbf5199fa7abac5d

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ jobs:
5353
- name: Upload coverage.xml to codecov
5454
if: ${{ matrix.python-version == '3.9' && matrix.env.TOXENV == 'latest'}}
5555
uses: codecov/codecov-action@v3
56+
57+
pre-commit:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v3
61+
- uses: pre-commit/[email protected]

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
profile = black

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/PyCQA/flake8
3+
rev: 6.0.0 # 6.0.0 drops Python 3.7 support
4+
hooks:
5+
- id: flake8
6+
args: ['--config=.flake8']
7+
- repo: https://github.com/psf/black.git
8+
rev: 23.3.0
9+
hooks:
10+
- id: black
11+
exclude: ^dateparser/data/date_translation_data/
12+
- repo: https://github.com/pycqa/isort
13+
rev: 5.12.0 # 5.12 drops Python 3.7 support
14+
hooks:
15+
- id: isort

conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ def pytest_collection_modifyitems(session, config, items):
22
# Avoid executing tests when executing `--flake8` flag (pytest-flake8)
33
try:
44
from pytest_flake8 import Flake8Item
5-
if config.getoption('--flake8'):
5+
6+
if config.getoption("--flake8"):
67
items[:] = [item for item in items if isinstance(item, Flake8Item)]
78
except ImportError:
89
pass

dateparser/__init__.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
__version__ = '1.1.8'
1+
__version__ = "1.1.8"
22

3-
from .date import DateDataParser
43
from .conf import apply_settings
4+
from .date import DateDataParser
55

66
_default_parser = DateDataParser()
77

88

99
@apply_settings
10-
def parse(date_string, date_formats=None, languages=None, locales=None,
11-
region=None, settings=None, detect_languages_function=None):
10+
def parse(
11+
date_string,
12+
date_formats=None,
13+
languages=None,
14+
locales=None,
15+
region=None,
16+
settings=None,
17+
detect_languages_function=None,
18+
):
1219
"""Parse date and time from given date string.
1320
1421
:param date_string:
@@ -54,11 +61,22 @@ def parse(date_string, date_formats=None, languages=None, locales=None,
5461
"""
5562
parser = _default_parser
5663

57-
if languages or locales or region or detect_languages_function or not settings._default:
58-
parser = DateDataParser(languages=languages, locales=locales,
59-
region=region, settings=settings, detect_languages_function=detect_languages_function)
64+
if (
65+
languages
66+
or locales
67+
or region
68+
or detect_languages_function
69+
or not settings._default
70+
):
71+
parser = DateDataParser(
72+
languages=languages,
73+
locales=locales,
74+
region=region,
75+
settings=settings,
76+
detect_languages_function=detect_languages_function,
77+
)
6078

6179
data = parser.get_date_data(date_string, date_formats)
6280

6381
if data:
64-
return data['date_obj']
82+
return data["date_obj"]

dateparser/calendars/__init__.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from datetime import datetime
2+
3+
from dateparser.conf import settings
14
from dateparser.date import DateData
25
from dateparser.parser import _parser
3-
from dateparser.conf import settings
4-
from datetime import datetime
56

67

78
class CalendarBase:
@@ -26,7 +27,6 @@ def get_date(self):
2627

2728

2829
class non_gregorian_parser(_parser):
29-
3030
calendar_converter = NotImplemented
3131
default_year = NotImplemented
3232
default_month = NotImplemented
@@ -77,15 +77,16 @@ def to_latin(cls, source):
7777
return result
7878

7979
def _get_datetime_obj(self, **params):
80-
day = params['day']
81-
year = params['year']
82-
month = params['month']
83-
if (
84-
not(0 < day <= self.calendar_converter.month_length(year, month))
85-
and not(self._token_day or hasattr(self, '_token_weekday'))
80+
day = params["day"]
81+
year = params["year"]
82+
month = params["month"]
83+
if not (0 < day <= self.calendar_converter.month_length(year, month)) and not (
84+
self._token_day or hasattr(self, "_token_weekday")
8685
):
8786
day = self.calendar_converter.month_length(year, month)
88-
year, month, day = self.calendar_converter.to_gregorian(year=year, month=month, day=day)
87+
year, month, day = self.calendar_converter.to_gregorian(
88+
year=year, month=month, day=day
89+
)
8990
c_params = params.copy()
9091
c_params.update(dict(year=year, month=month, day=day))
9192
return datetime(**c_params)
@@ -94,38 +95,39 @@ def _get_datetime_obj_params(self):
9495
if not self.now:
9596
self._set_relative_base()
9697
now_year, now_month, now_day = self.calendar_converter.from_gregorian(
97-
self.now.year, self.now.month, self.now.day)
98+
self.now.year, self.now.month, self.now.day
99+
)
98100
params = {
99-
'day': self.day or now_day,
100-
'month': self.month or now_month,
101-
'year': self.year or now_year,
102-
'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0,
101+
"day": self.day or now_day,
102+
"month": self.month or now_month,
103+
"year": self.year or now_year,
104+
"hour": 0,
105+
"minute": 0,
106+
"second": 0,
107+
"microsecond": 0,
103108
}
104109
return params
105110

106111
def _get_date_obj(self, token, directive):
107112
year, month, day = self.default_year, self.default_month, self.default_day
108113
token_len = len(token)
109114
is_digit = token.isdigit()
110-
if directive == '%A' and self._weekdays and token.title() in self._weekdays:
115+
if directive == "%A" and self._weekdays and token.title() in self._weekdays:
111116
pass
112117
elif (
113-
directive == '%m'
114-
and token_len <= 2
115-
and is_digit
116-
and 1 <= int(token) <= 12
118+
directive == "%m" and token_len <= 2 and is_digit and 1 <= int(token) <= 12
117119
):
118120
month = int(token)
119-
elif directive == '%B' and self._months and token in self._months:
121+
elif directive == "%B" and self._months and token in self._months:
120122
month = list(self._months.keys()).index(token) + 1
121123
elif (
122-
directive == '%d'
124+
directive == "%d"
123125
and token_len <= 2
124126
and is_digit
125127
and 0 < int(token) <= self.calendar_converter.month_length(year, month)
126128
):
127129
day = int(token)
128-
elif directive == '%Y' and token_len == 4 and is_digit:
130+
elif directive == "%Y" and token_len == 4 and is_digit:
129131
year = int(token)
130132
else:
131133
raise ValueError

dateparser/calendars/hijri_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55

66
class hijri:
7-
87
@classmethod
98
def to_gregorian(cls, year=None, month=None, day=None):
10-
g = convert.Hijri(year=year, month=month, day=day, validate=False).to_gregorian()
9+
g = convert.Hijri(
10+
year=year, month=month, day=day, validate=False
11+
).to_gregorian()
1112
return g.datetuple()
1213

1314
@classmethod
@@ -35,16 +36,15 @@ def weekday(self):
3536

3637

3738
class hijri_parser(non_gregorian_parser):
38-
3939
calendar_converter = hijri
4040
default_year = 1389
4141
default_month = 1
4242
default_day = 1
4343
non_gregorian_date_cls = HijriDate
4444

4545
_time_conventions = {
46-
'am': ["صباحاً"],
47-
'pm': ["مساءً"],
46+
"am": ["صباحاً"],
47+
"pm": ["مساءً"],
4848
}
4949

5050
@classmethod

dateparser/calendars/jalali.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from . import CalendarBase
21
from dateparser.calendars.jalali_parser import jalali_parser
32

3+
from . import CalendarBase
4+
45

56
class JalaliCalendar(CalendarBase):
67
"""Calendar class for Jalali calendar."""

0 commit comments

Comments
 (0)