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

Do not depend on pkg_resources module #42

Merged
merged 1 commit into from
Jun 23, 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
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ load-plugins=
persistent = no
jobs = 0
unsafe-load-any-extension = yes
good-names = wc
good-names = wc,fp

[MESSAGES CONTROL]
disable=
Expand Down
2 changes: 1 addition & 1 deletion bin/new-wide-by-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
previous version (4.1.0).
"""
# std imports
import json
import sys
import json


# List new WIDE characters at each unicode version.
Expand Down
11 changes: 3 additions & 8 deletions bin/run_codecov.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
"""
Workaround for https://github.com/codecov/codecov-python/issues/158
"""
"""Workaround for https://github.com/codecov/codecov-python/issues/158."""

# std imports
import sys
import time

# local
# 3rd party
import codecov

RETRIES = 5
TIMEOUT = 2


def main():
"""
Run codecov up to RETRIES times
On the final attempt, let it exit normally
"""
"""Run codecov up to RETRIES times On the final attempt, let it exit normally."""

# Make a copy of argv and make sure --required is in it
args = sys.argv[1:]
Expand Down
37 changes: 28 additions & 9 deletions bin/update-tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
do_east_asian(versions)
do_zero_width(versions)
do_rst_file_update()
do_version_json(versions)
do_unicode_versions(versions)


def get_unicode_versions():
Expand Down Expand Up @@ -297,18 +297,37 @@ def do_write_table(fname, variable, table):
print("complete.")


def do_version_json(versions):
fname = os.path.join(PATH_CODE, 'version.json')
def do_unicode_versions(versions):
"""Write unicode_versions.py function list_versions()."""
fname = os.path.join(PATH_CODE, 'unicode_versions.py')
print(f"writing {fname} ... ", end='')

with open(fname, 'r') as fp:
version_data = json.load(fp)
utc_now = datetime.datetime.utcnow()
version_tuples_str = '\n '.join(
f'"{ver}",' for ver in versions)
with open(fname, 'w') as fp:
fp.write(f"""\"\"\"
Exports function list_versions() for unicode version level support.

version_data['tables'] = versions
This code generated by {__file__} on {utc_now}.
\"\"\"

with open(fname, 'w') as fp:
json.dump(version_data, fp)
print()

def list_versions():
\"\"\"
Return Unicode version levels supported by this module release.

Any of the version strings returned may be used as keyword argument
``unicode_version`` to the ``wcwidth()`` family of functions.

:returns: Supported Unicode version numbers in ascending sorted order.
:rtype: list[str]
\"\"\"
return (
{version_tuples_str}
)
""")
print('done.')


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion bin/wcwidth-browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def _process_keystroke_movement(self, inp, idx, offset):
# scroll backward 1 line
offset -= self.screen.num_columns
elif inp in ('e', 'j') or inp.code in (term.KEY_ENTER,
term.KEY_DOWN,):
term.KEY_DOWN,):
# scroll forward 1 line
offset = offset + self.screen.num_columns
elif inp in ('f', ' ') or inp.code in (term.KEY_PGDOWN,):
Expand Down
8 changes: 1 addition & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ def _get_here(fname):
return os.path.join(os.path.dirname(__file__), fname)


def _get_version(fname, key='package'):
import json
return json.load(open(fname, 'r'))[key]


class _SetupUpdate(setuptools.Command):
# This is a compatibility, some downstream distributions might
# still call "setup.py update".
Expand Down Expand Up @@ -49,8 +44,7 @@ def main():
setuptools.setup(
name='wcwidth',
# NOTE: manually manage __version__ in wcwidth/__init__.py !
version=_get_version(
_get_here(os.path.join('wcwidth', 'version.json'))),
version='0.2.5',
description=(
"Measures the displayed width of unicode strings in a terminal"),
long_description=codecs.open(
Expand Down
14 changes: 0 additions & 14 deletions tests/test_ucslevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@
import wcwidth


def test_list_versions():
"""wcwidth.list_versions() returns expected value."""
# given,
expected = json.loads(
pkg_resources.resource_string('wcwidth', 'version.json').decode('utf8')
)['tables']

# exercise,
result = wcwidth.list_versions()

# verify,
assert result == expected


def test_latest():
"""wcwidth._wcmatch_version('latest') returns tail item."""
# given,
Expand Down
6 changes: 5 additions & 1 deletion wcwidth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
# these always bit me, too, so I can sympathize -- this version is now manually
# kept in sync with version.json to help them out. Shucks, this variable is just
# for legacy, from the days before 'pip freeze' was a thing.
__version__ = '0.2.4'
#
# We also used pkg_resources to load unicode version tables from version.json,
# generated by bin/update-tables.py, but some environments are unable to
# import pkg_resources for one reason or another, yikes!
__version__ = '0.2.5'
2 changes: 1 addition & 1 deletion wcwidth/table_wide.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Wide_Eastasian table, created by bin/update-tables.py."""
# Generated: 2020-06-01T15:38:29.249643
# Generated: 2020-06-23T15:58:41.860748
WIDE_EASTASIAN = {
'4.1.0': (
# Source: EastAsianWidth-4.1.0.txt
Expand Down
2 changes: 1 addition & 1 deletion wcwidth/table_zero.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Zero_Width table, created by bin/update-tables.py."""
# Generated: 2020-06-01T15:38:31.292746
# Generated: 2020-06-23T15:58:43.900697
ZERO_WIDTH = {
'4.1.0': (
# Source: DerivedGeneralCategory-4.1.0.txt
Expand Down
35 changes: 35 additions & 0 deletions wcwidth/unicode_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Exports function list_versions() for unicode version level support.

This code generated by bin/update-tables.py on 2020-06-23 15:58:44.035540.
"""


def list_versions():
"""
Return Unicode version levels supported by this module release.

Any of the version strings returned may be used as keyword argument
``unicode_version`` to the ``wcwidth()`` family of functions.

:returns: Supported Unicode version numbers in ascending sorted order.
:rtype: list[str]
"""
return (
"4.1.0",
"5.0.0",
"5.1.0",
"5.2.0",
"6.0.0",
"6.1.0",
"6.2.0",
"6.3.0",
"7.0.0",
"8.0.0",
"9.0.0",
"10.0.0",
"11.0.0",
"12.0.0",
"12.1.0",
"13.0.0",
)
1 change: 0 additions & 1 deletion wcwidth/version.json

This file was deleted.

37 changes: 1 addition & 36 deletions wcwidth/wcwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@
# std imports
import os
import sys
import json
import warnings

# 3rd party
import pkg_resources

# local
from .table_wide import WIDE_EASTASIAN
from .table_zero import ZERO_WIDTH
from .unicode_versions import list_versions

try:
from functools import lru_cache
Expand Down Expand Up @@ -252,25 +249,6 @@ def wcswidth(pwcs, n=None, unicode_version='auto'):
return width


@lru_cache(maxsize=1)
def list_versions():
"""
Return Unicode version levels supported by this module release.

Any of the version strings returned may be used as keyword argument
``unicode_version`` to the ``wcwidth()`` family of functions.

:returns: Supported Unicode version numbers in ascending sorted order.
:rtype: list[str]
"""
# load from 'version.json', use setuptools to access
# resource string so that the package is zip/wheel-compatible.
return json.loads(
pkg_resources.resource_string(
'wcwidth', "version.json"
).decode('utf8'))['tables']


@lru_cache(maxsize=128)
def _wcversion_value(ver_string):
"""
Expand Down Expand Up @@ -395,16 +373,3 @@ def _wcmatch_version(given_version):
if cmp_next_version > cmp_given:
return unicode_version
assert False, ("Code path unreachable", given_version, unicode_versions)


def _get_package_version():
"""
Version of wcwidth (produces module-level ``__version__`` val).

:rtype: str
:return: the version of the wcwidth library package.
"""
return json.loads(
pkg_resources.resource_string(
'wcwidth', "version.json"
).decode('utf8'))['package']