Skip to content

Commit

Permalink
Merge pull request #64 from pganssle/backports_migration
Browse files Browse the repository at this point in the history
Move module into backports namespace
  • Loading branch information
pganssle authored May 20, 2020
2 parents 6a1256a + e06878f commit ebbb76e
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 28 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ recursive-include licenses *
graft .github

# Stubs
include src/zoneinfo/py.typed
include src/backports/zoneinfo/py.typed
recursive-include src *.pyi

# Tests
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# -- Project information -----------------------------------------------------

project = "zoneinfo"
project = "backports.zoneinfo"
author = "Paul Ganssle"
copyright = f"2020, {author}"

Expand Down
9 changes: 5 additions & 4 deletions lib/zoneinfo_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,7 @@ static PyMemberDef zoneinfo_members[] = {

static PyTypeObject PyZoneInfo_ZoneInfoType = {
PyVarObject_HEAD_INIT(NULL, 0) //
.tp_name = "zoneinfo.ZoneInfo",
.tp_name = "backports.zoneinfo.ZoneInfo",
.tp_basicsize = sizeof(PyZoneInfo_ZoneInfo),
.tp_weaklistoffset = offsetof(PyZoneInfo_ZoneInfo, weakreflist),
.tp_repr = (reprfunc)zoneinfo_repr,
Expand Down Expand Up @@ -2628,7 +2628,8 @@ zoneinfomodule_exec(PyObject *m)
PyModule_AddObject(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType);

/* Populate imports */
PyObject *_tzpath_module = PyImport_ImportModule("zoneinfo._tzpath");
PyObject *_tzpath_module =
PyImport_ImportModule("backports.zoneinfo._tzpath");
if (_tzpath_module == NULL) {
goto error;
}
Expand All @@ -2651,7 +2652,7 @@ zoneinfomodule_exec(PyObject *m)
goto error;
}

_common_mod = PyImport_ImportModule("zoneinfo._common");
_common_mod = PyImport_ImportModule("backports.zoneinfo._common");
if (_common_mod == NULL) {
goto error;
}
Expand Down Expand Up @@ -2681,7 +2682,7 @@ static PyModuleDef_Slot zoneinfomodule_slots[] = {

static struct PyModuleDef zoneinfomodule = {
PyModuleDef_HEAD_INIT,
.m_name = "zoneinfo._czoneinfo",
.m_name = "backports.zoneinfo._czoneinfo",
.m_doc = "C implementation of the zoneinfo module",
.m_size = 0,
.m_methods = module_methods,
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ build-backend = "setuptools.build_meta"
line-length = 80

[tool.coverage.run]
source = ["zoneinfo"]
omit = ["tests/typing_example.py"]

[tool.coverage.paths]
Expand All @@ -20,6 +19,16 @@ skip_covered = true
atomic=true
force_grid_wrap=0
include_trailing_comma=true
known_first_party = ["backports.zoneinfo"]
known_third_party=[
"click",
"dateutil",
"hypothesis",
"pint",
"pytest",
"pytz",
"requests",
]
multi_line_output=3
not_skip="__init__.py"
use_parentheses=true
6 changes: 3 additions & 3 deletions scripts/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from datetime import datetime, timedelta, timezone

import click

import pint
import pytz
from dateutil import tz
from zoneinfo import ZoneInfo
from zoneinfo._zoneinfo import ZoneInfo as PyZoneInfo

from backports.zoneinfo import ZoneInfo
from backports.zoneinfo._zoneinfo import ZoneInfo as PyZoneInfo

_PINT_REGISTRY = pint.UnitRegistry()
S = _PINT_REGISTRY.s
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import textwrap
import typing

import zoneinfo
import backports.zoneinfo as zoneinfo

KEYS = [
"Africa/Abidjan",
Expand Down
11 changes: 6 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[metadata]
name = zoneinfo
version = attr:zoneinfo._version.__version__
name = backports.zoneinfo
version = attr:backports.zoneinfo._version.__version__
description = Backport of the standard library zoneinfo module
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/python/cpython
url = https://github.com/pganssle/zoneinfo
author = Python Software Foundation
author_email = [email protected]
license = Apache-2.0
Expand All @@ -20,8 +20,9 @@ classifiers =
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
project_urls =
Bug Reports = https://bugs.python.org
Source = https://github.com/python/cpython
Source = https://github.com/pganssle/zoneinfo
Documentation = https://zoneinfo.readthedocs.io/en/latest/
Bug Reports = https://github.com/pganssle/zoneinfo/issues

[options]
packages = find:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import Extension

c_extension = Extension(
"zoneinfo._czoneinfo", sources=["lib/zoneinfo_module.c"],
"backports.zoneinfo._czoneinfo", sources=["lib/zoneinfo_module.c"],
)

setuptools.setup(ext_modules=[c_extension])
Expand Down
5 changes: 5 additions & 0 deletions src/backports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A Python "namespace package" http://www.python.org/dev/peps/pep-0382/
# This always goes inside of a namespace package's __init__.py
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__) # type: ignore
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ZoneInfo(tzinfo):
_strong_cache_size = 8
_strong_cache = collections.OrderedDict()
_weak_cache = weakref.WeakValueDictionary()
__module__ = "zoneinfo"
__module__ = "backports.zoneinfo"

def __init_subclass__(cls):
cls._strong_cache = collections.OrderedDict()
Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions tests/_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def get_modules():
# 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.
py_module, c_module = (import_fresh_module("zoneinfo") for _ in range(2))
py_module, c_module = (
import_fresh_module("backports.zoneinfo") for _ in range(2)
)

from zoneinfo import _zoneinfo as py_zoneinfo
from zoneinfo import _czoneinfo as c_zoneinfo
from backports.zoneinfo import _zoneinfo as py_zoneinfo
from backports.zoneinfo import _czoneinfo as c_zoneinfo

py_module.ZoneInfo = py_zoneinfo.ZoneInfo
c_module.ZoneInfo = c_zoneinfo.ZoneInfo
Expand All @@ -57,11 +59,11 @@ def set_zoneinfo_module(module):
"""

NOT_PRESENT = object()
old_zoneinfo = sys.modules.get("zoneinfo", NOT_PRESENT)
sys.modules["zoneinfo"] = module
old_zoneinfo = sys.modules.get("backports.zoneinfo", NOT_PRESENT)
sys.modules["backports.zoneinfo"] = module
yield
if old_zoneinfo is not NOT_PRESENT:
sys.modules["zoneinfo"] = old_zoneinfo
sys.modules["backports.zoneinfo"] = old_zoneinfo


class ZoneInfoTestBase(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_zoneinfo_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import hypothesis
import pytest
import zoneinfo

from backports import zoneinfo

from . import _support as test_support
from ._support import ZoneInfoTestBase
Expand Down
2 changes: 1 addition & 1 deletion tests/typing_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from typing import Callable, Optional, Sequence, Set, Tuple

import zoneinfo
import backports.zoneinfo as zoneinfo

REGISTERED_FUNCTIONS = []

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setenv =
COVERAGE_FILE={toxworkdir}/.coverage/.coverage.{envname}
CFLAGS={env:CFLAGS:-UNDEBUG}
commands =
pytest {toxinidir} {posargs: --cov=zoneinfo --cov=tests}
pytest {toxinidir} {posargs: --cov=backports.zoneinfo --cov=tests}

# This should probably be integrated into the main testenv as an option if such
# a thing is possible, but because it's more important that it runs on CI and
Expand Down Expand Up @@ -115,7 +115,7 @@ description = Run mypy on the testing example
deps =
mypy
commands =
mypy src/zoneinfo/__init__.pyi
mypy src/backports/zoneinfo/__init__.pyi
mypy tests/typing_example.py
mypy scripts/update_test_data.py

Expand Down

0 comments on commit ebbb76e

Please sign in to comment.