Skip to content

Commit

Permalink
更新PyPI包名为GB2260-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhao.chen committed Apr 17, 2019
1 parent 27bef77 commit f6b6378
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 79 deletions.
5 changes: 2 additions & 3 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[bumpversion]
files = setup.py gb2260/__init__.py
files = setup.py gb2260_v2/__init__.py
commit = True
tag = True
current_version = 0.4.1

current_version = 0.2.0
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = gb2260/data/*
omit = gb2260_v2/data/*
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ __pycache__
/.idea
/.python-version
.pytest_cache/
gb2260/data/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- "2.7"
- "3.3"
- "3.4"
- "3.7"
- "pypy"
install:
- "pip install pytest pytest-cov pytest-pep8 pytest-mock coveralls"
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ TOX := tox

all: build

build: gb2260/data/__init__.py
build: gb2260_v2/data/__init__.py
$(PYTHON) setup.py sdist bdist_wheel

test: gb2260/data/__init__.py
test: gb2260_v2/data/__init__.py
$(PYTEST)

test-all: gb2260/data/__init__.py
test-all: gb2260_v2/data/__init__.py
$(TOX)

clean:
rm -rf dist build gb2260/data/
rm -rf dist build *.egg-info gb2260_v2/data/

gb2260/data/__init__.py: data/revisions.json
gb2260_v2/data/__init__.py: data/revisions.json
$(PYTHON) generate.py $?
1 change: 0 additions & 1 deletion gb2260/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions gb2260_v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
10 changes: 5 additions & 5 deletions gb2260/__init__.py → gb2260_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

from gb2260.gb2260 import GB2260
from gb2260.exceptions import (
from __future__ import absolute_import, unicode_literals

from gb2260_v2.exceptions import (
GB2260Exception,
InvalidCode,
RevisionNotFound,
SourceNotFound,
)

from gb2260_v2.gb2260 import GB2260

__all__ = [
'GB2260',
Expand Down
7 changes: 3 additions & 4 deletions gb2260/_compat.py → gb2260_v2/_compat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

import sys
from __future__ import absolute_import, unicode_literals

import sys

PY2 = sys.version_info[0] == 2


if PY2:
text_type = unicode
binary_type = str
Expand Down
9 changes: 4 additions & 5 deletions gb2260/code.py → gb2260_v2/code.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

import re
from __future__ import absolute_import, unicode_literals

from gb2260.exceptions import InvalidCode
import re

from gb2260_v2.exceptions import InvalidCode

# GB/T 2260 conformant code pattern.
# Every two digits form a province / prefecture / county layer subcode.
Expand All @@ -13,7 +13,6 @@
CODE_PATTERN = re.compile(
r'^(?P<province>\d\d)(?P<prefecture>\d\d)(?P<county>\d\d)$')


# The following province / prefecture / county code patterns are from the Spec.
# Subcode 00 is considered special, denoting the upper level division.
# When used as an argument, trailing 00s can be ommited.
Expand Down
9 changes: 4 additions & 5 deletions gb2260/division.py → gb2260_v2/division.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import gb2260.code as dcode
from gb2260._compat import ensure_str
import gb2260_v2.code as dcode
from gb2260_v2._compat import ensure_str


class Division(object):

__slots__ = ['_code', '_name', '_revision']

def __init__(self, code, name, revision):
Expand Down
5 changes: 3 additions & 2 deletions gb2260/exceptions.py → gb2260_v2/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals


class GB2260Exception(Exception):
Expand Down
8 changes: 4 additions & 4 deletions gb2260/gb2260.py → gb2260_v2/gb2260.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

from gb2260.revision import Source
from __future__ import absolute_import, unicode_literals

from gb2260_v2.revision import Source


# GB2260 is mainly a proxy object for Source & Revision


class GB2260(object):

source = Source('curated')

__slots__ = ['revision']
Expand Down
17 changes: 9 additions & 8 deletions gb2260/revision.py → gb2260_v2/revision.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

import gb2260.code as dcode
from gb2260._compat import ensure_text, iteritems
from gb2260.division import Division
from gb2260.exceptions import RevisionNotFound, SourceNotFound
from __future__ import absolute_import, unicode_literals

import gb2260_v2.code as dcode
from gb2260_v2._compat import ensure_text, iteritems
from gb2260_v2.division import Division
from gb2260_v2.exceptions import RevisionNotFound, SourceNotFound


def _import_module(name):
Expand Down Expand Up @@ -81,7 +82,7 @@ class Source(object):
__slots__ = ['all_revisions', 'name']

def __init__(self, name):
module_name = 'gb2260.data.{0}'.format(name)
module_name = 'gb2260_v2.data.{0}'.format(name)
try:
module = _import_module(module_name)
except ImportError:
Expand All @@ -95,7 +96,7 @@ def latest_revision(self):
return self.all_revisions[0]

def load_revision(self, name):
module_name = 'gb2260.data.{0}.revision_{1}'.format(self.name, name)
module_name = 'gb2260_v2.data.{0}.revision_{1}'.format(self.name, name)
try:
module = _import_module(module_name)
except ImportError:
Expand Down
7 changes: 3 additions & 4 deletions generate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
A script to generate the data module.
Expand All @@ -12,13 +13,11 @@
import os
import sys


if sys.version_info[0] == 2:
imap = itertools.imap
else:
imap = map


TAB_CHAR = ' ' * 4


Expand Down Expand Up @@ -89,7 +88,7 @@ def main():

revisions = gb_revisions | stats_revisions | mca_revisions

output_dir = os.path.join('gb2260', 'data')
output_dir = os.path.join('gb2260_v2', 'data')
source_dir = os.path.join(output_dir, 'curated')

if not os.path.exists(output_dir):
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[tool:pytest]
addopts = --pep8 --cov gb2260
addopts = --pep8 --cov gb2260_v2
norecursedirs = .tox .git build data dist *.egg-info __pycache__
pep8ignore =
data/* ALL
gb2260/data.py ALL
gb2260_v2/* ALL

[bdist_wheel]
universal = 1
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup
from setuptools import setup, find_packages


def fread(filepath, skip_lines=0):
Expand All @@ -9,12 +10,10 @@ def fread(filepath, skip_lines=0):


setup(
name='GB2260',
version='0.4.1',
author='Jiangge Zhang',
author_email='[email protected]',
url='https://github.com/cn/GB2260.py',
packages=['gb2260'],
name='GB2260-v2',
version='0.2.0',
url='https://github.com/bosndata/GB2260.py',
packages=find_packages(exclude=('tests', 'tests.*')),
description='The Python implementation for looking up the Chinese '
'administrative divisions.',
long_description=fread('README.rst', skip_lines=2),
Expand All @@ -29,6 +28,7 @@ def fread(filepath, skip_lines=0):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
]
Expand Down
9 changes: 5 additions & 4 deletions tests/test_code.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest

import gb2260.code as dcode
from gb2260.exceptions import InvalidCode
import gb2260_v2.code as dcode
from gb2260_v2.exceptions import InvalidCode


class TestCodePattern(object):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_division.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

from __future__ import absolute_import, unicode_literals

import pytest

from gb2260.division import Division
from gb2260.revision import Revision
from gb2260_v2.division import Division
from gb2260_v2.revision import Revision


@pytest.fixture
Expand Down Expand Up @@ -60,18 +60,18 @@ def test_description(revision, division):


def test_is_province(mocker, division):
mocked = mocker.patch('gb2260.code.PROVINCE_CODE_PATTERN')
mocked = mocker.patch('gb2260_v2.code.PROVINCE_CODE_PATTERN')
division.is_province
mocked.match.assert_called_once_with(division.code)


def test_is_prefecture(mocker, division):
mocked = mocker.patch('gb2260.code.PREFECTURE_CODE_PATTERN')
mocked = mocker.patch('gb2260_v2.code.PREFECTURE_CODE_PATTERN')
division.is_prefecture
mocked.match.assert_called_once_with(division.code)


def test_is_county(mocker, division):
mocked = mocker.patch('gb2260.code.COUNTY_CODE_PATTERN')
mocked = mocker.patch('gb2260_v2.code.COUNTY_CODE_PATTERN')
division.is_county
mocked.match.assert_called_once_with(division.code)
9 changes: 5 additions & 4 deletions tests/test_gb2260.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import pytest

from gb2260.revision import Revision, Source
from gb2260.gb2260 import GB2260
from gb2260_v2.gb2260 import GB2260
from gb2260_v2.revision import Revision, Source


@pytest.fixture
Expand Down
12 changes: 6 additions & 6 deletions tests/test_revision.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

from __future__ import absolute_import, unicode_literals

import pytest

from gb2260.exceptions import RevisionNotFound, SourceNotFound
from gb2260.revision import Revision, Source
from gb2260_v2.exceptions import RevisionNotFound, SourceNotFound
from gb2260_v2.revision import Revision, Source


@pytest.fixture
def mocked_source(mocker):
source = mocker.patch('gb2260.data.curated')
source = mocker.patch('gb2260_v2.data.curated')
source.revisions = ['198012', '200212']
return source


@pytest.fixture
def mocked_revision(mocker, mocked_source):
revision = mocker.patch('gb2260.data.curated.revision_198012')
revision = mocker.patch('gb2260_v2.data.curated.revision_198012')
revision.name = '198012'
revision.division_schema = {
'990000': '测试省',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,py33,py34,pypy
envlist = py26,py27,py33,py34,py37,pypy
[testenv]
whitelist_externals = make
deps =
Expand Down

0 comments on commit f6b6378

Please sign in to comment.