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

Add pypy support #74

Merged
merged 3 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8']
python-version: ['3.6', '3.7', '3.8', 'pypy3']
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
tzdata_extras: ["", "tzdata"]
env:
Expand All @@ -26,7 +26,7 @@ jobs:
python -m pip install --upgrade pip tox
- name: Run tests
run: |
tox
python -m tox
- name: Report coverage
run: |
tox -e coverage-report,codecov
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `backports.zoneinfo`: Backport of the standard library module `zoneinfo`

This package was originally the reference implementation for [PEP 615](https://www.python.org/dev/peps/pep-0615/), which proposes support for the IANA time zone database in the standard library, and now serves as a backport to Python 3.6+.
This package was originally the reference implementation for [PEP 615](https://www.python.org/dev/peps/pep-0615/), which proposes support for the IANA time zone database in the standard library, and now serves as a backport to Python 3.6+ (including PyPy).

This exposes the `backports.zoneinfo` module, which is a backport of the [`zoneinfo`](https://docs.python.org/3.9/library/zoneinfo.html#module-zoneinfo) module. The backport's documentation can be found [on readthedocs](https://zoneinfo.readthedocs.io/en/latest/).

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

This was originally the reference implementation for :pep:`615`, which adds
support for the IANA time zone database to the Python standard library, but now
serves as a backport of the module to Python 3.6+.
serves as a backport of the module to Python 3.6+ (including PyPy).

The upstream documentation can be found at :mod:`zoneinfo`. A mirror of the
documentation pinned to the version supported in the backport can be found at
Expand Down
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import os
import platform

import setuptools
from setuptools import Extension

c_extension = Extension(
"backports.zoneinfo._czoneinfo", sources=["lib/zoneinfo_module.c"],
)
if platform.python_implementation() != "PyPy":
c_extension = Extension(
"backports.zoneinfo._czoneinfo", sources=["lib/zoneinfo_module.c"],
)

setuptools.setup(ext_modules=[c_extension])
else:
setuptools.setup()

setuptools.setup(ext_modules=[c_extension])

if "GCNO_TARGET_DIR" in os.environ:
import glob
Expand Down
11 changes: 10 additions & 1 deletion tests/_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import functools
import platform
import sys
import threading
import unittest
Expand All @@ -9,6 +10,8 @@
TZPATH_LOCK = threading.Lock()
TZPATH_TEST_LOCK = threading.Lock()

IS_PYPY = platform.python_implementation() == "PyPy"


def call_once(f):
"""Decorator that ensures a function is only ever called once."""
Expand All @@ -33,6 +36,13 @@ def get_modules():
one time — in other words, when using this function you will only ever
get one copy of each module rather than a fresh import each time.
"""
# PyPy doesn't have a C extension, so for the moment we'll just give it
# two copies of the normal module
if IS_PYPY:
from backports import zoneinfo

return zoneinfo, zoneinfo

# The standard import_fresh_module approach seems to be somewhat buggy
# when it comes to C imports, so in the short term, we will do a little
# module surgery to test this.
Expand All @@ -45,7 +55,6 @@ def get_modules():

py_module.ZoneInfo = py_zoneinfo.ZoneInfo
c_module.ZoneInfo = c_zoneinfo.ZoneInfo

return py_module, c_module


Expand Down
3 changes: 2 additions & 1 deletion tests/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from datetime import date, datetime, time, timedelta, timezone

from . import _support as test_support
from ._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase
from ._support import IS_PYPY, OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase

try:
from functools import cached_property
Expand Down Expand Up @@ -1771,6 +1771,7 @@ class CTestModule(TestModule):
module = c_zoneinfo


@unittest.skipIf(IS_PYPY, "C Extension not built on PyPy")
class ExtensionBuiltTest(unittest.TestCase):
"""Smoke test to ensure that the C and Python extensions are both tested.

Expand Down