Skip to content

Commit

Permalink
Merge 08c89b8 into 3c682d0
Browse files Browse the repository at this point in the history
  • Loading branch information
pganssle committed Jun 20, 2019
2 parents 3c682d0 + 08c89b8 commit 2556de3
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 232 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ build
dist
*.egg*
*.py[co]
.tox
.coverage
docs/_*
datetime_tz/win32tz_map.py
py2
py3
release_venv
venv
venv3
21 changes: 11 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
language: python
python:
- 2.6
- 2.7
- 3.3
- 3.4
- 3.6
- nightly

matrix:
include:
# Required to run Python 3.7
- python: 3.7
dist: xenial
sudo: required
allow_failures:
- python: nightly


sudo: false

cache:
Expand All @@ -19,15 +23,12 @@ cache:

install:
- pip install --upgrade pip
- pip install pyopenssl ndg-httpsclient pyasn1
- pip install -r requirements.txt
- python setup.py install
- python run_tests_all_pytz.py --download-only
- pip install --upgrade tox

script:
- python run_tests_all_pytz.py
- ./test_multiple_pytz_versions.sh
- tox -e py

after_success:
- pip install coveralls
- coverage run --source=datetime_tz setup.py test
- coveralls
- coveralls # Coverage generated by tox run
2 changes: 1 addition & 1 deletion datetime_tz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def smartparse(cls, toparse, tzinfo=None):
if isinstance(dt.tzinfo, pytz_abbr.tzabbr):
abbr = dt.tzinfo
dt = dt.replace(tzinfo=None)
dt = cls(dt, abbr.zone, is_dst=abbr.dst)
dt = cls(dt, abbr.zone, is_dst=abbr.is_dst)

dt = cls(dt)

Expand Down
7 changes: 6 additions & 1 deletion datetime_tz/detect_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ def _detect_timezone_windows():
win32timezone.TimeZoneInfo._get_indexed_time_zone_keys("Std"))
win32tz_key_name = win32timezone_to_en.get(win32tz_name, win32tz_name)

territory = locale.getdefaultlocale()[0].split("_", 1)[1]
language_code = locale.getdefaultlocale()[0]
if language_code is None:
# Failure getting the system locale, result may be wrong!
territory = None
else:
territory = language_code.split("_", 1)[1]
olson_name = win32tz_map.win32timezones.get((win32tz_key_name, territory), win32tz_map.win32timezones.get(win32tz_key_name, None))
if not olson_name:
return None
Expand Down
61 changes: 50 additions & 11 deletions datetime_tz/pytz_abbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,63 @@
import pytz
import pytz.tzfile

try:
basestring
except NameError:
# pylint: disable=redefined-builtin
basestring = str


class tzabbr(datetime.tzinfo):
"""A timezone abbreviation.
*WARNING*: This is not a tzinfo implementation! Trying to use this as tzinfo
object will result in failure. We inherit from datetime.tzinfo so we can get
through the dateutil checks.
*WARNING*: This is a proxy object for an underlying `pytz` object only
intended to allow dateutil to probe the localized datetime for information.
datetime_tz's parsing logic will replace it with the relevant pytz zone
before returning to the end user.
"""
pass

def __init__(self, abbr, name, region, zone, dst):
super(tzabbr, self).__init__()

self.abbr = abbr
self.name = name
self.region = region

if isinstance(zone, basestring):
zone = pytz.timezone(zone)

self.zone = zone
self.is_dst = dst

def _get_localized(self, dt):
# To make this a fully-functioning pass-through to the underlying pytz
# zone, we would want to use `fold` to set `is_dst`, but since this is
# only a temporary proxy for the zone, we will fix the DST status
return self.zone.localize(dt.replace(tzinfo=None), is_dst=self.is_dst)

def tzname(self, dt):
return self._get_localized(dt).tzname()

def utcoffset(self, dt):
return self._get_localized(dt).utcoffset() # pragma: no cover

def dst(self, dt):
return self._get_localized(dt).dst() # pragma: no cover


# A "marker" tzinfo object which is used to signify an unknown timezone.
unknown = datetime.tzinfo()
class _UnknownZone(datetime.tzinfo):
def tzname(self, dt):
return "UNK"

def dst(self, dt):
return None

def utcoffset(self, dt):
return datetime.timedelta(0) # pragma: no cover

unknown = _UnknownZone()


regions = {"all": {}, "military": {}}
Expand All @@ -74,12 +118,7 @@ def tzabbr_register(abbr, name, region, zone, dst):
If another abbreviation with the same name has already been registered it new
abbreviation will only be registered in region specific dictionary.
"""
newabbr = tzabbr()
newabbr.abbr = abbr
newabbr.name = name
newabbr.region = region
newabbr.zone = zone
newabbr.dst = dst
newabbr = tzabbr(abbr, name, region, zone, dst)

if abbr not in all:
all[abbr] = newabbr
Expand Down
2 changes: 1 addition & 1 deletion datetime_tz/update_win32tz_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
win32tz_map = None


_CLDR_WINZONES_URL = "http://www.unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml" # pylint: disable=line-too-long
_CLDR_WINZONES_URL = "https://github.com/unicode-org/cldr/raw/master/common/supplemental/windowsZones.xml" # pylint: disable=line-too-long


def download_cldr_win32tz_map_xml():
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build-system]
requires = [
"setuptools>=41.0",
"wheel",
"Genshi",
"python-dateutil>=2.0",
"pytz >= 2011g",
]
build-backend = "setuptools.build_meta"
42 changes: 12 additions & 30 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
#!/bin/bash

rm -rf py2
virtualenv-2.7 py2
#!/bin/bash -e
rm -rf release_env
rm -rf dist/
python3 -m virtualenv release_env
source release_env/bin/activate
(
. py2/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install -r requirements.txt
pip install wheel
python setup.py clean
python setup.py sdist
python setup.py bdist_wheel
python setup.py sdist upload
python setup.py bdist_wheel upload
#PS1="py2setup # " bash --norc
)
pip install -U pip
pip install -U twine
pip install -U pep517
# Run the build
python -m pep517.build . -b -s

rm -rf py3
virtualenv-3.4 py3
(
. py3/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install wheel
pip install -r requirements.txt
python setup.py clean
python setup.py sdist
python setup.py bdist_wheel
python setup.py sdist upload
python setup.py bdist_wheel upload
#PS1="py3setup # " bash --norc
# Upload the files with twine
twine upload dist/*
)
148 changes: 0 additions & 148 deletions run_tests_all_pytz.py

This file was deleted.

0 comments on commit 2556de3

Please sign in to comment.