Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking changes with arrow 1.0.0 #407

Closed
veganjay opened this issue Feb 27, 2021 · 4 comments · Fixed by #408
Closed

Breaking changes with arrow 1.0.0 #407

veganjay opened this issue Feb 27, 2021 · 4 comments · Fixed by #408
Assignees

Comments

@veganjay
Copy link
Contributor

Problem Description

I installed td-watson in a fresh environment and received an error when running:

$ docker run -it --rm python:latest /bin/bash
root@4156557dc8cf:/# pip install td-watson
...
root@4156557dc8cf:/# watson status
Traceback (most recent call last):
  File "/usr/local/bin/watson", line 5, in <module>
    from watson.__main__ import cli
  File "/usr/local/lib/python3.9/site-packages/watson/__main__.py", line 2, in <module>
    from watson import cli
  File "/usr/local/lib/python3.9/site-packages/watson/cli.py", line 441, in <module>
    _SHORTCUT_OPTIONS_VALUES = {
  File "/usr/local/lib/python3.9/site-packages/watson/cli.py", line 442, in <dictcomp>
    k: get_start_time_for_period(k) for k in _SHORTCUT_OPTIONS
  File "/usr/local/lib/python3.9/site-packages/watson/utils.py", line 193, in get_start_time_for_period
    start_time = get_last_full_moon(now)
  File "/usr/local/lib/python3.9/site-packages/watson/fullmoon.py", line 226, in get_last_full_moon
    idx = bisect.bisect_right(fullmoons, now)
TypeError: '<' not supported between instances of 'method' and 'int'

The arrow library was updated on Feb 24, 2021 and there are breaking changes.

The default td-watson installation uses the new version, arrow 1.0.0:

root@4156557dc8cf:/# pip freeze
arrow==1.0.0
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
click-didyoumean==0.0.3
idna==2.10
python-dateutil==2.8.1
requests==2.25.1
six==1.15.0
td-watson==1.10.0
urllib3==1.26.3

Workaround

Downgrade to arrow 0.17.0:

root@4156557dc8cf:/# pip uninstall arrow
Found existing installation: arrow 1.0.0
Uninstalling arrow-1.0.0:
  Would remove:
    /usr/local/lib/python3.9/site-packages/arrow-1.0.0.dist-info/*
    /usr/local/lib/python3.9/site-packages/arrow/*
Proceed (y/n)? y
  Successfully uninstalled arrow-1.0.0
root@4156557dc8cf:/# pip install arrow==0.17.0

And td-watson works again:

root@4156557dc8cf:/# watson status
No project started.
root@4156557dc8cf:/# watson start testing123
Starting project testing123 at 15:25
root@4156557dc8cf:/# watson stop
Stopping project testing123, started just now and stopped just now. (id: d056c4c)

Quick fix

Update requirements.txt changing the line:

arrow>=0.15.6

To specify the exact version:

arrow==0.17.0

Long-term solution

According to the arrow 1.0.0 migration guide:

The .timestamp property has been removed to improve compatibility with datetime. Use .int_timestamp for the same results.

arrow.utcnow().int_timestamp
1608640233

I tried this and it appears to work.

The changes are:

diff watson/frames.py /usr/local/lib/python3.9/site-packages/watson/frames.py
38,40c38,40
<         start = self.start.to('utc').timestamp
<         stop = self.stop.to('utc').timestamp
<         updated_at = self.updated_at.timestamp
---
>         start = self.start.to('utc').int_timestamp
>         stop = self.stop.to('utc').int_timestamp
>         updated_at = self.updated_at.int_timestamp
diff watson/fullmoon.py /usr/local/lib/python3.9/site-packages/watson/fullmoon.py
225c225,226
<     now = d.timestamp
---
>     now = d.int_timestamp
diff watson/watson.py /usr/local/lib/python3.9/site-packages/watson/watson.py
104c104
<         return date.timestamp
---
>         return date.int_timestamp
veganjay added a commit to veganjay/Watson that referenced this issue Feb 27, 2021
- requirements.txt: specify arrow==1.00
- frames.py, fullmoon.py, watson.py: change "timestamp" to
  "int_timestamp"
@veganjay
Copy link
Contributor Author

Also need to update the tzinfo calls.

According to the arrow 1.0.0 migration guide.

It's no longer possible to set the tzinfo property directly, instead use replace().

dt=arrow.utcnow()
dt.tzinfo=tz.gettz("US/Pacific")
Traceback (most recent call last):
File "", line 1, in
AttributeError: can't set attribute
dt.replace(tzinfo=tz.gettz("US/Pacific"))
<Arrow [2020-12-22T16:03:29.630250-08:00]>

The following seems to address this:

# diff watson/cli.py /usr/local/lib/python3.9/site-packages/watson/cli.py
84c84
<             date.tzinfo = tz.tzlocal()
---
>             date.replace(tzinfo=tz.tzlocal())

veganjay added a commit to veganjay/Watson that referenced this issue Feb 27, 2021
- cli.py: change "date.tzinfo = tz.tzlocal()" to "date.replace(tzinfo=tz.tzlocal())"
@jmaupetit
Copy link
Member

Looks wonderful. Can you submit a PR with your fix?

@veganjay
Copy link
Contributor Author

veganjay commented Mar 1, 2021

Thank you. PR submitted.

This was linked to pull requests Mar 1, 2021
@jmaupetit jmaupetit removed a link to a pull request Mar 2, 2021
veganjay added a commit to veganjay/Watson that referenced this issue Mar 3, 2021
- watson.cli.py: use date = date.replace(tzinfo=tz.tzlocal())
  (date.replace does not modify the existing object)
veganjay added a commit to veganjay/Watson that referenced this issue Mar 3, 2021
Update unit test cases:

- tests/test_cli.py: replace arrow.arrow.datetime with arrow.arrow.dt_datetime
- tests/test_watson.py: replace .timestamp with .int_timestamp
veganjay added a commit to veganjay/Watson that referenced this issue Mar 4, 2021
- .travis.yml: remove python 3.5
- setup.py: require python >= 3.6
- CHANGELOG.md: mention arrow upgrade and drop of python 3.5 support
jmaupetit pushed a commit that referenced this issue Mar 4, 2021
- requirements.txt: specify arrow==1.00
- frames.py, fullmoon.py, watson.py: change "timestamp" to
  "int_timestamp"
jmaupetit pushed a commit that referenced this issue Mar 4, 2021
- cli.py: change "date.tzinfo = tz.tzlocal()" to "date.replace(tzinfo=tz.tzlocal())"
jmaupetit pushed a commit that referenced this issue Mar 4, 2021
- watson.cli.py: use date = date.replace(tzinfo=tz.tzlocal())
  (date.replace does not modify the existing object)
jmaupetit pushed a commit that referenced this issue Mar 4, 2021
Update unit test cases:

- tests/test_cli.py: replace arrow.arrow.datetime with arrow.arrow.dt_datetime
- tests/test_watson.py: replace .timestamp with .int_timestamp
jmaupetit pushed a commit that referenced this issue Mar 4, 2021
- .travis.yml: remove python 3.5
- setup.py: require python >= 3.6
- CHANGELOG.md: mention arrow upgrade and drop of python 3.5 support
jmaupetit added a commit that referenced this issue Mar 19, 2021
Added:

- The `log` command output can now be filtered to exclude projects and
  tags via `--ignore-project` and `--ignore-tag` (#395)
- Python 3.8 support (#402)
- Python 3.9 support (#402)
- Support for the TZ environment variable to specify the local time zone
  (#391)

Changed:

- Upgrade to major arrow release 1.0.0 (#407)

Fixed:

- Zsh completion (#379)

Removed:

- Python 2.7 support (#305).
- Python 3.5 support (#407).
jmaupetit added a commit that referenced this issue Mar 19, 2021
Added:

- The `log` command output can now be filtered to exclude projects and
  tags via `--ignore-project` and `--ignore-tag` (#395)
- Python 3.8 support (#402)
- Python 3.9 support (#402)
- Support for the TZ environment variable to specify the local time zone
  (#391)

Changed:

- Upgrade to major arrow release 1.0.0 (#407)

Fixed:

- Zsh completion (#379)

Removed:

- Python 2.7 support (#305).
- Python 3.5 support (#407).
@jmaupetit
Copy link
Member

📢 The new 2.0.0 release including this fix is out! https://pypi.org/project/td-watson/2.0.0/ 🔥

veganjay pushed a commit to veganjay/Watson that referenced this issue May 15, 2021
Added:

- The `log` command output can now be filtered to exclude projects and
  tags via `--ignore-project` and `--ignore-tag` (TailorDev#395)
- Python 3.8 support (TailorDev#402)
- Python 3.9 support (TailorDev#402)
- Support for the TZ environment variable to specify the local time zone
  (TailorDev#391)

Changed:

- Upgrade to major arrow release 1.0.0 (TailorDev#407)

Fixed:

- Zsh completion (TailorDev#379)

Removed:

- Python 2.7 support (TailorDev#305).
- Python 3.5 support (TailorDev#407).
samtx added a commit to samtx/Watson that referenced this issue Apr 17, 2022
* Resolve Issue TailorDev#407: Migrate to arrow 1.0.0

- requirements.txt: specify arrow==1.00
- frames.py, fullmoon.py, watson.py: change "timestamp" to
  "int_timestamp"

* Resolve Issue TailorDev#407: Migrate to arrow 1.0.0

- cli.py: change "date.tzinfo = tz.tzlocal()" to "date.replace(tzinfo=tz.tzlocal())"

* Update requirements.txt

This makes sense, especially given that arrow is already up to 1.0.2

Co-authored-by: Julien Maupetit <jmaupetit@users.noreply.github.com>

* Resolve Issue TailorDev#407: Migrate to arrow 1.0.0

- watson.cli.py: use date = date.replace(tzinfo=tz.tzlocal())
  (date.replace does not modify the existing object)

* Resolve Issue TailorDev#407: Migrate to arrow 1.0.0

Update unit test cases:

- tests/test_cli.py: replace arrow.arrow.datetime with arrow.arrow.dt_datetime
- tests/test_watson.py: replace .timestamp with .int_timestamp

* Resolve Issue TailorDev#407: Migrate to arrow 1.0.0

- .travis.yml: remove python 3.5
- setup.py: require python >= 3.6
- CHANGELOG.md: mention arrow upgrade and drop of python 3.5 support

* Update watson.zsh-completion

fix: autocompletion won't work with zsh 5.8

* Use TZ environment variable to set the timezone (TailorDev#411)

Watson did not have a way to set the timezone, other than what the system used.
In UNIX you can set the TZ variable to represent the timezone you want your
programs to respect.

* Bump release to 2.0.0

Added:

- The `log` command output can now be filtered to exclude projects and
  tags via `--ignore-project` and `--ignore-tag` (TailorDev#395)
- Python 3.8 support (TailorDev#402)
- Python 3.9 support (TailorDev#402)
- Support for the TZ environment variable to specify the local time zone
  (TailorDev#391)

Changed:

- Upgrade to major arrow release 1.0.0 (TailorDev#407)

Fixed:

- Zsh completion (TailorDev#379)

Removed:

- Python 2.7 support (TailorDev#305).
- Python 3.5 support (TailorDev#407).

* Fix year in 2.0.0 release

Believe it or not its 2021!

* Gracefully handle empty stop time (TailorDev#418)

Recent arrow library update broke the current frame edition.

* Bump release to 2.0.1

Fixed:

- Ability to `edit` the current frame (TailorDev#418)

* Add 'notes' field to frames.

This is a large commit that adds the following:

1. Syntax: `watson stop --notes "some additional information"`.
2. Print only non-empty notes in log.
3. Always pass id to `new_frame` so that the length of array with/without
   notes doesn't cause ambiguity.
4. Print a warning message and the existing note if overwriting a note.
5. Print notes in report.

Primary work here was done by the following people:

Co-authored-by: Tristan Pratt <prat0088@gmail.com>
Co-authored-by: Joel Ostblom <joelostblom@users.noreply.github.com>

* notes: Print notes in `watson log`.

* notes: Fix tests.

* Set requirements for click >= 8.0 and rename autocompletion parameter to shell_complete. Remove 'multiple' paramater on reporting option

Co-authored-by: Jason Youzwak <jyouzwak@perspectalabs.com>
Co-authored-by: veganjay <veganjay@gmail.com>
Co-authored-by: Julien Maupetit <jmaupetit@users.noreply.github.com>
Co-authored-by: Nikolay Shkrylev <snnwolf@users.noreply.github.com>
Co-authored-by: Eddie Ash <cazador481@users.noreply.github.com>
Co-authored-by: Julien Maupetit <julien@maupetit.net>
Co-authored-by: Matthew Barry <komputerwiz.matt@gmail.com>
Co-authored-by: Rohitt Vashishtha <aero31aero@gmail.com>
Co-authored-by: Tristan Pratt <prat0088@gmail.com>
Co-authored-by: Joel Ostblom <joelostblom@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants