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

DEV: Update API calls to datetime functionality #117

Merged
merged 6 commits into from
Sep 16, 2024

Conversation

czgdp1807
Copy link
Contributor

@czgdp1807 czgdp1807 commented Aug 22, 2024

Continues - #114. #114 uses the latest APIs from datetime which works with Python >= 3.11. However, one needs to make it work with Python 3.9, Python 3.10 as well. For that one has to use datetime.timezone.utc and not datetime.UTC (available only in >= 3.11). See the review thread - #117 (comment)

The API calls in main are depreciated. I have updated these calls to comply with the latest versions. If I use main to build SciPy docs with myst_nb execution mode set to cache then I get the following errors,

reading sources... [  3%] reference/generated/scipy.cluster.hierarchy.DisjointSet.add .. reference/generated/scipy.fft.ifft
(Error in parallel process)
Traceback (most recent call last):
  File "/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/site-packages/sphinx/util/parallel.py", line 76, in _process
    ret = func(arg)
          ^^^^^^^^^
  File "/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 495, in read_process
    self.read_doc(docname, _cache=False)
  File "/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 536, in read_doc
    publisher.publish()
  File "/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/site-packages/docutils/core.py", line 234, in publish
    self.document = self.reader.read(self.source, self.parser,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/site-packages/sphinx/io.py", line 106, in read
    self.parse()
  File "/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/site-packages/docutils/readers/__init__.py", line 76, in parse
    self.parser.parse(self.input, document)
  File "/Users/czgdp1807/Quansight/MyST-NB/myst_nb/sphinx_.py", line 152, in parse
    with create_client(
  File "/Users/czgdp1807/Quansight/MyST-NB/myst_nb/core/execute/base.py", line 79, in __enter__
    self.start_client()
  File "/Users/czgdp1807/Quansight/MyST-NB/myst_nb/core/execute/cache.py", line 36, in start_client
    _, self._notebook = cache.merge_match_into_notebook(self.notebook)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/czgdp1807/Quansight/jupyter-cache/jupyter_cache/cache/main.py", line 357, in merge_match_into_notebook
    cache_nb = self.get_cache_bundle(pk).nb
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/czgdp1807/Quansight/jupyter-cache/jupyter_cache/cache/main.py", line 296, in get_cache_bundle
    NbCacheRecord.touch(pk, self.db)
  File "/Users/czgdp1807/Quansight/jupyter-cache/jupyter_cache/cache/db.py", line 371, in touch
    record.accessed = datetime.utcnow()
                      ^^^^^^^^^^^^^^^^^
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

Sphinx parallel build error:
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
make: *** [html-build] Error 2

With my PR I get the following,

writing additional pages... search done
copying images... [  9%] ../build/plot_directive/reference/generated/scipy-interpolate-SmoothSphereBivariateSpline-__call__-1.pn
copying images... [100%] ../build/plot_directive/tutorial/stats/sampling_srou-1.png
dumping search index in English (code: en)... done
dumping object inventory... done
[jupyterlite-sphinx] Running JupyterLite build
[jupyterlite-sphinx] JupyterLite build done
build succeeded.

The HTML pages are in build/html.

@czgdp1807
Copy link
Contributor Author

Seems like the newer API is applicable from Python 3.11 onwards.

@czgdp1807
Copy link
Contributor Author

https://github.com/executablebooks/jupyter-cache/actions/runs/10508401592/job/29112220264?pr=117 should pass by re-running.
https://results.pre-commit.ci/run/github/241082514/1724330944.ZhjaR52vT1yom94a3rWsWw - I couldn't figure out why it fails because I didn't do any of the changes where flake8 fails. Locally on my machine flake8 . passes.

@czgdp1807
Copy link
Contributor Author

Requesting @chrisjsewell @choldgraf @agoose77 for review. Thanks. <3.

Comment on lines 55 to 56
def datetime_utcnow():
if sys.version_info.minor >= 11:
return lambda: datetime.datetime.now(datetime.UTC)
return datetime.datetime.utcnow

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to test the version; datetime.datetime.now(...) works in all versions of Python supported by jupyter-cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually datetime.UTC is available only in Python >= 3.11. Let me try with datetime.datetime.now().

Copy link
Collaborator

@agoose77 agoose77 Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@czgdp1807 ah, try datetime.timezone.utc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

@czgdp1807
Copy link
Contributor Author

There is a codecov error with Python 3.10 job.

@bsipocz
Copy link
Collaborator

bsipocz commented Aug 26, 2024

This is a duplicate of #114. Either way, please let me know how I can help moving a release fwd as I run into these deprecations in a few projects, too.

@czgdp1807
Copy link
Contributor Author

@bsipocz I noticed your PR as well. I think merging this PR (this one is compatible with Python 3.9, 3.10, 3.11 and 3.12) and releasing a new version of jupyter-cache should get things going.

Requesting @agoose77 for reviewing and if possible merge this PR.

@bsipocz
Copy link
Collaborator

bsipocz commented Aug 28, 2024

Well, the other would have been compatible too two weeks ago if CI was allowed to run on it 🤷‍♀️
And if you noticed it, it would have been a minimum courtesy to at least cross-reference an existing PR before starting a new one or at least once you notice it.

@czgdp1807
Copy link
Contributor Author

Well, the other would have been compatible too two weeks ago if CI was allowed to run on it 🤷‍♀️

Please check the description of this PR. I personally don't know why CI wasn't executed on your PR. Maintainers of this repository can comment on it.

And if you noticed it, it would have been a minimum courtesy to at least cross-reference an existing PR before starting a new one or at least once you notice it.

Apologies. Referenced your PR here as well.

@bsipocz bsipocz added python Pull requests that update Python code duplicate This issue or pull request already exists labels Sep 13, 2024
@agoose77 agoose77 merged commit a5efd20 into executablebooks:main Sep 16, 2024
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants