From 117a26b31d2686b559a913dfc3115dc0c4859e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 22 Jan 2018 10:37:22 -0500 Subject: [PATCH 01/63] Bump version to 1.4.0 --- CHANGELOG.md | 7 ++++--- docs/conf.py | 4 ++-- pendulum/version.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfbc46d5..fcdd785f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ # Change Log -## [Unreleased] +## [1.4.0] - 2017-01-22 ### Changed -- `format()`, `diff_for_humans()`, `in_words()` and `to_xxx_string()` methods now return unicode strings. +- `format()`, `diff_for_humans()`, `in_words()` and `to_xxx_string()` methods now return unicode strings for Python 2.7. - Improved performance of `now()` and `utcnow()`. (Thanks to [pganssle](https://github.com/pganssle)) ### Fixed @@ -440,7 +440,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.3.2...master +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.0...1.x +[1.4.0]: https://github.com/sdispater/pendulum/releases/tag/1.4.0 [1.3.2]: https://github.com/sdispater/pendulum/releases/tag/1.3.2 [1.3.1]: https://github.com/sdispater/pendulum/releases/tag/1.3.1 [1.3.0]: https://github.com/sdispater/pendulum/releases/tag/1.3.0 diff --git a/docs/conf.py b/docs/conf.py index f5b7be44..487cd4e8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -58,9 +58,9 @@ # built documents. # # The short X.Y version. -version = '1.3' +version = '1.4' # The full version, including alpha/beta/rc tags. -release = '1.3.2' +release = '1.4.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pendulum/version.py b/pendulum/version.py index fa653fde..c43f3e25 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.3.2' +VERSION = '1.4.0' From 1e46765631b85ccfbd1f97156882ea5f273bbf32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 22 Jan 2018 11:03:01 -0500 Subject: [PATCH 02/63] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcdd785f..4d68dd9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [1.4.0] - 2017-01-22 +## [1.4.0] - 2018-01-22 ### Changed From 3a0513ccad656f4b95cbd1e71039103e4ccafd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 24 Jan 2018 13:22:06 -0500 Subject: [PATCH 03/63] Fix an error when comparing a Period to a timedelta in PyPy --- .gitignore | 1 + .travis.yml | 1 + CHANGELOG.md | 7 +++++++ pendulum/period.py | 13 ++++++++++++- tests/period_tests/test_behavior.py | 11 +++++++++++ tox.ini | 2 +- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 29615ef8..402ca831 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ nosetests.xml .DS_Store .idea/* +.python-version /test.py /test_*.* diff --git a/.travis.yml b/.travis.yml index 73101e67..850d370c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ matrix: - python: 3.6 env: PENDULUM_EXTENSIONS=0 - python: pypy + - python: pypy3 before_install: - pip install codecov diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d68dd9d..37db55ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [Unreleased] + +### Fixed + +- Fixed an error when comparing a Period to a timedelta in PyPy. + + ## [1.4.0] - 2018-01-22 ### Changed diff --git a/pendulum/period.py b/pendulum/period.py index 5b7cd0cc..9f427088 100644 --- a/pendulum/period.py +++ b/pendulum/period.py @@ -3,7 +3,7 @@ import operator import pendulum -from datetime import datetime, date +from datetime import datetime, date, timedelta from .mixins.interval import WordableIntervalMixin from .interval import BaseInterval, Interval @@ -300,6 +300,17 @@ def __repr__(self): self._start, self._end ) + def _cmp(self, other): + # Only needed for PyPy3 + assert isinstance(other, timedelta) + + if isinstance(other, Period): + other = other.as_timedelta() + + td = self.as_timedelta() + + return 0 if td == other else 1 if td > other else -1 + def _getstate(self, protocol=3): start, end = self.start, self.end diff --git a/tests/period_tests/test_behavior.py b/tests/period_tests/test_behavior.py index f93f86fa..3f2700bd 100644 --- a/tests/period_tests/test_behavior.py +++ b/tests/period_tests/test_behavior.py @@ -2,6 +2,9 @@ import pickle import pendulum + +from datetime import timedelta + from .. import AbstractTestCase @@ -34,3 +37,11 @@ def test_pickle(self): self.assertEqual(p.start, p2.start) self.assertEqual(p.end, p2.end) self.assertEqual(p.invert, p2.invert) + + def test_comparison_to_timedelta(self): + dt1 = pendulum.create(2016, 11, 18) + dt2 = pendulum.create(2016, 11, 20) + + period = dt2 - dt1 + + assert period < timedelta(days=4) diff --git a/tox.ini b/tox.ini index f664d936..c3305105 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,35,36}-{without,with}-extensions, pypy +envlist = py{27,35,36}-{without,with}-extensions, pypy, pypy3 [testenv] deps = -rtests-requirements.txt From 5a596b0ab75960a8e86700cbe0f9ae6ec4fe1442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 24 Jan 2018 16:27:25 -0500 Subject: [PATCH 04/63] Fix an offset error for datetimes between the before last and last transition --- CHANGELOG.md | 1 + pendulum/tz/timezone.py | 84 +++++++++++++++------------------ tests/tz_tests/test_timezone.py | 9 ++++ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37db55ee..250485c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed an error when comparing a Period to a timedelta in PyPy. +- Fixed an offset error for datetimes between the before last and last transition. ## [1.4.0] - 2018-01-22 diff --git a/pendulum/tz/timezone.py b/pendulum/tz/timezone.py index 88592396..cb520de3 100644 --- a/pendulum/tz/timezone.py +++ b/pendulum/tz/timezone.py @@ -218,65 +218,55 @@ def _normalize(self, dt, dst_rule=None): offset = self._tzinfos[tzinfo_index].offset unix_time = (dt - datetime(1970, 1, 1)).total_seconds() - offset else: - # tr.pre_time < dt < tr.time - # Skipped time - if dst_rule == self.TRANSITION_ERROR: - raise NonExistingTime(dt) - elif dst_rule == self.PRE_TRANSITION: - # We do not apply the transition - (unix_time, - tzinfo_index) = self._get_previous_transition_time(tr, dt, skipped=True) - else: - unix_time = tr.unix_time - (tr.time - dt).total_seconds() + unix_time, tzinfo_index = self._get_time(dt, tr, dst_rule) elif tr is end: if tr.pre_time < dt: # After the last transition. unix_time = tr.unix_time + (dt - tr.time).total_seconds() else: - # tr.time <= dt <= tr.pre_time - # Repeated time - if dst_rule == self.TRANSITION_ERROR: - raise AmbiguousTime(dt) - elif dst_rule == self.PRE_TRANSITION: - # We do not apply the transition - (unix_time, - tzinfo_index) = self._get_previous_transition_time(tr, dt) - else: - unix_time = tr.unix_time + (dt - tr.time).total_seconds() + unix_time, tzinfo_index = self._get_time(dt, tr, dst_rule) else: - if tr.pre_time <= dt < tr.time: - # tr.pre_time <= dt < tr.time - # Skipped time - if dst_rule == self.TRANSITION_ERROR: - raise NonExistingTime(dt) - elif dst_rule == self.PRE_TRANSITION: - # We do not apply the transition - (unix_time, - tzinfo_index) = self._get_previous_transition_time(tr, dt, skipped=True) - else: - unix_time = tr.unix_time - (tr.pre_time - dt).total_seconds() - elif tr.time <= dt <= tr.pre_time: - # tr.time <= dt <= tr.pre_time - # Repeated time - if dst_rule == self.TRANSITION_ERROR: - raise AmbiguousTime(dt) - elif dst_rule == self.PRE_TRANSITION: - # We do not apply the transition - (unix_time, - tzinfo_index) = self._get_previous_transition_time(tr, dt) - else: - unix_time = tr.unix_time + (dt - tr.time).total_seconds() - else: - # In between transitions - # The actual transition type is the previous transition one - (unix_time, - tzinfo_index) = self._get_previous_transition_time(tr, dt) + unix_time, tzinfo_index = self._get_time(dt, tr, dst_rule) return self._to_local_time( unix_time, dt.microsecond, tzinfo_index, fold ) + def _get_time(self, dt, tr, dst_rule): + tzinfo_index = tr._tzinfo_index + + if tr.pre_time <= dt < tr.time: + # tr.pre_time <= dt < tr.time + # Skipped time + if dst_rule == self.TRANSITION_ERROR: + raise NonExistingTime(dt) + elif dst_rule == self.PRE_TRANSITION: + # We do not apply the transition + (unix_time, + tzinfo_index) = self._get_previous_transition_time(tr, dt, + skipped=True) + else: + unix_time = tr.unix_time - (tr.pre_time - dt).total_seconds() + elif tr.time <= dt <= tr.pre_time: + # tr.time <= dt <= tr.pre_time + # Repeated time + if dst_rule == self.TRANSITION_ERROR: + raise AmbiguousTime(dt) + elif dst_rule == self.PRE_TRANSITION: + # We do not apply the transition + (unix_time, + tzinfo_index) = self._get_previous_transition_time(tr, dt) + else: + unix_time = tr.unix_time + (dt - tr.time).total_seconds() + else: + # In between transitions + # The actual transition type is the previous transition one + (unix_time, + tzinfo_index) = self._get_previous_transition_time(tr, dt) + + return unix_time, tzinfo_index + def _convert(self, dt): """ Converts a timezone-aware datetime to local time. diff --git a/tests/tz_tests/test_timezone.py b/tests/tz_tests/test_timezone.py index 7b2ccd55..2b092315 100644 --- a/tests/tz_tests/test_timezone.py +++ b/tests/tz_tests/test_timezone.py @@ -227,6 +227,15 @@ def test_on_last_transition(self): assert dt.microsecond == 0 assert dt.utcoffset().total_seconds() == 7200 + def test_just_before_last_transition(self): + tz = pendulum.timezone('Asia/Shanghai') + dt = datetime(1991, 4, 20, 1, 49, 8) + dt = tz.convert(dt, dst_rule=tz.POST_TRANSITION) + + epoch = datetime(1970, 1, 1, tzinfo=timezone('UTC')) + expected = (dt - epoch).total_seconds() + assert expected == 672079748.0 + def test_convert_fold_attribute_is_honored(self): self.skip_if_not_36() From 56f93ba0104bd7387c902c75432486aa21750984 Mon Sep 17 00:00:00 2001 From: Delgan Date: Mon, 29 Jan 2018 20:04:04 +0100 Subject: [PATCH 05/63] Fix unpickling with undefined / empty timezone name (#174) --- pendulum/pendulum.py | 8 +------- pendulum/tz/timezone.py | 2 +- tests/pendulum_tests/test_behavior.py | 9 +++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pendulum/pendulum.py b/pendulum/pendulum.py index cbbf94ac..6cca7f63 100644 --- a/pendulum/pendulum.py +++ b/pendulum/pendulum.py @@ -1980,16 +1980,10 @@ def __getnewargs__(self): return(self, ) def _getstate(self, protocol=3): - tz = self.timezone_name - - # Fix for fixed timezones not being properly unpickled - if isinstance(self.tz, FixedTimezone): - tz = self.offset_hours - return ( self.year, self.month, self.day, self.hour, self.minute, self.second, self.microsecond, - tz, + self.tzinfo, self.fold ) diff --git a/pendulum/tz/timezone.py b/pendulum/tz/timezone.py index cb520de3..416b352d 100644 --- a/pendulum/tz/timezone.py +++ b/pendulum/tz/timezone.py @@ -512,7 +512,7 @@ def fromutc(self, dt): return (dt + self._tzinfo.adjusted_offset).replace(tzinfo=self._tzinfo) def __getinitargs__(self): - return self._offset + return (self._offset, ) class _UTC(FixedTimezone): diff --git a/tests/pendulum_tests/test_behavior.py b/tests/pendulum_tests/test_behavior.py index 12a12854..76d90edf 100644 --- a/tests/pendulum_tests/test_behavior.py +++ b/tests/pendulum_tests/test_behavior.py @@ -6,6 +6,7 @@ from datetime import datetime, date, time, timedelta from pendulum import Pendulum, timezone from pendulum.tz.timezone import Timezone +from pendulum.tz.loader import Loader from .. import AbstractTestCase @@ -101,6 +102,14 @@ def test_pickle_with_integer_tzinfo(self): self.assertEqual(dt1, dt2) + def test_pickle_with_empty_tzinfo_name(self): + empty_timezone = Timezone('', *Loader.load('Europe/Paris')) + dt1 = Pendulum(2016, 8, 27, 12, 34, 56, 123456, empty_timezone) + s = pickle.dumps(dt1) + dt2 = pickle.loads(s) + + self.assertEqual(dt1, dt2) + def test_proper_dst(self): dt = pendulum.create(1941, 7, 1, tz='Europe/Amsterdam') From 3a5bc4fef9a7c5ff121f3dd374168b33a2236e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 5 Feb 2018 13:32:17 -0500 Subject: [PATCH 06/63] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 250485c0..7ae78bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed an error when comparing a Period to a timedelta in PyPy. - Fixed an offset error for datetimes between the before last and last transition. +- Fixed unpickling with undefined / empty timezone name. (Thanks to [Delgan](https://github.com/Delgan)) ## [1.4.0] - 2018-01-22 From e0f40304d4f304831072c0fa6bf2b3e873deaaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 5 Feb 2018 14:34:37 -0500 Subject: [PATCH 07/63] Bump version to 1.4.1 --- CHANGELOG.md | 5 +++-- docs/conf.py | 2 +- pendulum/version.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae78bce..0de09ace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.4.1] - 2018-02-05 ### Fixed @@ -449,7 +449,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.0...1.x +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.1...1.x +[1.4.1]: https://github.com/sdispater/pendulum/releases/tag/1.4.1 [1.4.0]: https://github.com/sdispater/pendulum/releases/tag/1.4.0 [1.3.2]: https://github.com/sdispater/pendulum/releases/tag/1.3.2 [1.3.1]: https://github.com/sdispater/pendulum/releases/tag/1.3.1 diff --git a/docs/conf.py b/docs/conf.py index 487cd4e8..7db67fca 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,7 +60,7 @@ # The short X.Y version. version = '1.4' # The full version, including alpha/beta/rc tags. -release = '1.4.0' +release = '1.4.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pendulum/version.py b/pendulum/version.py index c43f3e25..453ea502 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.0' +VERSION = '1.4.1' From 5b06241f07ade260cb8825e7394890f2e4937b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Feb 2018 17:47:02 -0500 Subject: [PATCH 08/63] Fix offset error when subtracting datetimes in the same tz --- CHANGELOG.md | 7 +++++++ pendulum/helpers.py | 5 ++++- tests/period_tests/test_add_subtract.py | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de09ace..e6902d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [Unreleased] + +### Fixed + +- Fixed an offset error when subtracting datetimes in the same timezone. + + ## [1.4.1] - 2018-02-05 ### Fixed diff --git a/pendulum/helpers.py b/pendulum/helpers.py index 23b70232..b96245b3 100644 --- a/pendulum/helpers.py +++ b/pendulum/helpers.py @@ -194,7 +194,10 @@ def precise_diff(d1, d2): if hasattr(d2, 'hour'): # If we are not in the same timezone # we need to adjust - if not in_same_tz: + # + # We also need to adjust if we do not + # have variable-length units + if not in_same_tz or total_days == 0: offset1 = d1.utcoffset() offset2 = d2.utcoffset() diff --git a/tests/period_tests/test_add_subtract.py b/tests/period_tests/test_add_subtract.py index d645401f..3b177a1d 100644 --- a/tests/period_tests/test_add_subtract.py +++ b/tests/period_tests/test_add_subtract.py @@ -12,6 +12,15 @@ def test_dst_add(): assert new_end == end +def test_dst_add_non_variable_units(): + start = pendulum.create(2013, 3, 31, 1, 30, tz='Europe/Paris') + end = start.add(hours=1) + period = end - start + new_end = start + period + + assert new_end == end + + def test_dst_subtract(): start = pendulum.create(2017, 3, 7, tz='America/Toronto') end = start.add(days=6) From 1d714600ce267b340b00d3f28c140ecea6472d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 21 Feb 2018 16:51:18 -0500 Subject: [PATCH 09/63] Fix wrong value returned by tzname() for the UTC timezone --- CHANGELOG.md | 1 + pendulum/tz/timezone.py | 2 +- tests/tz_tests/test_timezone.py | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6902d5c..e23b9e50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed an offset error when subtracting datetimes in the same timezone. +- Fixed wrong value returned by `tzname()` for the UTC timezone ## [1.4.1] - 2018-02-05 diff --git a/pendulum/tz/timezone.py b/pendulum/tz/timezone.py index 416b352d..fad44e5c 100644 --- a/pendulum/tz/timezone.py +++ b/pendulum/tz/timezone.py @@ -518,7 +518,7 @@ def __getinitargs__(self): class _UTC(FixedTimezone): def __init__(self): - super(_UTC, self).__init__(0, 'UTC', TransitionType(0, False, 'GMT')) + super(_UTC, self).__init__(0, 'UTC', TransitionType(0, False, 'UTC')) UTC._tz = self diff --git a/tests/tz_tests/test_timezone.py b/tests/tz_tests/test_timezone.py index 2b092315..2b389aab 100644 --- a/tests/tz_tests/test_timezone.py +++ b/tests/tz_tests/test_timezone.py @@ -379,3 +379,9 @@ def test_fixed_timezone(self): self.assertEqual(tz2.utcoffset(dt).total_seconds(), 18000) self.assertIsNone(tz2.dst(dt)) + + def test_utc_tzname(self): + tz = Timezone.load('UTC') + dt = datetime(2016, 11, 26) + + assert tz.tzname(dt) == 'UTC' From 374d1da7c384797ef0d215418bb331aa30ff09d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 21 Feb 2018 16:59:00 -0500 Subject: [PATCH 10/63] Fix deepcopy() raising an error when using UTC --- CHANGELOG.md | 3 ++- pendulum/tz/timezone_info.py | 4 ++++ tests/pendulum_tests/test_behavior.py | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e23b9e50..fa2ebb53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ ### Fixed - Fixed an offset error when subtracting datetimes in the same timezone. -- Fixed wrong value returned by `tzname()` for the UTC timezone +- Fixed wrong value returned by `tzname()` for the UTC timezone. +- Fixed `deepcopy()` raising an error when using `UTC`. ## [1.4.1] - 2018-02-05 diff --git a/pendulum/tz/timezone_info.py b/pendulum/tz/timezone_info.py index 8dc1f4a7..a4ab1975 100644 --- a/pendulum/tz/timezone_info.py +++ b/pendulum/tz/timezone_info.py @@ -134,4 +134,8 @@ def dst(self, dt): def fromutc(self, dt): return dt.replace(tzinfo=self) + def __getinitargs__(self): + return () + + UTC = _UTC() diff --git a/tests/pendulum_tests/test_behavior.py b/tests/pendulum_tests/test_behavior.py index 76d90edf..acfbd65a 100644 --- a/tests/pendulum_tests/test_behavior.py +++ b/tests/pendulum_tests/test_behavior.py @@ -125,6 +125,11 @@ def test_deepcopy_datetime(self): self.assertEqual(dt._datetime, deepcopy(dt._datetime)) + def test_deepcopy_datetime_utcnow(self): + dt = pendulum.utcnow() + + self.assertEqual(dt._datetime, deepcopy(dt._datetime)) + def test_pickle_timezone(self): dt1 = pendulum.timezone('Europe/Amsterdam') s = pickle.dumps(dt1) From 8178bffabae5ed977ff52c87fa95e29cf0ecd40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Thu, 22 Feb 2018 15:14:59 -0500 Subject: [PATCH 11/63] Bump version to 1.4.2 --- CHANGELOG.md | 5 +++-- docs/conf.py | 2 +- pendulum/version.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa2ebb53..26318764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.4.2] - 2018-02-22 ### Fixed @@ -458,7 +458,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.1...1.x +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.2...1.x +[1.4.2]: https://github.com/sdispater/pendulum/releases/tag/1.4.2 [1.4.1]: https://github.com/sdispater/pendulum/releases/tag/1.4.1 [1.4.0]: https://github.com/sdispater/pendulum/releases/tag/1.4.0 [1.3.2]: https://github.com/sdispater/pendulum/releases/tag/1.3.2 diff --git a/docs/conf.py b/docs/conf.py index 7db67fca..c6f1bc20 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,7 +60,7 @@ # The short X.Y version. version = '1.4' # The full version, including alpha/beta/rc tags. -release = '1.4.1' +release = '1.4.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pendulum/version.py b/pendulum/version.py index 453ea502..abf07abc 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.1' +VERSION = '1.4.2' From 5cb910b2da142fc77280e276403d3b34e6f5d072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 5 Mar 2018 11:08:09 -0500 Subject: [PATCH 12/63] Update dependencies requirements --- .gitignore | 1 + pyproject.toml | 28 ++++++++++++++++++++++++++++ requirements.txt | 6 +++--- setup.py | 15 ++++++++++----- tests-requirements.txt | 7 +++---- 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index 402ca831..f400f9a1 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ benchmark.py results.json profile.html /wheelhouse +pyproject.lock diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..80ba49ab --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[tool.poetry] +name = "pendulum" +version = "1.4.2" +description = "Python datetimes made easy." + +license = "MIT" + +authors = [ + "Sébastien Eustace " +] + +readme = 'README.rst' + +homepage = "https://pendulum.eustace.io" +repository = "https://github.com/sdispater/pendulum" + +keywords = ['datetime', 'date', 'time', 'timezone'] + + +[tool.poetry.dependencies] +python = "~2.7 || ^3.4" +python-dateutil = "^2.6" +tzlocal = "^1.5" +pytzdata = ">=2018.3" + +[tool.poetry.dev-dependencies] +pytest = "^3.4" +pytest-cov = "^2.4" diff --git a/requirements.txt b/requirements.txt index 390579a2..2b04c39b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -tzlocal -python-dateutil -pytzdata>=2017.2.2 +tzlocal>=1.5.0,<2.0.0 +python-dateutil>=2.6.0,<3.0.0 +pytzdata>=2018.3 diff --git a/setup.py b/setup.py index bd780d6a..a59a0c93 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,7 @@ def get_version(): ['pendulum/_extensions/_helpers.c']), ] + class BuildFailed(Exception): pass @@ -66,6 +67,7 @@ def build_extension(self, ext): DistutilsPlatformError, ValueError): raise BuildFailed() + packages = ['pendulum'] for pkg in find_packages('pendulum'): packages.append('pendulum.' + pkg) @@ -82,13 +84,16 @@ def build_extension(self, ext): download_url='https://github.com/sdispater/pendulum/archive/%s.tar.gz' % __version__, packages=packages, install_requires=[ - 'tzlocal', - 'python-dateutil', - 'pytzdata', + 'tzlocal>=1.5.0,<2.0.0', + 'python-dateutil>=2.6.0,<3.0.0', + 'pytzdata>=2018.3', ], include_package_data=True, - tests_require=['pytest'], - test_suite='nose.collector', + tests_require=[ + 'pytest>=3.4.0,<4.0.0', + 'pytest-cov>=2.4.0,<3.0.0', + 'pytz>=2018.3', + ], classifiers=[ 'Intended Audience :: Developers', 'Operating System :: OS Independent', diff --git a/tests-requirements.txt b/tests-requirements.txt index edfd951d..5b9891f1 100644 --- a/tests-requirements.txt +++ b/tests-requirements.txt @@ -1,5 +1,4 @@ -r requirements.txt -pytest -pytest-cov -coverage<4 -pytz +pytest>=3.4.0,<4.0.0 +pytest-cov>=2.4.0,<3.0.0 +pytz>=2018.3 From a7400a770e802ea57b9fb87fb43f7fd097bb242e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 12 Mar 2018 15:50:24 -0500 Subject: [PATCH 13/63] Fix an error when adding an interval to a pendulum instance across DST transition --- CHANGELOG.md | 7 +++++++ pendulum/pendulum.py | 3 +-- tests/pendulum_tests/test_add.py | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26318764..37d697ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [Unreleased] + +### Fixed + +- Fixed an error when adding intervals to a Pendulum instance across DST transition. + + ## [1.4.2] - 2018-02-22 ### Fixed diff --git a/pendulum/pendulum.py b/pendulum/pendulum.py index 6cca7f63..38f37eec 100644 --- a/pendulum/pendulum.py +++ b/pendulum/pendulum.py @@ -1233,8 +1233,7 @@ def add_timedelta(self, delta): seconds=delta.remaining_seconds, microseconds=delta.microseconds ) - return self.add(days=delta.days, seconds=delta.seconds, - microseconds=delta.microseconds) + return self.add(seconds=delta.total_seconds()) def subtract_timedelta(self, delta): """ diff --git a/tests/pendulum_tests/test_add.py b/tests/pendulum_tests/test_add.py index e11fd031..822fbc02 100644 --- a/tests/pendulum_tests/test_add.py +++ b/tests/pendulum_tests/test_add.py @@ -236,3 +236,9 @@ def test_add_time_to_new_transition_does_not_use_transition_rule(self): self.assertEqual('Europe/Paris', dt.timezone_name) self.assertEqual(7200, dt.offset) self.assertTrue(dt.is_dst) + + def test_add_interval(self): + dt = pendulum.create(2017, 3, 11, 10, 45, tz='America/Los_Angeles') + new = dt + pendulum.interval(hours=24) + + self.assertPendulum(new, 2017, 3, 12, 11, 45) From 9b3a086c8da9fc2da54134a9eaaaf487c711b28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 12 Mar 2018 15:53:35 -0500 Subject: [PATCH 14/63] Fix an error when subtracting two pendulum instances in the same timezone --- CHANGELOG.md | 1 + pendulum/helpers.py | 13 ++++++++++--- tests/pendulum_tests/test_add.py | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37d697ea..f617b61e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed an error when adding intervals to a Pendulum instance across DST transition. +- Fixed an error when subtracting two pendulum instances in the same timezone. ## [1.4.2] - 2018-02-22 diff --git a/pendulum/helpers.py b/pendulum/helpers.py index b96245b3..094dea79 100644 --- a/pendulum/helpers.py +++ b/pendulum/helpers.py @@ -159,9 +159,7 @@ def precise_diff(d1, d2): d1, d2 = d2, d1 sign = -1 - y_diff = d2.year - d1.year - m_diff = d2.month - d1.month - d_diff = d2.day - d1.day + d_diff = 0 hour_diff = 0 min_diff = 0 sec_diff = 0 @@ -170,6 +168,7 @@ def precise_diff(d1, d2): _day_number(d2.year, d2.month, d2.day) - _day_number(d1.year, d1.month, d1.day) ) + in_same_tz = False tz1 = None tz2 = None @@ -228,6 +227,14 @@ def precise_diff(d1, d2): hour_diff += 24 d_diff -= 1 + if d1 > d2: + d1, d2 = d2, d1 + sign = -1 + + y_diff = d2.year - d1.year + m_diff = d2.month - d1.month + d_diff += d2.day - d1.day + if d_diff < 0: year = d2.year month = d2.month diff --git a/tests/pendulum_tests/test_add.py b/tests/pendulum_tests/test_add.py index 822fbc02..8b75d40e 100644 --- a/tests/pendulum_tests/test_add.py +++ b/tests/pendulum_tests/test_add.py @@ -237,6 +237,14 @@ def test_add_time_to_new_transition_does_not_use_transition_rule(self): self.assertEqual(7200, dt.offset) self.assertTrue(dt.is_dst) + def test_period_over_midnight_tz(self): + start = pendulum.create(2018, 2, 25, tz='Europe/Paris') + end = start.add(hours=1) + period = end - start + new_end = start + period + + assert new_end == end + def test_add_interval(self): dt = pendulum.create(2017, 3, 11, 10, 45, tz='America/Los_Angeles') new = dt + pendulum.interval(hours=24) From 689a73e4c7e1bd4a261455220fed409a0ce1b3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 16:34:00 -0500 Subject: [PATCH 15/63] Use poetry in Travis --- .travis.yml | 37 ++++++++++++++++++---------- build.py | 60 +++++++++++++++++++++++++++++++++++++++++++++ pendulum/version.py | 2 +- pyproject.toml | 6 +++-- 4 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 build.py diff --git a/.travis.yml b/.travis.yml index 850d370c..a04150b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,32 @@ language: python +python: + - "3.6" + matrix: include: - - python: 2.7 + - env: VENV='2.7' env: PENDULUM_EXTENSIONS=1 - - python: 2.7 + - env: VENV='2.7' env: PENDULUM_EXTENSIONS=0 - - python: 3.4 + - env: VENV='3.4' env: PENDULUM_EXTENSIONS=1 - - python: 3.4 + - env: VENV='3.4' env: PENDULUM_EXTENSIONS=0 - - python: 3.5 + - env: VENV='3.5' env: PENDULUM_EXTENSIONS=1 - - python: 3.5 + - env: VENV='3.5' env: PENDULUM_EXTENSIONS=0 - - python: 3.6 + - env: VENV='' env: PENDULUM_EXTENSIONS=1 - - python: 3.6 + - env: VENV='' env: PENDULUM_EXTENSIONS=0 - - python: pypy - - python: pypy3 + - env: VENV='pypy' + - env: VENV='pypy3' before_install: - pip install codecov + - pip install poetry install: - | @@ -38,10 +42,17 @@ install: virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION" source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - - pip install -r tests-requirements.txt - - python setup.py develop + - | + if [ "$VENV" != "" ]; then + virtualenv --python="$HOME/virtualenv/python$VENV/bin/python" "$HOME/virtualenvs/venv-$VENV" + source "$HOME/virtualenvs/venv-$VENV/bin/activate" + fi + - poetry install -v + - poetry build + - pip --version + - find dist/ -iname pendulum*.tar.gz -exec pip install {} \; -script: py.test --cov=pendulum --cov-config=.coveragerc tests/ +script: pytest --cov=pendulum --cov-config=.coveragerc tests/ after_success: - codecov diff --git a/build.py b/build.py new file mode 100644 index 00000000..cd286d1c --- /dev/null +++ b/build.py @@ -0,0 +1,60 @@ +import os +import sys + + +from distutils.core import Extension + +from distutils.errors import (CCompilerError, DistutilsExecError, + DistutilsPlatformError) +from distutils.command.build_ext import build_ext + + +# C Extensions +with_extensions = os.getenv('PENDULUM_EXTENSIONS', None) + +if with_extensions == '1' or with_extensions is None: + with_extensions = True + +if with_extensions == '0' or hasattr(sys, 'pypy_version_info'): + with_extensions = False + +extensions = [] +if with_extensions: + extensions = [ + Extension('pendulum._extensions._helpers', + ['pendulum/_extensions/_helpers.c']), + ] + + +class BuildFailed(Exception): + + pass + + +class ExtBuilder(build_ext): + # This class allows C extension building to fail. + + def run(self): + try: + build_ext.run(self) + except (DistutilsPlatformError, FileNotFoundError): + raise BuildFailed() + + def build_extension(self, ext): + try: + build_ext.build_extension(self, ext) + except (CCompilerError, DistutilsExecError, + DistutilsPlatformError, ValueError): + raise BuildFailed() + + +def build(setup_kwargs): + """ + This function is mandatory in order to build the extensions. + """ + setup_kwargs.update({ + 'ext_modules': extensions, + 'cmdclass': { + 'build_ext': ExtBuilder + } + }) diff --git a/pendulum/version.py b/pendulum/version.py index abf07abc..133cc7a3 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.2' +VERSION = '1.4.3-beta' diff --git a/pyproject.toml b/pyproject.toml index 80ba49ab..109190d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pendulum" -version = "1.4.2" +version = "1.4.3-beta" description = "Python datetimes made easy." license = "MIT" @@ -16,9 +16,11 @@ repository = "https://github.com/sdispater/pendulum" keywords = ['datetime', 'date', 'time', 'timezone'] +build = "build.py" + [tool.poetry.dependencies] -python = "~2.7 || ^3.4" +python = ">=2.7 || ^3.4" python-dateutil = "^2.6" tzlocal = "^1.5" pytzdata = ">=2018.3" From eb19d0b556d118e9f87060b7fc48cfd967383292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 16:37:20 -0500 Subject: [PATCH 16/63] Update Travis config --- .travis.yml | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index a04150b1..433901d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,22 +5,30 @@ python: matrix: include: - - env: VENV='2.7' - env: PENDULUM_EXTENSIONS=1 - - env: VENV='2.7' - env: PENDULUM_EXTENSIONS=0 - - env: VENV='3.4' - env: PENDULUM_EXTENSIONS=1 - - env: VENV='3.4' - env: PENDULUM_EXTENSIONS=0 - - env: VENV='3.5' - env: PENDULUM_EXTENSIONS=1 - - env: VENV='3.5' - env: PENDULUM_EXTENSIONS=0 - - env: VENV='' - env: PENDULUM_EXTENSIONS=1 - - env: VENV='' - env: PENDULUM_EXTENSIONS=0 + - env: + - VENV='2.7' + - PENDULUM_EXTENSIONS=0 + - env: + - VENV='2.7' + - PENDULUM_EXTENSIONS=1 + - env: + - VENV='3.4' + - PENDULUM_EXTENSIONS=0 + - env: + - VENV='3.4' + - PENDULUM_EXTENSIONS=1 + - env: + - VENV='3.5' + - PENDULUM_EXTENSIONS=0 + - env: + - VENV='3.5' + - PENDULUM_EXTENSIONS=1 + - env: + - VENV='' + - PENDULUM_EXTENSIONS=0 + - env: + - VENV='' + - PENDULUM_EXTENSIONS=1 - env: VENV='pypy' - env: VENV='pypy3' @@ -48,7 +56,7 @@ install: source "$HOME/virtualenvs/venv-$VENV/bin/activate" fi - poetry install -v - - poetry build + - poetry build -v - pip --version - find dist/ -iname pendulum*.tar.gz -exec pip install {} \; From c3319e90a1ad8d5aaab2276252d756ce8cff2861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 16:45:44 -0500 Subject: [PATCH 17/63] Update Travis config --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 433901d3..7cf7046f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,12 +51,12 @@ install: source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - | - if [ "$VENV" != "" ]; then + if [ "$VENV" != "" && "$VENV" != "pypy" ]; then virtualenv --python="$HOME/virtualenv/python$VENV/bin/python" "$HOME/virtualenvs/venv-$VENV" source "$HOME/virtualenvs/venv-$VENV/bin/activate" fi - - poetry install -v - - poetry build -v + - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry install -v + - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry build -v - pip --version - find dist/ -iname pendulum*.tar.gz -exec pip install {} \; From 1cde9a8de10c39a404b6a8eec5e39833eb979442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 16:48:07 -0500 Subject: [PATCH 18/63] Fix Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7cf7046f..d683f8b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ install: source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - | - if [ "$VENV" != "" && "$VENV" != "pypy" ]; then + if ([ "$VENV" != "" ] && [ "$VENV" != "pypy" ]); then virtualenv --python="$HOME/virtualenv/python$VENV/bin/python" "$HOME/virtualenvs/venv-$VENV" source "$HOME/virtualenvs/venv-$VENV/bin/activate" fi From 3b6d5c2d170ad82491cfe4bc24c49c10cd7da64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 16:57:20 -0500 Subject: [PATCH 19/63] Fix Travis config --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d683f8b2..889d5872 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,11 +34,11 @@ matrix: before_install: - pip install codecov - - pip install poetry + - pip install poetry --pre install: - | - if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then + if [ "$VENV" = "pypy" ]; then export PYENV_ROOT="$HOME/.pyenv" if [ -f "$PYENV_ROOT/bin/pyenv" ]; then pushd "$PYENV_ROOT" && git pull && popd From 9baeb91b2a55ed739b8cb8b25fbb87bdc1b04909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:03:30 -0500 Subject: [PATCH 20/63] Update Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 889d5872..5e5a2d3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ install: fi - | if ([ "$VENV" != "" ] && [ "$VENV" != "pypy" ]); then - virtualenv --python="$HOME/virtualenv/python$VENV/bin/python" "$HOME/virtualenvs/venv-$VENV" + virtualenv --python="$(which python$VENV)" "$HOME/virtualenvs/venv-$VENV" source "$HOME/virtualenvs/venv-$VENV/bin/activate" fi - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry install -v From 1675d085481b8efc0393f84e5fd7645d86c54b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:07:31 -0500 Subject: [PATCH 21/63] Debug Travis config --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5e5a2d3c..39f52e8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ matrix: before_install: - pip install codecov - pip install poetry --pre + - echo $(which python$VENV) install: - | @@ -52,7 +53,7 @@ install: fi - | if ([ "$VENV" != "" ] && [ "$VENV" != "pypy" ]); then - virtualenv --python="$(which python$VENV)" "$HOME/virtualenvs/venv-$VENV" + virtualenv --python=$(which python$VENV) "$HOME/virtualenvs/venv-$VENV" source "$HOME/virtualenvs/venv-$VENV/bin/activate" fi - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry install -v From 003717fd8ca05fe8b15e74ba0f48ee5ec51faeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:10:41 -0500 Subject: [PATCH 22/63] Debug Travis config --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39f52e8b..f6d83d73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,9 +33,9 @@ matrix: - env: VENV='pypy3' before_install: + - ls /opt/python/ - pip install codecov - pip install poetry --pre - - echo $(which python$VENV) install: - | @@ -53,7 +53,7 @@ install: fi - | if ([ "$VENV" != "" ] && [ "$VENV" != "pypy" ]); then - virtualenv --python=$(which python$VENV) "$HOME/virtualenvs/venv-$VENV" + virtualenv --python="$HOME/virtualenv/python$VENV/bin/python" "$HOME/virtualenvs/venv-$VENV" source "$HOME/virtualenvs/venv-$VENV/bin/activate" fi - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry install -v From 3ac1885faa0a4d03140b389eff82389afdf4f5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:19:21 -0500 Subject: [PATCH 23/63] Try another strategy for Travis --- .travis.yml | 62 +++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6d83d73..c03ea3d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,45 +1,32 @@ language: python -python: - - "3.6" - matrix: include: - - env: - - VENV='2.7' - - PENDULUM_EXTENSIONS=0 - - env: - - VENV='2.7' - - PENDULUM_EXTENSIONS=1 - - env: - - VENV='3.4' - - PENDULUM_EXTENSIONS=0 - - env: - - VENV='3.4' - - PENDULUM_EXTENSIONS=1 - - env: - - VENV='3.5' - - PENDULUM_EXTENSIONS=0 - - env: - - VENV='3.5' - - PENDULUM_EXTENSIONS=1 - - env: - - VENV='' - - PENDULUM_EXTENSIONS=0 - - env: - - VENV='' - - PENDULUM_EXTENSIONS=1 - - env: VENV='pypy' - - env: VENV='pypy3' + - python: 2.7 + env: PENDULUM_EXTENSIONS=1 + - python: 2.7 + env: PENDULUM_EXTENSIONS=0 + - python: 3.4 + env: PENDULUM_EXTENSIONS=1 + - python: 3.4 + env: PENDULUM_EXTENSIONS=0 + - python: 3.5 + env: PENDULUM_EXTENSIONS=1 + - python: 3.5 + env: PENDULUM_EXTENSIONS=0 + - python: 3.6 + env: PENDULUM_EXTENSIONS=1 + - python: 3.6 + env: PENDULUM_EXTENSIONS=0 + - python: pypy + - python: pypy3 before_install: - - ls /opt/python/ - pip install codecov - - pip install poetry --pre install: - | - if [ "$VENV" = "pypy" ]; then + if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then export PYENV_ROOT="$HOME/.pyenv" if [ -f "$PYENV_ROOT/bin/pyenv" ]; then pushd "$PYENV_ROOT" && git pull && popd @@ -52,13 +39,12 @@ install: source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - | - if ([ "$VENV" != "" ] && [ "$VENV" != "pypy" ]); then - virtualenv --python="$HOME/virtualenv/python$VENV/bin/python" "$HOME/virtualenvs/venv-$VENV" - source "$HOME/virtualenvs/venv-$VENV/bin/activate" + if [ "$TRAVIS_PYTHON_VERSION" != "3.6" ]; then + virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" fi - - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry install -v - - $HOME/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/poetry build -v - - pip --version + - $HOME/virtualenvs/venv-poetry/bin/pip install poetry + - $HOME/virtualenvs/venv-poetry/bin/poetry install -v + - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - find dist/ -iname pendulum*.tar.gz -exec pip install {} \; script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From fb013d2553c84b13311c8c63db809e34853b273d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:21:17 -0500 Subject: [PATCH 24/63] Allow poetry's prereleases in Travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c03ea3d7..ef15f31f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ install: if [ "$TRAVIS_PYTHON_VERSION" != "3.6" ]; then virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" fi - - $HOME/virtualenvs/venv-poetry/bin/pip install poetry + - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - find dist/ -iname pendulum*.tar.gz -exec pip install {} \; From 09a894c834a7efc7a446a6f6c3702780fdf69577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:26:27 -0500 Subject: [PATCH 25/63] Always create poetry's virtualenv in Travis --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef15f31f..88653122 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,10 +38,7 @@ install: virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION" source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - - | - if [ "$TRAVIS_PYTHON_VERSION" != "3.6" ]; then - virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" - fi + - virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v From 1c4b58911a8273b77ab292e4850792a60bbc94ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 17:58:20 -0500 Subject: [PATCH 26/63] Add pytz to dev dependencies --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 109190d3..a02274ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,3 +28,4 @@ pytzdata = ">=2018.3" [tool.poetry.dev-dependencies] pytest = "^3.4" pytest-cov = "^2.4" +pytz = ">=2018.3" From 43f3ee8d295b204dc4c6a40d6e4a40de9ca3433a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 18:08:59 -0500 Subject: [PATCH 27/63] Tweak Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 88653122..90287607 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ install: - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - - find dist/ -iname pendulum*.tar.gz -exec pip install {} \; + - find dist/ -iname pendulum*.tar.gz -exec pip install {} --no-deps --no-binary \; script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From 323009ff2e10d481bc9b78e068b874d226b89952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 19 Mar 2018 18:22:42 -0500 Subject: [PATCH 28/63] Tweak Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 90287607..b60940dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ install: - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - - find dist/ -iname pendulum*.tar.gz -exec pip install {} --no-deps --no-binary \; + - find dist/ -iname pendulum*.tar.gz -exec pip install -e {} --no-deps \; script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From cc7833b9ec1165735a62f3d60f97d489a187e793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 11:12:25 -0500 Subject: [PATCH 29/63] Update Travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b60940dc..957fec6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,7 @@ install: - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - find dist/ -iname pendulum*.tar.gz -exec pip install -e {} --no-deps \; + - python -c "import pendulum; print(pendulum.__file__)" script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From 1e9d51a0b02c79689113528cb390bcc6ee16c2a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 11:28:40 -0500 Subject: [PATCH 30/63] Update Travis config --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 957fec6d..69a1a4c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,10 +40,11 @@ install: fi - virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre - - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - - find dist/ -iname pendulum*.tar.gz -exec pip install -e {} --no-deps \; - - python -c "import pendulum; print(pendulum.__file__)" + - | + if [ "$PENDULUM_EXTENSIONS" == "1" ]; then + find dist/ -iname pendulum*.whl -exec unzip {} 'pendulum/*' -d pendulum/ \; + fi script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From 414974c4789fad1f4a5e40c2ceb0514360f6b6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 11:32:24 -0500 Subject: [PATCH 31/63] Update Travis config --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 69a1a4c6..21d8a0ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,10 +40,11 @@ install: fi - virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre + - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - | if [ "$PENDULUM_EXTENSIONS" == "1" ]; then - find dist/ -iname pendulum*.whl -exec unzip {} 'pendulum/*' -d pendulum/ \; + find dist/ -iname pendulum*.whl -exec unzip {} 'pendulum/*' -d . \; fi script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From 3145664f74ff19c936e538ca589c3a0c4b16081b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 11:35:02 -0500 Subject: [PATCH 32/63] Fix Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 21d8a0ed..d2b9b67c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,7 +44,7 @@ install: - $HOME/virtualenvs/venv-poetry/bin/poetry build -v - | if [ "$PENDULUM_EXTENSIONS" == "1" ]; then - find dist/ -iname pendulum*.whl -exec unzip {} 'pendulum/*' -d . \; + find dist/ -iname pendulum*.whl -exec unzip -o {} 'pendulum/*' -d . \; fi script: pytest --cov=pendulum --cov-config=.coveragerc tests/ From 6a0a72fa12d9401389a1f5297fde6475cdd9e12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 11:47:05 -0500 Subject: [PATCH 33/63] Update appveyor config --- appveyor.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a2bf497a..c5188057 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,6 +8,8 @@ environment: - PYTHON: "C:/Python34-x64" - PYTHON: "C:/Python35" - PYTHON: "C:/Python35-x64" + - PYTHON: "C:/Python36" + - PYTHON: "C:/Python36-x64" install: - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" @@ -16,12 +18,17 @@ install: # about it being out of date. - "pip install --disable-pip-version-check --user --upgrade pip" + # Create poetry virtualenv + - pip install virtualenv + - virtualenv --python="C:/Python36-x64\\Scripts\\python.exe" "venv-poetry" + # Install dependencies - - "%CMD_IN_ENV% pip install -r tests-requirements.txt" - - "%CMD_IN_ENV% pip install codecov" + - pip install codecov + - venv-poetry\\Scripts\\pip.exe install poetry --pre + - venv-poetry\\Scripts\\poetry.exe install -v test_script: - - "py.test --cov=pendulum --cov-config=.coveragerc tests/" + - "pytest --cov=pendulum --cov-config=.coveragerc tests/" after_test: - "codecov" From 02bcc5d6baf5a081c72747e1f2d8c1a023ad1a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 11:54:18 -0500 Subject: [PATCH 34/63] Update appveyor config --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index c5188057..519bd020 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ install: # Create poetry virtualenv - pip install virtualenv - - virtualenv --python="C:/Python36-x64\\Scripts\\python.exe" "venv-poetry" + - virtualenv --python="C:/Python36-x64\\python.exe" "venv-poetry" # Install dependencies - pip install codecov From 02fb22e2b9a09cee0ff39ce05eca81f1cc66d9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 13:57:01 -0500 Subject: [PATCH 35/63] Update appveyor config --- appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 519bd020..431a21f4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,6 +22,10 @@ install: - pip install virtualenv - virtualenv --python="C:/Python36-x64\\python.exe" "venv-poetry" + # Create current python virtualenv + - "virtualenv --python=%PYTHON%\\python.exe venv" + - venv\\Scripts\\activate.bat + # Install dependencies - pip install codecov - venv-poetry\\Scripts\\pip.exe install poetry --pre From 9046f88e0ca2cfc2fe80b7c6be2aef6ad44dca6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 14:02:27 -0500 Subject: [PATCH 36/63] Update appveyor config --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 431a21f4..0faa62dd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,14 +21,15 @@ install: # Create poetry virtualenv - pip install virtualenv - virtualenv --python="C:/Python36-x64\\python.exe" "venv-poetry" + - venv-poetry\\Scripts\\pip.exe install poetry --pre # Create current python virtualenv - "virtualenv --python=%PYTHON%\\python.exe venv" - venv\\Scripts\\activate.bat + - python --version # Install dependencies - pip install codecov - - venv-poetry\\Scripts\\pip.exe install poetry --pre - venv-poetry\\Scripts\\poetry.exe install -v test_script: From 20e1c347e3a5881806131a684d659ff143b935f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 14:13:03 -0500 Subject: [PATCH 37/63] Update appveyor config --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0faa62dd..4215b3e3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,7 +25,7 @@ install: # Create current python virtualenv - "virtualenv --python=%PYTHON%\\python.exe venv" - - venv\\Scripts\\activate.bat + - cmd: call venv\Scripts\activate.bat - python --version # Install dependencies From 75f36dae14f3676fa32c628b1aa5ec0e9387c003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 14:17:44 -0500 Subject: [PATCH 38/63] Update appveyor config --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4215b3e3..47c8a584 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,9 +24,9 @@ install: - venv-poetry\\Scripts\\pip.exe install poetry --pre # Create current python virtualenv - - "virtualenv --python=%PYTHON%\\python.exe venv" - - cmd: call venv\Scripts\activate.bat - - python --version + - python -m virtualenv venv + - venv\Scripts\activate.bat + - "python -c \"import sys; print(sys.executable)\"" # Install dependencies - pip install codecov From 6cce7e3d2c9997f193b60ab7a4aa7371badd124f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 14:28:39 -0500 Subject: [PATCH 39/63] Debug appveyor config --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 47c8a584..933d33e8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,6 +21,7 @@ install: # Create poetry virtualenv - pip install virtualenv - virtualenv --python="C:/Python36-x64\\python.exe" "venv-poetry" + - "python -c \"import sys; print(sys.executable)\"" - venv-poetry\\Scripts\\pip.exe install poetry --pre # Create current python virtualenv From 01a9d12393090e0da176d80c400116f615b6d492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 14:36:02 -0500 Subject: [PATCH 40/63] Debug appveyor config --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 933d33e8..9e041df4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,6 +27,7 @@ install: # Create current python virtualenv - python -m virtualenv venv - venv\Scripts\activate.bat + - "SET VIRTUAL_ENV=venv" - "python -c \"import sys; print(sys.executable)\"" # Install dependencies From a4fca341758205184af60f1965a663faf834df7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 14:46:01 -0500 Subject: [PATCH 41/63] Cleanup appveyor config --- appveyor.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 9e041df4..6ea15971 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,14 +21,12 @@ install: # Create poetry virtualenv - pip install virtualenv - virtualenv --python="C:/Python36-x64\\python.exe" "venv-poetry" - - "python -c \"import sys; print(sys.executable)\"" - venv-poetry\\Scripts\\pip.exe install poetry --pre # Create current python virtualenv - python -m virtualenv venv - venv\Scripts\activate.bat - - "SET VIRTUAL_ENV=venv" - - "python -c \"import sys; print(sys.executable)\"" + - "SET VIRTUAL_ENV=venv" # Seems that activate.bat does not set VIRTUAL_ENV # Install dependencies - pip install codecov From 3c0bdcbabce38e4e809fb9ccc7a12e3210eadead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 16:49:52 -0500 Subject: [PATCH 42/63] Only use poetry for dependency management and packaging --- MANIFEST.in | 2 - Makefile | 6 +- build-wheels.sh | 28 ++++++--- pendulum/version.py | 2 +- pyproject.toml | 2 +- requirements.txt | 3 - setup.cfg | 2 - setup.py | 126 ---------------------------------------- tests-requirements.txt | 4 -- wheels-requirements.txt | 1 - 10 files changed, 27 insertions(+), 149 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 requirements.txt delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 tests-requirements.txt delete mode 100644 wheels-requirements.txt diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 4e978a51..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include README.rst LICENSE -exclude test* diff --git a/Makefile b/Makefile index 35b9c94b..52aca505 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ setup: setup-python test: @py.test --cov=pendulum --cov-config .coveragerc tests/ -sq -release: tar wheels_x64 cp_wheels_x64 wheels_i686 cp_wheels_i686 wheel +release: wheels_x64 cp_wheels_x64 wheels_i686 cp_wheels_i686 wheel publish: @python -m twine upload dist/pendulum-$(PENDULUM_RELEASE)* @@ -32,7 +32,7 @@ tar: python setup.py sdist --formats=gztar wheel: - @pip wheel --no-index --no-deps --wheel-dir dist dist/pendulum-$(PENDULUM_RELEASE).tar.gz + @poetry build -v wheels_x64: clean_wheels build_wheels_x64 @@ -40,11 +40,13 @@ wheels_i686: clean_wheels build_wheels_i686 build_wheels_x64: rm -rf wheelhouse/ + mkdir wheelhouse docker pull quay.io/pypa/manylinux1_x86_64 docker run --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh build_wheels_i686: rm -rf wheelhouse/ + mkdir wheelhouse docker pull quay.io/pypa/manylinux1_i686 docker run --rm -v `pwd`:/io quay.io/pypa/manylinux1_i686 /io/build-wheels.sh diff --git a/build-wheels.sh b/build-wheels.sh index cfc83949..7df85f45 100755 --- a/build-wheels.sh +++ b/build-wheels.sh @@ -1,25 +1,39 @@ #!/bin/bash PYTHON_VERSIONS="cp27-cp27m cp35-cp35m cp36-cp36m" +POETRY_PYTHON="cp36-cp36m" +POETRY_VENV="/opt/python/poetry" +echo "Create Poetry's virtualenv" +/opt/python/${POETRY_PYTHON}/bin/pip install virtualenv +/opt/python/${POETRY_PYTHON}/bin/virtualenv --python /opt/python/${POETRY_PYTHON}/bin/python ${POETRY_VENV} +${POETRY_VENV}/bin/pip install poetry --pre + +RELEASE=$(sed -n "s/VERSION = '\(.*\)'/\1/p" /io/pendulum/version.py) + echo "Compile wheels" for PYTHON in ${PYTHON_VERSIONS}; do cd /io - /opt/python/${PYTHON}/bin/pip install -r wheels-requirements.txt - /opt/python/${PYTHON}/bin/pip install -r tests-requirements.txt - /opt/python/${PYTHON}/bin/python setup.py sdist --dist-dir wheelhouse --formats=gztar - /opt/python/${PYTHON}/bin/pip wheel --no-index --no-deps --wheel-dir wheelhouse wheelhouse/*.tar.gz + /opt/python/${POETRY_PYTHON}/bin/virtualenv --python /opt/python/${PYTHON}/bin/python /opt/python/venv-${PYTHON} + . /opt/python/venv-${PYTHON}/bin/activate + ${POETRY_VENV}/bin/poetry install -v + ${POETRY_VENV}/bin/poetry build -v + mv dist/*-${RELEASE}-*.whl wheelhouse/ + deactivate cd - done echo "Bundle external shared libraries into the wheels" -for whl in /io/wheelhouse/*.whl; do +for whl in /io/wheelhouse/pendulum-${RELEASE}-*.whl; do auditwheel repair $whl -w /io/wheelhouse/ + rm -f $whl done echo "Install packages and test" for PYTHON in ${PYTHON_VERSIONS}; do - /opt/python/${PYTHON}/bin/pip install pendulum --no-index -f /io/wheelhouse + . /opt/python/venv-${PYTHON}/bin/activate + pip install pendulum==${RELEASE} --no-index --find-links /io/wheelhouse find ./io/tests | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf - /opt/python/${PYTHON}/bin/py.test /io/tests + pytest /io/tests find ./io/tests | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf + deactivate done diff --git a/pendulum/version.py b/pendulum/version.py index 133cc7a3..f891c9f0 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.3-beta' +VERSION = '1.4.3b0' diff --git a/pyproject.toml b/pyproject.toml index a02274ae..bc67edca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pendulum" -version = "1.4.3-beta" +version = "1.4.3b0" description = "Python datetimes made easy." license = "MIT" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 2b04c39b..00000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -tzlocal>=1.5.0,<2.0.0 -python-dateutil>=2.6.0,<3.0.0 -pytzdata>=2018.3 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2a9acf13..00000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[bdist_wheel] -universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100644 index a59a0c93..00000000 --- a/setup.py +++ /dev/null @@ -1,126 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import sys -from setuptools import setup, find_packages, Extension -from distutils.errors import (CCompilerError, DistutilsExecError, - DistutilsPlatformError) -from distutils.command.build_ext import build_ext - - -try: - FileNotFoundError -except NameError: - FileNotFoundError = IOError # py2k - - -def get_version(): - basedir = os.path.dirname(__file__) - with open(os.path.join(basedir, 'pendulum/version.py')) as f: - variables = {} - exec(f.read(), variables) - - version = variables.get('VERSION') - if version: - return version - - raise RuntimeError('No version info found.') - - -__version__ = get_version() - -# C Extensions -with_extensions = os.getenv('PENDULUM_EXTENSIONS', None) - -if with_extensions == '1' or with_extensions is None: - with_extensions = True - -if with_extensions == '0' or hasattr(sys, 'pypy_version_info'): - with_extensions = False - -extensions = [] -if with_extensions: - extensions = [ - Extension('pendulum._extensions._helpers', - ['pendulum/_extensions/_helpers.c']), - ] - - -class BuildFailed(Exception): - - pass - - -class ve_build_ext(build_ext): - # This class allows C extension building to fail. - - def run(self): - try: - build_ext.run(self) - except (DistutilsPlatformError, FileNotFoundError): - raise BuildFailed() - - def build_extension(self, ext): - try: - build_ext.build_extension(self, ext) - except (CCompilerError, DistutilsExecError, - DistutilsPlatformError, ValueError): - raise BuildFailed() - - -packages = ['pendulum'] -for pkg in find_packages('pendulum'): - packages.append('pendulum.' + pkg) - -kwargs = dict( - name='pendulum', - license='MIT', - version=__version__, - description='Python datetimes made easy.', - long_description=open('README.rst').read(), - author='Sébastien Eustace', - author_email='sebastien@eustace.io', - url='https://github.com/sdispater/pendulum', - download_url='https://github.com/sdispater/pendulum/archive/%s.tar.gz' % __version__, - packages=packages, - install_requires=[ - 'tzlocal>=1.5.0,<2.0.0', - 'python-dateutil>=2.6.0,<3.0.0', - 'pytzdata>=2018.3', - ], - include_package_data=True, - tests_require=[ - 'pytest>=3.4.0,<4.0.0', - 'pytest-cov>=2.4.0,<3.0.0', - 'pytz>=2018.3', - ], - classifiers=[ - 'Intended Audience :: Developers', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy' - ], -) - -if extensions: - kwargs['ext_modules'] = extensions - kwargs['cmdclass'] = dict(build_ext=ve_build_ext) - - -try: - setup(**kwargs) -except BuildFailed: - print("************************************************************") - print("Cannot compile C accelerator module, use pure python version") - print("************************************************************") - del kwargs['ext_modules'] - del kwargs['cmdclass'] - setup(**kwargs) diff --git a/tests-requirements.txt b/tests-requirements.txt deleted file mode 100644 index 5b9891f1..00000000 --- a/tests-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ --r requirements.txt -pytest>=3.4.0,<4.0.0 -pytest-cov>=2.4.0,<3.0.0 -pytz>=2018.3 diff --git a/wheels-requirements.txt b/wheels-requirements.txt deleted file mode 100644 index e079f8a6..00000000 --- a/wheels-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pytest From 11ac856f943dffb980493edf585ac04b686afcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 18:26:53 -0500 Subject: [PATCH 43/63] Bump version to 1.4.3 --- CHANGELOG.md | 5 +++-- pendulum/version.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f617b61e..b1e63971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.4.3] - 2018-03-20 ### Fixed @@ -466,7 +466,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.2...1.x +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.3...1.x +[1.4.3]: https://github.com/sdispater/pendulum/releases/tag/1.4.3 [1.4.2]: https://github.com/sdispater/pendulum/releases/tag/1.4.2 [1.4.1]: https://github.com/sdispater/pendulum/releases/tag/1.4.1 [1.4.0]: https://github.com/sdispater/pendulum/releases/tag/1.4.0 diff --git a/pendulum/version.py b/pendulum/version.py index f891c9f0..aaa8257c 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.3b0' +VERSION = '1.4.3' diff --git a/pyproject.toml b/pyproject.toml index bc67edca..6882b2d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pendulum" -version = "1.4.3b0" +version = "1.4.3" description = "Python datetimes made easy." license = "MIT" @@ -20,7 +20,7 @@ build = "build.py" [tool.poetry.dependencies] -python = ">=2.7 || ^3.4" +python = "~2.7 || ^3.4" python-dateutil = "^2.6" tzlocal = "^1.5" pytzdata = ">=2018.3" From 0054e7464fbfb82bfb34317b4bf2ccd67f04af3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 20 Mar 2018 18:57:43 -0500 Subject: [PATCH 44/63] Change wheels building process --- Makefile | 4 ++-- build-wheels.sh | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 52aca505..136f3d1b 100644 --- a/Makefile +++ b/Makefile @@ -54,10 +54,10 @@ clean_wheels: rm -rf wheelhouse/ cp_wheels_x64: - cp wheelhouse/*manylinux1_x86_64.whl dist/ + mv wheelhouse/*manylinux1_x86_64.whl dist/ cp_wheels_i686: - cp wheelhouse/*manylinux1_i686.whl dist/ + mv wheelhouse/*manylinux1_i686.whl dist/ upload_wheels_x64: @for f in wheelhouse/*manylinux1_x86_64.whl ; do \ diff --git a/build-wheels.sh b/build-wheels.sh index 7df85f45..18ff4b88 100755 --- a/build-wheels.sh +++ b/build-wheels.sh @@ -17,15 +17,14 @@ for PYTHON in ${PYTHON_VERSIONS}; do . /opt/python/venv-${PYTHON}/bin/activate ${POETRY_VENV}/bin/poetry install -v ${POETRY_VENV}/bin/poetry build -v - mv dist/*-${RELEASE}-*.whl wheelhouse/ + mv dist/*-${RELEASE}-*-linux_*.whl wheelhouse/ deactivate cd - done echo "Bundle external shared libraries into the wheels" -for whl in /io/wheelhouse/pendulum-${RELEASE}-*.whl; do - auditwheel repair $whl -w /io/wheelhouse/ - rm -f $whl +for whl in /io/wheelhouse/pendulum-${RELEASE}-*-linux_*.whl; do + auditwheel repair "$whl" -w /io/wheelhouse/ done echo "Install packages and test" From fd7430cf879b39a6eb6c381afd5f1e059f2e9385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 21 Mar 2018 01:36:54 -0500 Subject: [PATCH 45/63] Fix extension building script --- CHANGELOG.md | 7 +++++++ build.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1e63971..2089b4fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [Unreleased] + +### Fixed + +- Fixed extension building script. + + ## [1.4.3] - 2018-03-20 ### Fixed diff --git a/build.py b/build.py index cd286d1c..852a7acc 100644 --- a/build.py +++ b/build.py @@ -38,14 +38,14 @@ def run(self): try: build_ext.run(self) except (DistutilsPlatformError, FileNotFoundError): - raise BuildFailed() + pass def build_extension(self, ext): try: build_ext.build_extension(self, ext) except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError): - raise BuildFailed() + pass def build(setup_kwargs): From 55011d302b80c60360e2cc9f3a5ace7336c727c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 21 Mar 2018 01:47:06 -0500 Subject: [PATCH 46/63] Bump version to 1.4.4 --- pendulum/version.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pendulum/version.py b/pendulum/version.py index aaa8257c..360b89fb 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.3' +VERSION = '1.4.4' diff --git a/pyproject.toml b/pyproject.toml index 6882b2d6..c8fe9597 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pendulum" -version = "1.4.3" +version = "1.4.4" description = "Python datetimes made easy." license = "MIT" From c206fc248377e8440566c32ce639077738a035f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 21 Mar 2018 02:03:15 -0500 Subject: [PATCH 47/63] Update CHANGELOG --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2089b4fc..8f19529e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.4.4] - 2018-03-21 ### Fixed @@ -473,7 +473,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.3...1.x +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.4...1.x +[1.4.4]: https://github.com/sdispater/pendulum/releases/tag/1.4.4 [1.4.3]: https://github.com/sdispater/pendulum/releases/tag/1.4.3 [1.4.2]: https://github.com/sdispater/pendulum/releases/tag/1.4.2 [1.4.1]: https://github.com/sdispater/pendulum/releases/tag/1.4.1 From 894d0028b565788fa64a4d0452dc36b943854f26 Mon Sep 17 00:00:00 2001 From: Andriy Orehov Date: Wed, 4 Apr 2018 23:51:44 +0300 Subject: [PATCH 48/63] fix mismatch import in the documentation (#176) --- docs/_docs/comparison.rst | 4 ++-- docs/_docs/difference.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/_docs/comparison.rst b/docs/_docs/comparison.rst index 10369bbb..a6f1a7ea 100644 --- a/docs/_docs/comparison.rst +++ b/docs/_docs/comparison.rst @@ -102,7 +102,7 @@ the ``now()`` is created in the same timezone as the instance. import pendulum - dt = Pendulum.now() + dt = pendulum.now() dt.is_weekday() dt.is_weekend() @@ -112,7 +112,7 @@ the ``now()`` is created in the same timezone as the instance. dt.is_future() dt.is_past() dt.is_leap_year() - dt.is_same_day(Pendulum.now()) + dt.is_same_day(pendulum.now()) born = pendulum.create(1987, 4, 23) not_birthday = pendulum.create(2014, 9, 26) diff --git a/docs/_docs/difference.rst b/docs/_docs/difference.rst index 53c85706..13bdb7de 100644 --- a/docs/_docs/difference.rst +++ b/docs/_docs/difference.rst @@ -86,7 +86,7 @@ You may also pass ``True`` as a 2nd parameter to remove the modifiers `ago`, `fr pendulum.now().subtract(days=1).diff_for_humans() '5 days ago' - pendulum.now().diff_for_humans(Pendulum.now().subtract(years=1)) + pendulum.now().diff_for_humans(pendulum.now().subtract(years=1)) '1 year after' dt = pendulum.create(2011, 8, 1) From 58ffabdaa984571483d68fc62a9adaad93863718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Wed, 4 Apr 2018 17:04:20 -0500 Subject: [PATCH 49/63] Add deprecation warnings for methods that will no longer be supported in pendulum 2.0 --- CHANGELOG.md | 20 +++ docs/_docs/addition_subtraction.rst | 2 +- docs/_docs/attributes_properties.rst | 6 +- docs/_docs/comparison.rst | 24 ++-- docs/_docs/difference.rst | 12 +- docs/_docs/fluent_helpers.rst | 10 +- docs/_docs/instantiation.rst | 36 ++---- docs/_docs/interval.rst | 9 +- docs/_docs/introduction.rst | 4 +- docs/_docs/localization.rst | 9 +- docs/_docs/modifiers.rst | 38 +++--- docs/_docs/period.rst | 57 ++++---- docs/_docs/string_formatting.rst | 6 +- docs/_docs/testing.rst | 4 +- docs/_docs/timezones.rst | 30 ++--- pendulum/__init__.py | 17 ++- pendulum/date.py | 155 +++++++++++++++++++++- pendulum/mixins/default.py | 14 ++ pendulum/pendulum.py | 186 ++++++++++++++++++++++++++- pendulum/period.py | 14 ++ pendulum/time.py | 32 +++++ pyproject.toml | 1 + tests/test_helpers.py | 25 +++- 23 files changed, 560 insertions(+), 151 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f19529e..a3e950d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Change Log +## [Unreleased] + +### Added + +- Added the `set()` method to set properties. +- Added the `is_utc()` and `is_local()` methods. + +### Deprecated + +- `year_()`, `month_()`, `day_`, `hour_`, `minute_`, `second_`, `microsecond_()` are now deprecated. +- `timezone_()` and `tz_()` are now deprecated. +- `timestamp_()` is now deprecated. +- `with_date_time()`, `with_time_from_string()` and `with_timestamp()` are now deprecated. +- `between()` is now deprecated. +- `min_()`, `max_()`, `minimum()`, `maximum()` are now deprecated. +- `is_today()`, `is_yesterday()`, `is_tomorrow()` and `is_same_day()` are now depecreated. +- `is_sunday()` -> `is_saturday()` are now deprecated. +- The `utc` and `local` properties are now deprecated. Use `is_utc()` and `is_local()` instead. + + ## [1.4.4] - 2018-03-21 ### Fixed diff --git a/docs/_docs/addition_subtraction.rst b/docs/_docs/addition_subtraction.rst index df32ddad..37b3f6da 100644 --- a/docs/_docs/addition_subtraction.rst +++ b/docs/_docs/addition_subtraction.rst @@ -9,7 +9,7 @@ Each method returns a new ``Pendulum`` instance. import pendulum - dt = pendulum.create(2012, 1, 31, 0) + dt = pendulum.datetime(2012, 1, 31, 0) dt.to_datetime_string() '2012-01-31 00:00:00' diff --git a/docs/_docs/attributes_properties.rst b/docs/_docs/attributes_properties.rst index 0fb48cfd..b030d669 100644 --- a/docs/_docs/attributes_properties.rst +++ b/docs/_docs/attributes_properties.rst @@ -41,7 +41,7 @@ Pendulum gives access to more attributes and properties than the default ``datet dt.int_timestamp 1346887571 - pendulum.create(1975, 5, 21).age + pendulum.datetime(1975, 5, 21).age 41 # calculated vs now in the same tz dt.quarter 3 @@ -59,9 +59,9 @@ Pendulum gives access to more attributes and properties than the default ``datet 9.5 # Indicates if day light savings time is on - pendulum.create(2012, 1, 1, tz='America/Toronto').is_dst + pendulum.datetime(2012, 1, 1, tz='America/Toronto').is_dst False - pendulum.create(2012, 9, 1, tz='America/Toronto').is_dst + pendulum.datetime(2012, 9, 1, tz='America/Toronto').is_dst True # Indicates if the instance is in the same timezone as the local timezone diff --git a/docs/_docs/comparison.rst b/docs/_docs/comparison.rst index a6f1a7ea..7edfb696 100644 --- a/docs/_docs/comparison.rst +++ b/docs/_docs/comparison.rst @@ -8,8 +8,8 @@ Remember that the comparison is done in the UTC timezone so things aren't always import pendulum - first = pendulum.create(2012, 9, 5, 23, 26, 11, 0, tz='America/Toronto') - second = pendulum.create(2012, 9, 5, 20, 26, 11, 0, tz='America/Vancouver') + first = pendulum.datetime(2012, 9, 5, 23, 26, 11, tz='America/Toronto') + second = pendulum.datetime(2012, 9, 5, 20, 26, 11, tz='America/Vancouver') first.to_datetime_string() '2012-09-05 23:26:11' @@ -58,14 +58,14 @@ The default is ``True`` which determines if its between or equal to the boundari import pendulum - first = pendulum.create(2012, 9, 5, 1) - second = pendulum.create(2012, 9, 5, 5) + first = pendulum.datetime(2012, 9, 5, 1) + second = pendulum.datetime(2012, 9, 5, 5) - pendulum.create(2012, 9, 5, 3).between(first, second) + pendulum.datetime(2012, 9, 5, 3).between(first, second) True - pendulum.create(2012, 9, 5, 3).between(first, second) + pendulum.datetime(2012, 9, 5, 3).between(first, second) True - pendulum.create(2012, 9, 5, 5).between(first, second, False) + pendulum.datetime(2012, 9, 5, 5).between(first, second, False) False There are also the ``min_()`` and ``max_()`` methods. @@ -75,8 +75,8 @@ As usual the default parameter is ``now`` if ``None`` is specified. import pendulum - dt1 = pendulum.create(2012, 1, 1, 0, 0, 0, 0) - dt2 = pendulum.create(2014, 1, 30, 0, 0, 0, 0) + dt1 = pendulum.datetime(2012, 1, 1, 0, 0, 0, 0) + dt2 = pendulum.datetime(2014, 1, 30, 0, 0, 0, 0) print(dt1.min_(dt2)) '2012-01-01T00:00:00+00:00' @@ -104,15 +104,9 @@ the ``now()`` is created in the same timezone as the instance. dt = pendulum.now() - dt.is_weekday() - dt.is_weekend() - dt.is_yesterday() - dt.is_today() - dt.is_tomorrow() dt.is_future() dt.is_past() dt.is_leap_year() - dt.is_same_day(pendulum.now()) born = pendulum.create(1987, 4, 23) not_birthday = pendulum.create(2014, 9, 26) diff --git a/docs/_docs/difference.rst b/docs/_docs/difference.rst index 13bdb7de..81c6bdc8 100644 --- a/docs/_docs/difference.rst +++ b/docs/_docs/difference.rst @@ -17,8 +17,8 @@ This will default to ``True``, return the absolute value. The comparisons are do import pendulum - dt_ottawa = pendulum.create(2000, 1, 1, tz='America/Toronto') - dt_vancouver = pendulum.create(2000, 1, 1, tz='America/Vancouver') + dt_ottawa = pendulum.datetime(2000, 1, 1, tz='America/Toronto') + dt_vancouver = pendulum.datetime(2000, 1, 1, tz='America/Vancouver') dt_ottawa.diff(dt_vancouver).in_hours() 3 @@ -27,19 +27,19 @@ This will default to ``True``, return the absolute value. The comparisons are do dt_vancouver.diff(dt_ottawa, False).in_hours() -3 - dt = pendulum.create(2012, 1, 31, 0) + dt = pendulum.datetime(2012, 1, 31, 0) dt.diff(dt.add(months=1)).in_days() 29 dt.diff(dt.subtract(months=1), False).in_days() -31 - dt = pendulum.create(2012, 4, 30, 0) + dt = pendulum.datetime(2012, 4, 30, 0) dt.diff(dt.add(months=1)).in_days() 30 dt.diff(dt.add(weeks=1)).in_days() 7 - dt = pendulum.create(2012, 1, 1, 0) + dt = pendulum.datetime(2012, 1, 1, 0) dt.diff(dt.add(seconds=59)).in_minutes() 0 dt.diff(dt.add(seconds=60)).in_minutes() @@ -89,7 +89,7 @@ You may also pass ``True`` as a 2nd parameter to remove the modifiers `ago`, `fr pendulum.now().diff_for_humans(pendulum.now().subtract(years=1)) '1 year after' - dt = pendulum.create(2011, 8, 1) + dt = pendulum.datetime(2011, 8, 1) dt.diff_for_humans(dt.add(months=1)) '1 month before' dt.diff_for_humans(dt.subtract(months=1)) diff --git a/docs/_docs/fluent_helpers.rst b/docs/_docs/fluent_helpers.rst index 7f42a9f4..dd96d200 100644 --- a/docs/_docs/fluent_helpers.rst +++ b/docs/_docs/fluent_helpers.rst @@ -14,21 +14,21 @@ setting the timestamp will not set the corresponding timezone to UTC. dt = pendulum.now() - dt = dt.year_(1975).month_(5).day_(21).to_datetime_string() + dt = dt.set(year=1975, month=5, day=21).to_datetime_string() '1975-05-21 13:45:18' - dt.hour_(22).minute_(32).second_(5).to_datetime_string() + dt.set(hour=22, minute=32, second=5).to_datetime_string() '2016-11-16 22:32:05' dt.on(1975, 5, 21).at(22, 32, 5).to_datetime_string() '1975-05-21 22:32:05' - dt.timestamp_(169957925).timezone_('Europe/London') + dt.set(tz='Europe/London') - dt.tz_('America/Toronto').in_timezone('America/Vancouver') + dt.set(tz='America/Toronto').in_timezone('America/Vancouver') .. note:: - ``timezone_()`` and ``tz_()`` just modify the timezone information without + ``set(tz=...)`` just modify the timezone information without making any conversion while ``in_timezone()`` converts the time in the appropriate timezone. diff --git a/docs/_docs/instantiation.rst b/docs/_docs/instantiation.rst index 36af5bc2..cf1e84a1 100644 --- a/docs/_docs/instantiation.rst +++ b/docs/_docs/instantiation.rst @@ -2,22 +2,19 @@ Instantiation ============= There are several different methods available to create a new instance of Pendulum. -First there is a constructor. It accepts the same parameters as the standard class. +First there is a the `datetime()` helper. .. code-block:: python - from pendulum import Pendulum + import pendulum - dt = Pendulum(2015, 2, 5, tzinfo='America/Vancouver') + dt = pendulum.datetime(2015, 2, 5, tz='America/Vancouver') isinstance(dt, datetime) True - dt = Pendulum.now(-5) - -You'll notice above that the timezone (2nd) parameter was passed as a string and an integer -rather than a ``tzinfo`` instance. All timezone parameters have been augmented -so you can pass a ``tzinfo`` instance, string or integer offset to GMT -and the timezone will be created for you. +`datetime()` sets the time to `00:00:00` if it's not specified, +and the timezone (the `tz` keyword argument) to `UTC`. +It otherwise can be a `Timezone` instance or simply a string timezone value. .. note:: @@ -44,7 +41,7 @@ and the timezone will be created for you. 'US/Pacific-New', 'US/Samoa') -This is again shown in the next example which also introduces the ``now()`` function. +There is also the ``now()`` helper. .. code-block:: python @@ -87,7 +84,7 @@ besides behaving as expected, all accept a timezone parameter and each has their print(yesterday) '2016-06-27T00:00:00-05:00' -The next helper is ``create()`` which allows you to provide +The next helper is ``datetime()`` which allows you to provide as many or as few arguments as you want and will provide default values for all others. .. code-block:: python @@ -129,7 +126,7 @@ The difference being the addition the ``tz`` argument that can be a ``tzinfo`` i Note that it will be the only one supported in the next major version. -The final ``create`` function is for working with unix timestamps. +The final helper is for working with unix timestamps. ``from_timestamp()`` will create a ``Pendulum`` instance equal to the given timestamp and will set the timezone as well or default it to ``UTC``. @@ -141,21 +138,6 @@ and will set the timezone as well or default it to ``UTC``. pendulum.from_timestamp(-1, 'Europe/London').to_datetime_string() '1970-01-01 00:59:59' - # Using the standard fromtimestamp is also possible - pendulum.fromtimestamp(-1).to_datetime_string() - '1969-12-31 23:59:59' - -You can also create a ``copy()`` of an existing ``Pendulum`` instance. -As expected the date, time and timezone values are all copied to the new instance. - -.. code-block:: python - - dt = pendulum.now() - print(dt.diff(dt.copy().add(years=1)).in_years()) - 1 - - # dt was unchanged and still holds the value of pendulum.now() - Finally, if you find yourself inheriting a ``datetime`` instance, you can create a ``Pendulum`` instance via the ``instance()`` function. diff --git a/docs/_docs/interval.rst b/docs/_docs/interval.rst index 54fbbe9f..7b31aa02 100644 --- a/docs/_docs/interval.rst +++ b/docs/_docs/interval.rst @@ -12,6 +12,8 @@ It has many improvements over the base class. .. code-block:: python + import pendulum + d1 = datetime(2012, 1, 1, 1, 2, 3, tzinfo=pytz.UTC) d2 = datetime(2011, 12, 31, 22, 2, 3, tzinfo=pytz.UTC) delta = d2 - d1 @@ -20,8 +22,8 @@ It has many improvements over the base class. delta.seconds 75600 - d1 = Pendulum(2012, 1, 1, 1, 2, 3) - d2 = Pendulum(2011, 12, 31, 22, 2, 3) + d1 = pendulum.datetime(2012, 1, 1, 1, 2, 3) + d2 = pendulum.datetime(2011, 12, 31, 22, 2, 3) delta = d2 - d1 delta.days 0 @@ -37,7 +39,6 @@ You can create an instance in the following ways: import pendulum - it = pendulum.Interval(days=1177, seconds=7284, microseconds=1234) it = pendulum.interval(days=1177, seconds=7284, microseconds=1234) # You can use an existing timedelta instance @@ -63,7 +64,7 @@ The ``Interval`` class brings more properties than the default ``days``, ``secon 1117 # If you want the remaining days not included in full weeks - it.remaning_days + it.remaining_days 1 # The remaining number in each unit diff --git a/docs/_docs/introduction.rst b/docs/_docs/introduction.rst index 3002c438..3deb2a34 100644 --- a/docs/_docs/introduction.rst +++ b/docs/_docs/introduction.rst @@ -16,8 +16,8 @@ For example all comparisons are done in UTC or in the timezone of the datetime b import pendulum - dt_toronto = pendulum.create(2012, 1, 1, tz='America/Toronto') - dt_vancouver = pendulum.create(2012, 1, 1, tz='America/Vancouver') + dt_toronto = pendulum.datetime(2012, 1, 1, tz='America/Toronto') + dt_vancouver = pendulum.datetime(2012, 1, 1, tz='America/Vancouver') print(dt_vancouver.diff(dt_toronto).in_hours()) 3 diff --git a/docs/_docs/localization.rst b/docs/_docs/localization.rst index 20fc434e..a87ade9d 100644 --- a/docs/_docs/localization.rst +++ b/docs/_docs/localization.rst @@ -5,9 +5,9 @@ Localization occurs when using the ``format()`` method which accepts a ``locale` .. code-block:: python - from pendulum import Pendulum + import pendulum - dt = Pendulum(1975, 5, 21) + dt = pendulum.datetime(1975, 5, 21) dt.format('%A %d %B %Y', locale='de') 'Mittwoch 21 Mai 1975' @@ -22,9 +22,10 @@ Localization occurs when using the ``format()`` method which accepts a ``locale` .. code-block:: python import locale - from pendulum import Pendulum - dt = Pendulum(1975, 5, 21) + import pendulum + + dt = pendulum.datetime(1975, 5, 21) locale.setlocale(locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')) dt.format('%A %d %B %Y') diff --git a/docs/_docs/modifiers.rst b/docs/_docs/modifiers.rst index 87df0388..69f55628 100644 --- a/docs/_docs/modifiers.rst +++ b/docs/_docs/modifiers.rst @@ -12,90 +12,90 @@ It moves your instance to the middle date between itself and the provided Pendul import pendulum - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.start_of('day') '2012-01-31 00:00:00' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('day') '2012-01-31 23:59:59' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.start_of('month') '2012-01-01 00:00:00' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('month') '2012-01-31 23:59:59' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.start_of('year') '2012-01-01 00:00:00' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('year') '2012-01-31 23:59:59' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.start_of('decade') '2010-01-01 00:00:00' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('decade') '2019-01-31 23:59:59' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.start_of('century') '2000-01-01 00:00:00' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('century') '2099-12-31 23:59:59' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.start_of('week') '2012-01-30 00:00:00' dt.day_of_week == pendulum.MONDAY True # ISO8601 week starts on Monday - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('week') '2012-02-05 23:59:59' dt.day_of_week == pendulum.SUNDAY True # ISO8601 week ends on SUNDAY - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.end_of('week') '2012-02-05 23:59:59' dt.day_of_week == pendulum.SUNDAY True # ISO8601 week ends on SUNDAY - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.next(pendulum.WEDNESDAY) '2012-02-01 00:00:00' dt.day_of_week == pendulum.WEDNESDAY True - dt = pendulum.create(2012, 1, 1, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 1, 12, 0, 0) dt.next() '2012-01-08 00:00:00' dt.next(keep_time=True) '2012-01-08T12:00:00+00:00' - dt = pendulum.create(2012, 1, 31, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 31, 12, 0, 0) dt.previous(pendulum.WEDNESDAY) '2012-01-25 00:00:00' dt.day_of_week == pendulum.WEDNESDAY True - dt = pendulum.create(2012, 1, 1, 12, 0, 0) + dt = pendulum.datetime(2012, 1, 1, 12, 0, 0) dt.previous() '2011-12-25 00:00:00' dt.previous(keep_time=True) '2011-12-25 12:00:00' - start = pendulum.create(2014, 1, 1, 0, 0, 0) - end = pendulum.create(2014, 1, 30, 0, 0, 0) + start = pendulum.datetime(2014, 1, 1, 0, 0, 0) + end = pendulum.datetime(2014, 1, 30, 0, 0, 0) start.average(end) '2014-01-15 12:00:00' diff --git a/docs/_docs/period.rst b/docs/_docs/period.rst index bbe60fb8..63c47779 100644 --- a/docs/_docs/period.rst +++ b/docs/_docs/period.rst @@ -7,22 +7,17 @@ instances that generated it, so that it can give access to more methods and prop .. code-block:: python - from pendulum import Pendulum + import pendulum - start = Pendulum(2000, 1, 1) - end = Pendulum(2000, 1, 31) + start = pendulum.datetime(2000, 1, 1) + end = pendulum.datetime(2000, 1, 31) period = end - start - period.in_weekdays() - 21 - - period.in_weekend_days() - 10 - # You also have access to the years and months + # You have access to the years and months # properties and there related methods - start = Pendulum(2000, 11, 20) - end = Pendulum(2016, 11, 5) + start = pendulum.datetime(2000, 11, 20) + end = pendulum.datetime(2016, 11, 5) period = end - start @@ -53,7 +48,7 @@ transitions that might have occurred and adjust accordingly. Let's take an examp import pendulum - start = pendulum.create(2017, 3, 7, tz='America/Toronto') + start = pendulum.datetime(2017, 3, 7, tz='America/Toronto') end = start.add(days=6) period = end - start @@ -80,9 +75,11 @@ transitions that might have occurred and adjust accordingly. Let's take an examp .. code-block:: python - dt1 = Pendulum(2016, 8, 7, 12, 34, 56) + import pendulum + + dt1 = pendulum.datetime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=6, seconds=34) - period = Period(dt1, dt2) + period = pendulum.period(dt1, dt2) period * 2 # @@ -96,22 +93,19 @@ You can create an instance in the following ways: import pendulum - start = pendulum.Pendulum(2000, 1, 1) - end = pendulum.Pendulum(2000, 1, 31) + start = pendulum.datetime(2000, 1, 1) + end = pendulum.datetime(2000, 1, 31) - period = pendulum.Period(start, end) period = pendulum.period(start, end) + period = end - start You can also make an inverted period: .. code-block:: python period = pendulum.period(end, start) - period.in_weekdays() - -21 - - period.in_weekend_days() - -10 + period.days + -30 If you have inverted dates but want to make sure that the period is positive, you set the ``absolute`` keyword argument to ``True``: @@ -119,11 +113,8 @@ you set the ``absolute`` keyword argument to ``True``: .. code-block:: python period = pendulum.period(end, start, absolute=True) - period.in_weekdays() - 21 - - period.in_weekend_days() - 10 + period.days + 30 Range ----- @@ -134,8 +125,8 @@ If you want to iterate over a period, you can use the ``range()`` method: import pendulum - start = pendulum.Pendulum(2000, 1, 1) - end = pendulum.Pendulum(2000, 1, 10) + start = pendulum.datetime(2000, 1, 1) + end = pendulum.datetime(2000, 1, 10) period = pendulum.period(start, end) @@ -186,7 +177,7 @@ You can check if a ``Pendulum`` instance is inside a period using the ``in`` key .. code-block:: python - dt = Pendulum(2000, 1, 4) + dt = pendulum.datetime(2000, 1, 4) dt in period True @@ -202,12 +193,12 @@ using the ``intersect()`` method. import pendulum - monday = pendulum.create(2016, 9, 12) + monday = pendulum.datetime(2016, 9, 12) wednesday = monday.next(pendulum.WEDNESDAY) friday = monday.next(pendulum.FRIDAY) saturday = monday.next(pendulum.SATURDAY) - period = pendulum.period(monday, friday) + period = pendulum.datetime(monday, friday) period.intersect(pendulum.period(wednesday, saturday)) # 2016-09-16T00:00:00+00:00]> @@ -219,7 +210,7 @@ You can also pass multiple period to ``intersect()``. import pendulum - monday = pendulum.create(2016, 9, 12) + monday = pendulum.datetime(2016, 9, 12) wednesday = monday.next(pendulum.WEDNESDAY) thursday = monday.next(pendulum.THURSDAY) friday = monday.next(pendulum.FRIDAY) diff --git a/docs/_docs/string_formatting.rst b/docs/_docs/string_formatting.rst index f30e3ba8..496ed1d3 100644 --- a/docs/_docs/string_formatting.rst +++ b/docs/_docs/string_formatting.rst @@ -9,9 +9,9 @@ The default string representation is the same as the one returned by the ``isofo .. code-block:: python - from pendulum import Pendulum + import pendulum - dt = Pendulum(1975, 12, 25, 14, 15, 16) + dt = pendulum.datetime(1975, 12, 25, 14, 15, 16) print(dt) '1975-12-25T14:15:16+00:00' @@ -133,7 +133,7 @@ or globally by using ``pendulum.set_formatter()``. import pendulum - dt = pendulum.Pendulum(1975, 12, 25, 14, 15, 16) + dt = pendulum.datetime(1975, 12, 25, 14, 15, 16) dt.format('YYYY-MM-DD HH:mm:ss', formatter='alternative') '1975-12-25 14:15:16' diff --git a/docs/_docs/testing.rst b/docs/_docs/testing.rst index fb435b49..5e7323ca 100644 --- a/docs/_docs/testing.rst +++ b/docs/_docs/testing.rst @@ -13,7 +13,7 @@ The provided instance will be returned specifically under the following conditio import pendulum # Create testing datetime - known = pendulum.create(2001, 5, 21, 12) + known = pendulum.datetime(2001, 5, 21, 12) # Set the mock pendulum.set_test_now(known) @@ -50,7 +50,7 @@ you can use the provided ``test()`` contextmanager. import pendulum - known = pendulum.create(2001, 5, 21, 12) + known = pendulum.datetime(2001, 5, 21, 12) with pendulum.test(known): print(pendulum.now()) diff --git a/docs/_docs/timezones.rst b/docs/_docs/timezones.rst index b17d19dc..9e048727 100644 --- a/docs/_docs/timezones.rst +++ b/docs/_docs/timezones.rst @@ -21,12 +21,12 @@ given timezone to properly handle any transition that might have occurred. import pendulum - pendulum.create(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris') + pendulum.datetime(2013, 3, 31, 2, 30, 'Europe/Paris') # 2:30 for the 31th of March 2013 does not exist # so pendulum will return the actual time which is 3:30+02:00 '2013-03-31T03:30:00+02:00' - pendulum.create(2013, 10, 27, 2, 30, 0, 0, 'Europe/Paris') + pendulum.datetime(2013, 10, 27, 2, 30, 'Europe/Paris') # Here, 2:30 exists twice in the day so pendulum will # assume that the transition already occurred '2013-10-27T02:30:00+01:00' @@ -42,16 +42,16 @@ given timezone to properly handle any transition that might have occurred. pendulum.set_transition_rule(pendulum.PRE_TRANSITION) - pendulum.create(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris') + pendulum.datetime(2013, 3, 31, 2, 30, 'Europe/Paris') '2013-03-31T01:30:00+01:00' - pendulum.create(2013, 10, 27, 2, 30, 0, 0, 'Europe/Paris') + pendulum.datetime(2013, 10, 27, 2, 30, 'Europe/Paris') '2013-10-27T02:30:00+02:00' pendulum.set_transition_rule(pendulum.TRANSITION_ERROR) - pendulum.create(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris') + pendulum.datetime(2013, 3, 31, 2, 30, 'Europe/Paris') # NonExistingTime: The datetime 2013-03-31 02:30:00 does not exist - pendulum.create(2013, 10, 27, 2, 30, 0, 0, 'Europe/Paris') + pendulum.datetime(2013, 10, 27, 2, 30, 'Europe/Paris') # AmbiguousTime: The datetime 2013-10-27 02:30:00 is ambiguous. Note that it only affects instances at creation time. Shifting time around @@ -69,23 +69,23 @@ given timezone to properly handle any transition that might have occurred. from pendulum import Pendulum - dt = Pendulum(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris') + dt = Pendulum(2013, 3, 31, 2, 30, 'Europe/Paris') dt.isoformat() '2013-03-31T03:30:00+02:00' - dt = Pendulum(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris', fold=0) + dt = Pendulum(2013, 3, 31, 2, 30, 'Europe/Paris', fold=0) dt.isoformat() '2013-03-31T01:30:00+01:00' - dt = Pendulum(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris', fold=1) + dt = Pendulum(2013, 3, 31, 2, 30, 'Europe/Paris', fold=1) dt.isoformat() '2013-03-31T03:30:00+02:00' - dt = Pendulum(2013, 10, 27, 2, 30, 0, 0, 'Europe/Paris', fold=0) + dt = Pendulum(2013, 10, 27, 2, 30, 'Europe/Paris', fold=0) dt.isoformat() '2013-10-27T02:30:00+02:00' - dt = Pendulum(2013, 10, 27, 2, 30, 0, 0, 'Europe/Paris', fold=1) + dt = Pendulum(2013, 10, 27, 2, 30, 'Europe/Paris', fold=1) dt.isoformat() '2013-10-27T02:30:00+01:00' @@ -101,17 +101,17 @@ adopt the proper behavior and apply the transition accordingly. import pendulum - dt = pendulum.create(2013, 3, 31, 1, 59, 59, 999999, 'Europe/Paris') + dt = pendulum.datetime(2013, 3, 31, 1, 59, 59, 999999, 'Europe/Paris') '2013-03-31T01:59:59.999999+01:00' dt = dt.add(microseconds=1) '2013-03-31T03:00:00+02:00' dt.subtract(microseconds=1) '2013-03-31T01:59:59.999998+01:00' - dt = pendulum.create(2013, 10, 27, 1, 59, 59, 999999, 'Europe/Paris') + dt = pendulum.datetime(2013, 10, 27, 1, 59, 59, 999999, 'Europe/Paris') dt = dt.add(hours=1) # We can't just do - # pendulum.create(2013, 10, 27, 2, 59, 59, 999999, 'Europe/Paris') + # pendulum.datetime(2013, 10, 27, 2, 59, 59, 999999, 'Europe/Paris') # because of the default normalization '2013-10-27T02:59:59.999999+02:00' dt = dt.add(microseconds=1) @@ -131,7 +131,7 @@ with the ``in_timezone()`` method. .. code-block:: python - in_paris = pendulum.create(2016, 8, 7, 22, 24, 30, tz='Europe/Paris') + in_paris = pendulum.datetime(2016, 8, 7, 22, 24, 30, tz='Europe/Paris') '2016-08-07T22:24:30+02:00' in_paris.in_timezone('America/New_York') '2016-08-07T16:24:30-04:00' diff --git a/pendulum/__init__.py b/pendulum/__init__.py index 43d8b025..de17ae19 100644 --- a/pendulum/__init__.py +++ b/pendulum/__init__.py @@ -8,7 +8,6 @@ from .period import Period # Mimicking standard library -datetime = Pendulum date = Date time = Time @@ -78,3 +77,19 @@ # Timezones from .tz import timezone, timezones, local_timezone, UTC + + +def datetime(year, month, day, + hour=0, minute=0, second=0, microsecond=0, + tzinfo=None, tz=None, dst_rule=None): + fold = None + if dst_rule == POST_TRANSITION: + fold = 1 + elif dst_rule == PRE_TRANSITION: + fold = 0 + + return Pendulum( + year, month, day, hour, minute, second, microsecond, + tzinfo=tzinfo or tz, + fold=fold + ) diff --git a/pendulum/date.py b/pendulum/date.py index 41f266ee..afd3928d 100644 --- a/pendulum/date.py +++ b/pendulum/date.py @@ -4,6 +4,8 @@ import calendar import math +import warnings + from datetime import date, timedelta from dateutil.relativedelta import relativedelta @@ -113,16 +115,39 @@ def tomorrow(cls): ### Getters/Setters def year_(self, year): - return self._setter(year=year) + warnings.warn( + 'The year_() method will be removed in version 2.0. ' + 'Use set(year={}) instead.'.format(year), + DeprecationWarning, + stacklevel=2 + ) + + return self.set(year=year) def month_(self, month): - return self._setter(month=month) + warnings.warn( + 'The month_() method will be removed in version 2.0. ' + 'Use set(month={}) instead.'.format(month), + DeprecationWarning, + stacklevel=2 + ) + + return self.set(month=month) def day_(self, day): - return self._setter(day=day) + warnings.warn( + 'The day_() method will be removed in version 2.0. ' + 'Use set(day={}) instead.'.format(day), + DeprecationWarning, + stacklevel=2 + ) - def _setter(self, **kwargs): - return self.replace(**kwargs) + return self.set(day=day) + + def set(self, year=None, month=None, day=None): + return self.replace( + year=year, month=month, day=day + ) @property def day_of_week(self): @@ -266,6 +291,12 @@ def between(self, dt1, dt2, equal=True): :rtype: bool """ + warnings.warn( + 'The between() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt1 > dt2: dt1, dt2 = dt2, dt1 @@ -317,6 +348,12 @@ def min_(self, dt=None): :rtype: Date """ + warnings.warn( + 'The min_() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt is None: dt = Date.today() @@ -334,6 +371,12 @@ def minimum(self, dt=None): :rtype: Date """ + warnings.warn( + 'The minimum() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.min_(dt) def max_(self, dt=None): @@ -345,6 +388,12 @@ def max_(self, dt=None): :rtype: Date """ + warnings.warn( + 'The max_() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt is None: dt = Date.today() @@ -362,6 +411,12 @@ def maximum(self, dt=None): :rtype: Date """ + warnings.warn( + 'The maximum() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.max_(dt) def is_weekday(self): @@ -370,6 +425,12 @@ def is_weekday(self): :rtype: bool """ + warnings.warn( + 'The is_weekday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return not self.is_weekend() def is_weekend(self): @@ -378,6 +439,12 @@ def is_weekend(self): :rtype: bool """ + warnings.warn( + 'The is_weekend() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week in self._weekend_days def is_yesterday(self): @@ -386,6 +453,12 @@ def is_yesterday(self): :rtype: bool """ + warnings.warn( + 'The is_yesterday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self == self.yesterday() def is_today(self): @@ -394,6 +467,12 @@ def is_today(self): :rtype: bool """ + warnings.warn( + 'The is_today() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self == self.today() def is_tomorrow(self): @@ -402,6 +481,12 @@ def is_tomorrow(self): :rtype: bool """ + warnings.warn( + 'The is_tomorrow() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self == self.tomorrow() def is_future(self): @@ -446,6 +531,12 @@ def is_same_day(self, dt): :rtype: bool """ + warnings.warn( + 'The is_same_day() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self == dt def is_sunday(self): @@ -454,6 +545,12 @@ def is_sunday(self): :rtype: bool """ + warnings.warn( + 'The is_sunday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == SUNDAY def is_monday(self): @@ -462,6 +559,12 @@ def is_monday(self): :rtype: bool """ + warnings.warn( + 'The is_monday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == MONDAY def is_tuesday(self): @@ -470,6 +573,12 @@ def is_tuesday(self): :rtype: bool """ + warnings.warn( + 'The is_tuesday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == TUESDAY def is_wednesday(self): @@ -478,6 +587,12 @@ def is_wednesday(self): :rtype: bool """ + warnings.warn( + 'The is_wednesday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == WEDNESDAY def is_thursday(self): @@ -486,6 +601,12 @@ def is_thursday(self): :rtype: bool """ + warnings.warn( + 'The is_thursday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == THURSDAY def is_friday(self): @@ -494,6 +615,12 @@ def is_friday(self): :rtype: bool """ + warnings.warn( + 'The is_friday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == FRIDAY def is_saturday(self): @@ -502,6 +629,12 @@ def is_saturday(self): :rtype: bool """ + warnings.warn( + 'The is_saturday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.day_of_week == SATURDAY def is_birthday(self, dt=None): @@ -582,6 +715,12 @@ def add_timedelta(self, delta): :rtype: Date """ + warnings.warn( + 'The add_timedelta() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.add(days=delta.days) def subtract_timedelta(self, delta): @@ -593,6 +732,12 @@ def subtract_timedelta(self, delta): :rtype: Date """ + warnings.warn( + 'The subtract_timedelta() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.subtract(days=delta.days) def __add__(self, other): diff --git a/pendulum/mixins/default.py b/pendulum/mixins/default.py index b2177740..aa743a7a 100644 --- a/pendulum/mixins/default.py +++ b/pendulum/mixins/default.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import locale as _locale +import warnings + from contextlib import contextmanager from ..translator import Translator @@ -77,6 +79,12 @@ def reset_to_string_format(cls): Reset the format used to the default when type juggling a Date instance to a string. """ + warnings.warn( + 'The reset_to_string_format() helper ' + 'will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) cls.set_to_string_format(cls.DEFAULT_TO_STRING_FORMAT) @classmethod @@ -87,6 +95,12 @@ def set_to_string_format(cls, fmt): :type fmt: str """ + warnings.warn( + 'The set_to_string_format() helper ' + 'will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) cls._to_string_format = fmt def format(self, fmt, locale=None, formatter=None): diff --git a/pendulum/pendulum.py b/pendulum/pendulum.py index 38f37eec..75885aa9 100644 --- a/pendulum/pendulum.py +++ b/pendulum/pendulum.py @@ -352,6 +352,12 @@ def create(cls, year=None, month=None, day=None, :rtype: Pendulum """ + warnings.warn( + 'The create() helper will no longer exist in version 2.0. ' + 'Use datetime() instead.', + DeprecationWarning, + stacklevel=2 + ) tz = cls._safe_create_datetime_zone(tz) if any([year is None, month is None, day is None]): @@ -512,28 +518,68 @@ def copy(self): :rtype: Pendulum """ + warnings.warn( + 'The copy() method will be removed in version 2.0. ', + DeprecationWarning, + stacklevel=2 + ) return self.instance(self._datetime) # Getters/Setters def hour_(self, hour): - return self._setter(hour=hour) + warnings.warn( + 'The hour_() method will be removed in version 2.0. ' + 'Use set(hour={}) instead.'.format(hour), + DeprecationWarning, + stacklevel=2 + ) + + return self.set(hour=hour) def minute_(self, minute): - return self._setter(minute=minute) + warnings.warn( + 'The minute_() method will be removed in version 2.0. ' + 'Use set(minute={}) instead.'.format(minute), + DeprecationWarning, + stacklevel=2 + ) + + return self.set(minute=minute) def second_(self, second): - return self._setter(second=second) + warnings.warn( + 'The second_() method will be removed in version 2.0. ' + 'Use set(second={}) instead.'.format(second), + DeprecationWarning, + stacklevel=2 + ) + + return self.set(second=second) def microsecond_(self, microsecond): - return self._setter(microsecond=microsecond) + warnings.warn( + 'The microsecond_() method will be removed in version 2.0. ' + 'Use set(microsecond={}) instead.'.format(microsecond), + DeprecationWarning, + stacklevel=2 + ) + + return self.set(microsecond=microsecond) - def _setter(self, **kwargs): + def set(self, **kwargs): kwargs['tzinfo'] = True return self._tz.convert(self.replace(**kwargs)) def timezone_(self, tz): + warnings.warn( + 'The timezone_() method will be removed in version 2.0. ' + 'Use set(tz={}) instead.'.format(tz), + DeprecationWarning, + stacklevel=2 + ) + return self.__class__( self.year, self.month, self.day, self.hour, self.minute, self.second, self.microsecond, @@ -541,9 +587,22 @@ def timezone_(self, tz): ) def tz_(self, tz): + warnings.warn( + 'The tz_() method will be removed in version 2.0. ' + 'Use set(tz={}) instead.'.format(tz), + DeprecationWarning, + stacklevel=2 + ) + return self.timezone_(tz) def timestamp_(self, timestamp, tz=UTC): + warnings.warn( + 'The timestamp_() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.create_from_timestamp(timestamp, tz) @property @@ -615,10 +674,30 @@ def offset_hours(self): @property def local(self): + warnings.warn( + 'The local property will be removed in version 2.0. ' + 'Use is_local() instead.', + DeprecationWarning, + stacklevel=2 + ) + + return self.is_local() + + def is_local(self): return self.offset == self.in_timezone(self._local_timezone()).offset @property def utc(self): + warnings.warn( + 'The utc property will be removed in version 2.0. ' + 'Use is_utc() instead.', + DeprecationWarning, + stacklevel=2 + ) + + return self.is_utc() + + def is_utc(self): return self.offset == 0 @property @@ -708,6 +787,13 @@ def with_date_time(self, year, month, day, hour, minute, second, microsecond=0): :rtype: Pendulum """ + warnings.warn( + 'The with_date_time() method will be removed in version 2.0. ' + 'Use both on() and at() methods instead.', + DeprecationWarning, + stacklevel=2 + ) + return self.replace( year=year, month=month, day=day, hour=hour, minute=minute, second=second, @@ -723,6 +809,12 @@ def with_time_from_string(self, time): :rtype: Pendulum """ + warnings.warn( + 'The with_time_from_string() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + time = time.split(':') hour = int(time[0]) @@ -763,6 +855,12 @@ def with_timestamp(self, timestamp): :type timestamp: int or float :rtype: Pendulum """ + warnings.warn( + 'The with_timestamp() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + dt = datetime.datetime.fromtimestamp(timestamp, UTC).astimezone(self._tz) return self.instance(dt) @@ -951,6 +1049,12 @@ def between(self, dt1, dt2, equal=True): :rtype: bool """ + warnings.warn( + 'The between() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt1 > dt2: dt1, dt2 = dt2, dt1 @@ -1002,6 +1106,12 @@ def min_(self, dt=None): :rtype: Pendulum """ + warnings.warn( + 'The min_() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt is None: dt = Pendulum.now(self.timezone) @@ -1019,6 +1129,12 @@ def minimum(self, dt=None): :rtype: Pendulum """ + warnings.warn( + 'The minimum() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.min_(dt) def max_(self, dt=None): @@ -1030,6 +1146,12 @@ def max_(self, dt=None): :rtype: Pendulum """ + warnings.warn( + 'The max_() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt is None: dt = Pendulum.now(self.timezone) @@ -1047,6 +1169,12 @@ def maximum(self, dt=None): :rtype: Pendulum """ + warnings.warn( + 'The maximum() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.max_(dt) def is_yesterday(self): @@ -1055,6 +1183,12 @@ def is_yesterday(self): :rtype: bool """ + warnings.warn( + 'The is_yesterday() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.to_date_string() == self.yesterday(self._tz).to_date_string() def is_today(self): @@ -1063,6 +1197,12 @@ def is_today(self): :rtype: bool """ + warnings.warn( + 'The is_today() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.to_date_string() == self.now(self._tz).to_date_string() def is_tomorrow(self): @@ -1071,6 +1211,11 @@ def is_tomorrow(self): :rtype: bool """ + warnings.warn( + 'The is_tomorrow() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) return self.to_date_string() == self.tomorrow(self._tz).to_date_string() def is_future(self): @@ -1107,6 +1252,11 @@ def is_same_day(self, dt): :rtype: bool """ + warnings.warn( + 'The is_same_day() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) dt = self._get_datetime(dt, True) return self.to_date_string() == dt.to_date_string() @@ -1225,6 +1375,12 @@ def add_timedelta(self, delta): :rtype: Pendulum """ + warnings.warn( + 'The add_timedelta() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if isinstance(delta, Period): return self.add( years=delta.years, months=delta.months, @@ -1244,6 +1400,12 @@ def subtract_timedelta(self, delta): :rtype: Pendulum """ + warnings.warn( + 'The subtract_timedelta() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if isinstance(delta, Period): return self.subtract( years=delta.years, months=delta.months, @@ -1263,6 +1425,13 @@ def seconds_since_midnight(self): :rtype: int """ + warnings.warn( + 'The seconds_since_midnight() ' + 'method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.diff(self.start_of('day')).in_seconds() def seconds_until_end_of_day(self): @@ -1271,6 +1440,13 @@ def seconds_until_end_of_day(self): :rtype: int """ + warnings.warn( + 'The seconds_until_end_of_day() ' + 'method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.diff(self.end_of('day')).in_seconds() def diff(self, dt=None, abs=True): diff --git a/pendulum/period.py b/pendulum/period.py index 9f427088..d26e62a3 100644 --- a/pendulum/period.py +++ b/pendulum/period.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import operator +import warnings + import pendulum from datetime import datetime, date, timedelta @@ -144,6 +146,12 @@ def in_days(self): return self._delta['total']['days'] def in_weekdays(self): + warnings.warn( + 'The in_weekdays() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + start, end = self.start.start_of('day'), self.end.start_of('day') if not self._absolute and self.invert: start, end = self.end.start_of('day'), self.start.start_of('day') @@ -158,6 +166,12 @@ def in_weekdays(self): return days * (-1 if not self._absolute and self.invert else 1) def in_weekend_days(self): + warnings.warn( + 'The in_weekend_days() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + start, end = self.start.start_of('day'), self.end.start_of('day') if not self._absolute and self.invert: start, end = self.end.start_of('day'), self.start.start_of('day') diff --git a/pendulum/time.py b/pendulum/time.py index 4d7e0a3d..863731e6 100644 --- a/pendulum/time.py +++ b/pendulum/time.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import warnings + from datetime import time, datetime, timedelta from .interval import Interval, AbsoluteInterval @@ -129,6 +131,12 @@ def between(self, dt1, dt2, equal=True): :rtype: bool """ + warnings.warn( + 'The between() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt1 > dt2: dt1, dt2 = dt2, dt1 @@ -180,6 +188,12 @@ def min_(self, dt=None): :rtype: Time """ + warnings.warn( + 'The min_() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt is None: dt = Time.now() @@ -197,6 +211,12 @@ def minimum(self, dt=None): :rtype: Time """ + warnings.warn( + 'The minimum() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.min_(dt) def max_(self, dt=None): @@ -208,6 +228,12 @@ def max_(self, dt=None): :rtype: Time """ + warnings.warn( + 'The max() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + if dt is None: dt = Time.now() @@ -225,6 +251,12 @@ def maximum(self, dt=None): :rtype: Time """ + warnings.warn( + 'The maximum() method will be removed in version 2.0.', + DeprecationWarning, + stacklevel=2 + ) + return self.max_(dt) def __hash__(self): diff --git a/pyproject.toml b/pyproject.toml index c8fe9597..08151e18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,3 +29,4 @@ pytzdata = ">=2018.3" pytest = "^3.4" pytest-cov = "^2.4" pytz = ">=2018.3" +sphinx = "^1.7" diff --git a/tests/test_helpers.py b/tests/test_helpers.py index d1ef4511..e7d6bd41 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- +import pendulum + from datetime import datetime, date, time from pendulum.helpers import precise_diff, parse_iso8601 -from pendulum.tz.timezone import FixedTimezone from . import AbstractTestCase @@ -175,6 +176,28 @@ def test_parse_ios8601_invalid(self): self.assertRaises(ValueError, parse_iso8601, '2012W12-3') # Missing separator self.assertRaises(ValueError, parse_iso8601, '2012-W123') # Missing separator + def test_datetime(self): + dt = pendulum.datetime(2018, 4, 4, 12, 34, 56, 123456) + + self.assertPendulum(dt, 2018, 4, 4, 12, 34, 56, 123456) + + dt = pendulum.datetime( + 2013, 3, 31, 2, 30, + tzinfo='Europe/Paris' + ) + + self.assertPendulum(dt, 2013, 3, 31, 3, 30) + assert dt.timezone_name == 'Europe/Paris' + + dt = pendulum.datetime( + 2013, 3, 31, 2, 30, + tz='Europe/Paris', + dst_rule=pendulum.PRE_TRANSITION + ) + + self.assertPendulum(dt, 2013, 3, 31, 1, 30) + assert dt.timezone_name == 'Europe/Paris' + def assert_diff(self, diff, years=0, months=0, days=0, hours=0, minutes=0, seconds=0, microseconds=0): From d307c7e1aa02fb118962675b772c3a3235f8f101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 12:17:43 -0500 Subject: [PATCH 50/63] Update CI config --- .travis.yml | 13 +++++++++---- appveyor.yml | 16 +++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index d2b9b67c..264dd9c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,11 @@ matrix: - python: pypy - python: pypy3 +cache: + pip: true + directories: + - $HOME/.cache/pypoetry + before_install: - pip install codecov @@ -38,10 +43,10 @@ install: virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION" source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - - virtualenv --python="$HOME/virtualenv/python3.6/bin/python" "$HOME/virtualenvs/venv-poetry" - - $HOME/virtualenvs/venv-poetry/bin/pip install poetry --pre - - $HOME/virtualenvs/venv-poetry/bin/poetry install -v - - $HOME/virtualenvs/venv-poetry/bin/poetry build -v + - wget https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py + - python get-poetry.py --preview + - poetry install -v + - poetry build -v - | if [ "$PENDULUM_EXTENSIONS" == "1" ]; then find dist/ -iname pendulum*.whl -exec unzip -o {} 'pendulum/*' -d . \; diff --git a/appveyor.yml b/appveyor.yml index 6ea15971..a703eec0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,22 +18,16 @@ install: # about it being out of date. - "pip install --disable-pip-version-check --user --upgrade pip" - # Create poetry virtualenv - - pip install virtualenv - - virtualenv --python="C:/Python36-x64\\python.exe" "venv-poetry" - - venv-poetry\\Scripts\\pip.exe install poetry --pre - - # Create current python virtualenv - - python -m virtualenv venv - - venv\Scripts\activate.bat - - "SET VIRTUAL_ENV=venv" # Seems that activate.bat does not set VIRTUAL_ENV + # Downloading and installing poetry + - curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py + - python get-poetry.py --preview # Install dependencies - pip install codecov - - venv-poetry\\Scripts\\poetry.exe install -v + - poetry install -v test_script: - - "pytest --cov=pendulum --cov-config=.coveragerc tests/" + - "poetry run pytest --cov=pendulum --cov-config=.coveragerc tests/" after_test: - "codecov" From b3e3504a2bc2db2c640212e3220dc9d1fafecaac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 12:45:39 -0500 Subject: [PATCH 51/63] Fix appveyor config --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a703eec0..0e75b0d1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,7 +23,7 @@ install: - python get-poetry.py --preview # Install dependencies - - pip install codecov + - python -m pip install codecov - poetry install -v test_script: From bc4efe0ca3166da0ce88473f5007c30814573e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 13:10:05 -0500 Subject: [PATCH 52/63] Make warnings visible --- pendulum/date.py | 47 ++++++++++++++++--------------- pendulum/exceptions.py | 12 ++++++-- pendulum/mixins/default.py | 5 ++-- pendulum/parsing/parser.py | 5 ++-- pendulum/pendulum.py | 57 +++++++++++++++++++------------------- pendulum/period.py | 5 ++-- pendulum/time.py | 11 ++++---- 7 files changed, 78 insertions(+), 64 deletions(-) diff --git a/pendulum/date.py b/pendulum/date.py index afd3928d..fd06ac58 100644 --- a/pendulum/date.py +++ b/pendulum/date.py @@ -9,6 +9,7 @@ from datetime import date, timedelta from dateutil.relativedelta import relativedelta +from .exceptions import PendulumDeprecationWarning from .period import Period from .formatting.difference_formatter import DifferenceFormatter from .mixins.default import TranslatableMixin, FormattableMixing, TestableMixin @@ -118,7 +119,7 @@ def year_(self, year): warnings.warn( 'The year_() method will be removed in version 2.0. ' 'Use set(year={}) instead.'.format(year), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -128,7 +129,7 @@ def month_(self, month): warnings.warn( 'The month_() method will be removed in version 2.0. ' 'Use set(month={}) instead.'.format(month), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -138,7 +139,7 @@ def day_(self, day): warnings.warn( 'The day_() method will be removed in version 2.0. ' 'Use set(day={}) instead.'.format(day), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -293,7 +294,7 @@ def between(self, dt1, dt2, equal=True): """ warnings.warn( 'The between() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -350,7 +351,7 @@ def min_(self, dt=None): """ warnings.warn( 'The min_() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -373,7 +374,7 @@ def minimum(self, dt=None): """ warnings.warn( 'The minimum() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -390,7 +391,7 @@ def max_(self, dt=None): """ warnings.warn( 'The max_() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -413,7 +414,7 @@ def maximum(self, dt=None): """ warnings.warn( 'The maximum() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -427,7 +428,7 @@ def is_weekday(self): """ warnings.warn( 'The is_weekday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -441,7 +442,7 @@ def is_weekend(self): """ warnings.warn( 'The is_weekend() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -455,7 +456,7 @@ def is_yesterday(self): """ warnings.warn( 'The is_yesterday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -469,7 +470,7 @@ def is_today(self): """ warnings.warn( 'The is_today() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -483,7 +484,7 @@ def is_tomorrow(self): """ warnings.warn( 'The is_tomorrow() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -533,7 +534,7 @@ def is_same_day(self, dt): """ warnings.warn( 'The is_same_day() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -547,7 +548,7 @@ def is_sunday(self): """ warnings.warn( 'The is_sunday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -561,7 +562,7 @@ def is_monday(self): """ warnings.warn( 'The is_monday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -575,7 +576,7 @@ def is_tuesday(self): """ warnings.warn( 'The is_tuesday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -589,7 +590,7 @@ def is_wednesday(self): """ warnings.warn( 'The is_wednesday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -603,7 +604,7 @@ def is_thursday(self): """ warnings.warn( 'The is_thursday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -617,7 +618,7 @@ def is_friday(self): """ warnings.warn( 'The is_friday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -631,7 +632,7 @@ def is_saturday(self): """ warnings.warn( 'The is_saturday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -717,7 +718,7 @@ def add_timedelta(self, delta): """ warnings.warn( 'The add_timedelta() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -734,7 +735,7 @@ def subtract_timedelta(self, delta): """ warnings.warn( 'The subtract_timedelta() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) diff --git a/pendulum/exceptions.py b/pendulum/exceptions.py index b777018b..ba278362 100644 --- a/pendulum/exceptions.py +++ b/pendulum/exceptions.py @@ -1,8 +1,16 @@ # -*- coding: utf-8 -*- -from .parsing.exceptions import ParserError - class PendulumException(BaseException): pass + + +class PendulumWarning(Warning): + + pass + + +class PendulumDeprecationWarning(PendulumWarning): + + pass diff --git a/pendulum/mixins/default.py b/pendulum/mixins/default.py index aa743a7a..77aba1e6 100644 --- a/pendulum/mixins/default.py +++ b/pendulum/mixins/default.py @@ -5,6 +5,7 @@ from contextlib import contextmanager +from ..exceptions import PendulumDeprecationWarning from ..translator import Translator from ..formatting import FORMATTERS @@ -82,7 +83,7 @@ def reset_to_string_format(cls): warnings.warn( 'The reset_to_string_format() helper ' 'will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) cls.set_to_string_format(cls.DEFAULT_TO_STRING_FORMAT) @@ -98,7 +99,7 @@ def set_to_string_format(cls, fmt): warnings.warn( 'The set_to_string_format() helper ' 'will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) cls._to_string_format = fmt diff --git a/pendulum/parsing/parser.py b/pendulum/parsing/parser.py index d64fd7c6..2e61fa80 100644 --- a/pendulum/parsing/parser.py +++ b/pendulum/parsing/parser.py @@ -7,6 +7,7 @@ from datetime import datetime, date, time from dateutil import parser +from ..exceptions import PendulumDeprecationWarning from ..helpers import parse_iso8601, week_day, days_in_year from .exceptions import ParserError @@ -68,7 +69,7 @@ def __init__(self, **options): warnings.warn( 'The "strict" keyword when parsing will have ' 'another meaning in version 2.0. Use "exact" instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -80,7 +81,7 @@ def __init__(self, **options): def is_strict(self): warnings.warn( 'is_strict() is deprecated. Use is_exact() instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) diff --git a/pendulum/pendulum.py b/pendulum/pendulum.py index 75885aa9..a86ce829 100644 --- a/pendulum/pendulum.py +++ b/pendulum/pendulum.py @@ -11,6 +11,7 @@ from .date import Date from .time import Time from .period import Period +from .exceptions import PendulumDeprecationWarning from .exceptions import PendulumException from .tz import Timezone, UTC, FixedTimezone, local_timezone from .tz.timezone_info import TimezoneInfo @@ -355,7 +356,7 @@ def create(cls, year=None, month=None, day=None, warnings.warn( 'The create() helper will no longer exist in version 2.0. ' 'Use datetime() instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) tz = cls._safe_create_datetime_zone(tz) @@ -409,7 +410,7 @@ def create_from_format(cls, time, fmt, tz=UTC, formatter='classic'): 'Using the classic formatter in from_format() ' 'is deprecated and will no longer be possible ' 'in version 2.0. Use the alternative formatter instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) dt = datetime.datetime.strptime(time, fmt) @@ -520,7 +521,7 @@ def copy(self): """ warnings.warn( 'The copy() method will be removed in version 2.0. ', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) return self.instance(self._datetime) @@ -531,7 +532,7 @@ def hour_(self, hour): warnings.warn( 'The hour_() method will be removed in version 2.0. ' 'Use set(hour={}) instead.'.format(hour), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -541,7 +542,7 @@ def minute_(self, minute): warnings.warn( 'The minute_() method will be removed in version 2.0. ' 'Use set(minute={}) instead.'.format(minute), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -551,7 +552,7 @@ def second_(self, second): warnings.warn( 'The second_() method will be removed in version 2.0. ' 'Use set(second={}) instead.'.format(second), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -561,7 +562,7 @@ def microsecond_(self, microsecond): warnings.warn( 'The microsecond_() method will be removed in version 2.0. ' 'Use set(microsecond={}) instead.'.format(microsecond), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -576,7 +577,7 @@ def timezone_(self, tz): warnings.warn( 'The timezone_() method will be removed in version 2.0. ' 'Use set(tz={}) instead.'.format(tz), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -590,7 +591,7 @@ def tz_(self, tz): warnings.warn( 'The tz_() method will be removed in version 2.0. ' 'Use set(tz={}) instead.'.format(tz), - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -599,7 +600,7 @@ def tz_(self, tz): def timestamp_(self, timestamp, tz=UTC): warnings.warn( 'The timestamp_() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -677,7 +678,7 @@ def local(self): warnings.warn( 'The local property will be removed in version 2.0. ' 'Use is_local() instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -691,7 +692,7 @@ def utc(self): warnings.warn( 'The utc property will be removed in version 2.0. ' 'Use is_utc() instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -790,7 +791,7 @@ def with_date_time(self, year, month, day, hour, minute, second, microsecond=0): warnings.warn( 'The with_date_time() method will be removed in version 2.0. ' 'Use both on() and at() methods instead.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -811,7 +812,7 @@ def with_time_from_string(self, time): """ warnings.warn( 'The with_time_from_string() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -857,7 +858,7 @@ def with_timestamp(self, timestamp): """ warnings.warn( 'The with_timestamp() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1051,7 +1052,7 @@ def between(self, dt1, dt2, equal=True): """ warnings.warn( 'The between() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1108,7 +1109,7 @@ def min_(self, dt=None): """ warnings.warn( 'The min_() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1131,7 +1132,7 @@ def minimum(self, dt=None): """ warnings.warn( 'The minimum() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1148,7 +1149,7 @@ def max_(self, dt=None): """ warnings.warn( 'The max_() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1171,7 +1172,7 @@ def maximum(self, dt=None): """ warnings.warn( 'The maximum() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1185,7 +1186,7 @@ def is_yesterday(self): """ warnings.warn( 'The is_yesterday() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1199,7 +1200,7 @@ def is_today(self): """ warnings.warn( 'The is_today() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1213,7 +1214,7 @@ def is_tomorrow(self): """ warnings.warn( 'The is_tomorrow() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) return self.to_date_string() == self.tomorrow(self._tz).to_date_string() @@ -1254,7 +1255,7 @@ def is_same_day(self, dt): """ warnings.warn( 'The is_same_day() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) dt = self._get_datetime(dt, True) @@ -1377,7 +1378,7 @@ def add_timedelta(self, delta): """ warnings.warn( 'The add_timedelta() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1402,7 +1403,7 @@ def subtract_timedelta(self, delta): """ warnings.warn( 'The subtract_timedelta() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1428,7 +1429,7 @@ def seconds_since_midnight(self): warnings.warn( 'The seconds_since_midnight() ' 'method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -1443,7 +1444,7 @@ def seconds_until_end_of_day(self): warnings.warn( 'The seconds_until_end_of_day() ' 'method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) diff --git a/pendulum/period.py b/pendulum/period.py index d26e62a3..e62361f8 100644 --- a/pendulum/period.py +++ b/pendulum/period.py @@ -7,6 +7,7 @@ from datetime import datetime, date, timedelta +from .exceptions import PendulumDeprecationWarning from .mixins.interval import WordableIntervalMixin from .interval import BaseInterval, Interval from .constants import MONTHS_PER_YEAR @@ -148,7 +149,7 @@ def in_days(self): def in_weekdays(self): warnings.warn( 'The in_weekdays() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -168,7 +169,7 @@ def in_weekdays(self): def in_weekend_days(self): warnings.warn( 'The in_weekend_days() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) diff --git a/pendulum/time.py b/pendulum/time.py index 863731e6..06dd94e0 100644 --- a/pendulum/time.py +++ b/pendulum/time.py @@ -4,6 +4,7 @@ from datetime import time, datetime, timedelta +from .exceptions import PendulumDeprecationWarning from .interval import Interval, AbsoluteInterval from .mixins.default import TranslatableMixin, FormattableMixing, TestableMixin from .constants import ( @@ -133,7 +134,7 @@ def between(self, dt1, dt2, equal=True): """ warnings.warn( 'The between() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -190,7 +191,7 @@ def min_(self, dt=None): """ warnings.warn( 'The min_() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -213,7 +214,7 @@ def minimum(self, dt=None): """ warnings.warn( 'The minimum() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -230,7 +231,7 @@ def max_(self, dt=None): """ warnings.warn( 'The max() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) @@ -253,7 +254,7 @@ def maximum(self, dt=None): """ warnings.warn( 'The maximum() method will be removed in version 2.0.', - DeprecationWarning, + PendulumDeprecationWarning, stacklevel=2 ) From b790f9b4741dbe52a437b904fca5d6f178fd4110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 13:20:01 -0500 Subject: [PATCH 53/63] Update appveyor config --- appveyor.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0e75b0d1..afeebee3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,12 +11,17 @@ environment: - PYTHON: "C:/Python36" - PYTHON: "C:/Python36-x64" +cache: + - '%LocalAppData%\pip\Cache' + - '%LocalAppData%\pypoetry\Cache' + + install: - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" # Upgrade to the latest version of pip to avoid it displaying warnings # about it being out of date. - - "pip install --disable-pip-version-check --user --upgrade pip" + - "python -m pip install --disable-pip-version-check --user --upgrade pip" # Downloading and installing poetry - curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py From 1ba13c08f65c76f71e664f9c66bf4e86124356f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 13:55:20 -0500 Subject: [PATCH 54/63] Update CI config --- .travis.yml | 2 +- appveyor.yml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 264dd9c8..73fad2c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ install: find dist/ -iname pendulum*.whl -exec unzip -o {} 'pendulum/*' -d . \; fi -script: pytest --cov=pendulum --cov-config=.coveragerc tests/ +script: poetry run pytest --cov=pendulum --cov-config=.coveragerc tests/ -W ignore after_success: - codecov diff --git a/appveyor.yml b/appveyor.yml index afeebee3..739197f2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,8 +4,6 @@ environment: matrix: - PYTHON: "C:/Python27" - PYTHON: "C:/Python27-x64" - - PYTHON: "C:/Python34" - - PYTHON: "C:/Python34-x64" - PYTHON: "C:/Python35" - PYTHON: "C:/Python35-x64" - PYTHON: "C:/Python36" @@ -32,7 +30,7 @@ install: - poetry install -v test_script: - - "poetry run pytest --cov=pendulum --cov-config=.coveragerc tests/" + - "poetry run pytest --cov=pendulum --cov-config=.coveragerc tests/ -W ignore" after_test: - "codecov" From 87c584b2f9525b2e2bf9fe4b975bdd8e0cfd631f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 15:00:05 -0500 Subject: [PATCH 55/63] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e950d8..7d8b2a03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,13 @@ ### Added +- Added the `datetime()` helper. - Added the `set()` method to set properties. - Added the `is_utc()` and `is_local()` methods. ### Deprecated -- `year_()`, `month_()`, `day_`, `hour_`, `minute_`, `second_`, `microsecond_()` are now deprecated. +- `year_()`, `month_()`, `day_()`, `hour_()`, `minute_()`, `second_()`, `microsecond_()` are now deprecated. - `timezone_()` and `tz_()` are now deprecated. - `timestamp_()` is now deprecated. - `with_date_time()`, `with_time_from_string()` and `with_timestamp()` are now deprecated. From 62486839b75c6160892240d617b3081d9fce777b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 16:22:00 -0500 Subject: [PATCH 56/63] Update files for building process --- Makefile | 2 +- build-wheels.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 136f3d1b..518d1bf8 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ test: release: wheels_x64 cp_wheels_x64 wheels_i686 cp_wheels_i686 wheel publish: - @python -m twine upload dist/pendulum-$(PENDULUM_RELEASE)* + @poetry publish --no-build tar: python setup.py sdist --formats=gztar diff --git a/build-wheels.sh b/build-wheels.sh index 18ff4b88..63139ece 100755 --- a/build-wheels.sh +++ b/build-wheels.sh @@ -1,5 +1,5 @@ #!/bin/bash -PYTHON_VERSIONS="cp27-cp27m cp35-cp35m cp36-cp36m" +PYTHON_VERSIONS="cp27-cp27m cp34-cp34m cp35-cp35m cp36-cp36m" POETRY_PYTHON="cp36-cp36m" POETRY_VENV="/opt/python/poetry" @@ -32,7 +32,7 @@ for PYTHON in ${PYTHON_VERSIONS}; do . /opt/python/venv-${PYTHON}/bin/activate pip install pendulum==${RELEASE} --no-index --find-links /io/wheelhouse find ./io/tests | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf - pytest /io/tests + pytest /io/tests -W ignore find ./io/tests | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf deactivate done From a8bf381cba548879a297e1a8c2beef9c14f1fde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 16:23:09 -0500 Subject: [PATCH 57/63] Bump version to 1.5.0 --- docs/conf.py | 6 +++--- pendulum/version.py | 2 +- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c6f1bc20..f3fa34cf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,7 +50,7 @@ # General information about the project. project = 'Pendulum' -copyright = '2016, Sébastien Eustace' +copyright = '2016-2018, Sébastien Eustace' author = 'Sébastien Eustace' # The version info for the project you're documenting, acts as replacement for @@ -58,9 +58,9 @@ # built documents. # # The short X.Y version. -version = '1.4' +version = '1.5' # The full version, including alpha/beta/rc tags. -release = '1.4.2' +release = '1.5.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pendulum/version.py b/pendulum/version.py index 360b89fb..93cd0233 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.4' +VERSION = '1.5.0' diff --git a/pyproject.toml b/pyproject.toml index 08151e18..823789a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pendulum" -version = "1.4.4" +version = "1.5.0" description = "Python datetimes made easy." license = "MIT" From 4b31cddcf9dd52366018feab75f0471f3eb4cbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 16 Apr 2018 17:51:14 -0500 Subject: [PATCH 58/63] Update CHANGELOG --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d8b2a03..fb975ea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.5.0] - 2018-04-16 ### Added @@ -494,7 +494,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.4.4...1.x +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.5.0...1.x +[1.5.0]: https://github.com/sdispater/pendulum/releases/tag/1.5.0 [1.4.4]: https://github.com/sdispater/pendulum/releases/tag/1.4.4 [1.4.3]: https://github.com/sdispater/pendulum/releases/tag/1.4.3 [1.4.2]: https://github.com/sdispater/pendulum/releases/tag/1.4.2 From cbc8184e27ea9c47da05eb5c60f027f21563b436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 24 Apr 2018 18:31:56 -0500 Subject: [PATCH 59/63] Fix set() not accepting the tz argument --- CHANGELOG.md | 7 +++++++ pendulum/pendulum.py | 5 +++++ tests/pendulum_tests/test_fluent_setters.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb975ea6..9a195514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [Unreleased] + +### Fixed + +- Fixed `set()` not acception the `tz` keyword argument. + + ## [1.5.0] - 2018-04-16 ### Added diff --git a/pendulum/pendulum.py b/pendulum/pendulum.py index a86ce829..733d5b07 100644 --- a/pendulum/pendulum.py +++ b/pendulum/pendulum.py @@ -569,6 +569,11 @@ def microsecond_(self, microsecond): return self.set(microsecond=microsecond) def set(self, **kwargs): + if 'tz' in kwargs: + kwargs['tzinfo'] = kwargs.pop('tz') + + return self.replace(**kwargs) + kwargs['tzinfo'] = True return self._tz.convert(self.replace(**kwargs)) diff --git a/tests/pendulum_tests/test_fluent_setters.py b/tests/pendulum_tests/test_fluent_setters.py index ddd68d9c..d3d9347c 100644 --- a/tests/pendulum_tests/test_fluent_setters.py +++ b/tests/pendulum_tests/test_fluent_setters.py @@ -184,3 +184,19 @@ def test_replace_tzinfo_dst_with_error_transition_rule(self): d = Pendulum.create(2013, 3, 31, 2, 30) self.assertRaises(NonExistingTime, d.replace, tzinfo='Europe/Paris') + + def test_set(self): + dt = pendulum.datetime(2016, 7, 2, 0, 41, 20) + + assert dt.set(year=1995).year == 1995 + assert dt.set(month=11).month == 11 + assert dt.set(day=9).day == 9 + assert dt.set(hour=12).hour == 12 + assert dt.set(minute=34).minute == 34 + assert dt.set(second=56).second == 56 + assert dt.set(tz='Europe/Paris').timezone_name == 'Europe/Paris' + + dt = pendulum.datetime(2013, 3, 31, 2, 30) + dt = dt.set(tz='Europe/Paris') + + self.assertPendulum(dt, 2013, 3, 31, 3, 30) From 556a34666c1c9e3f425485491434e153663ca210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 24 Apr 2018 18:36:48 -0500 Subject: [PATCH 60/63] Fix datetime() not setting the timezone to UTC by default. --- CHANGELOG.md | 1 + pendulum/__init__.py | 2 +- tests/test_helpers.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a195514..7e5397b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed `set()` not acception the `tz` keyword argument. +- Fixed `datetime()` not setting the timezone to `UTC` by default. ## [1.5.0] - 2018-04-16 diff --git a/pendulum/__init__.py b/pendulum/__init__.py index de17ae19..bb4403e6 100644 --- a/pendulum/__init__.py +++ b/pendulum/__init__.py @@ -90,6 +90,6 @@ def datetime(year, month, day, return Pendulum( year, month, day, hour, minute, second, microsecond, - tzinfo=tzinfo or tz, + tzinfo=tzinfo or tz or UTC, fold=fold ) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index e7d6bd41..854972c6 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -180,6 +180,7 @@ def test_datetime(self): dt = pendulum.datetime(2018, 4, 4, 12, 34, 56, 123456) self.assertPendulum(dt, 2018, 4, 4, 12, 34, 56, 123456) + assert dt.timezone_name == 'UTC' dt = pendulum.datetime( 2013, 3, 31, 2, 30, From 41f5ac3c145b66dbf5c2f1d9c6860a8c776a09f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 24 Apr 2018 18:44:01 -0500 Subject: [PATCH 61/63] Bump version to 1.5.1 --- CHANGELOG.md | 5 +++-- pendulum/version.py | 2 +- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5397b1..3716d138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.5.1] - 2018-04-24 ### Fixed @@ -502,7 +502,8 @@ Initial release -[Unreleased]: https://github.com/sdispater/pendulum/compare/1.5.0...1.x +[Unreleased]: https://github.com/sdispater/pendulum/compare/1.5.1...1.x +[1.5.1]: https://github.com/sdispater/pendulum/releases/tag/1.5.1 [1.5.0]: https://github.com/sdispater/pendulum/releases/tag/1.5.0 [1.4.4]: https://github.com/sdispater/pendulum/releases/tag/1.4.4 [1.4.3]: https://github.com/sdispater/pendulum/releases/tag/1.4.3 diff --git a/pendulum/version.py b/pendulum/version.py index 93cd0233..3224c5e7 100644 --- a/pendulum/version.py +++ b/pendulum/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.5.0' +VERSION = '1.5.1' diff --git a/pyproject.toml b/pyproject.toml index 823789a4..24c86c8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pendulum" -version = "1.5.0" +version = "1.5.1" description = "Python datetimes made easy." license = "MIT" From 666fac217d745058e929c5c600d1d7d966228c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Thu, 26 Apr 2018 19:58:04 -0500 Subject: [PATCH 62/63] Update Travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 73fad2c3..7e7b7d8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,7 @@ install: - python get-poetry.py --preview - poetry install -v - poetry build -v + - pip install dist/pendulum-$(sed -n "s/VERSION = '\(.*\)'/\1/p" /io/pendulum/version.py).tar.gz - | if [ "$PENDULUM_EXTENSIONS" == "1" ]; then find dist/ -iname pendulum*.whl -exec unzip -o {} 'pendulum/*' -d . \; From 11c36e079f7c20bc7959af3bac6c6bb873857d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Thu, 26 Apr 2018 20:01:18 -0500 Subject: [PATCH 63/63] Update Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7e7b7d8f..e2ab6469 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ install: - python get-poetry.py --preview - poetry install -v - poetry build -v - - pip install dist/pendulum-$(sed -n "s/VERSION = '\(.*\)'/\1/p" /io/pendulum/version.py).tar.gz + - pip install dist/pendulum-$(sed -n "s/VERSION = '\(.*\)'/\1/p" pendulum/version.py).tar.gz - | if [ "$PENDULUM_EXTENSIONS" == "1" ]; then find dist/ -iname pendulum*.whl -exec unzip -o {} 'pendulum/*' -d . \;