Skip to content

Commit 29c32b3

Browse files
authored
Do not depend on pkg_resources module (#42)
Generate code for `wcwidth/unicode_versions.py`, delete `wcwidth/version.json`, and all references to it.
1 parent 28f0fe5 commit 29c32b3

File tree

13 files changed

+78
-81
lines changed

13 files changed

+78
-81
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ load-plugins=
99
persistent = no
1010
jobs = 0
1111
unsafe-load-any-extension = yes
12-
good-names = wc
12+
good-names = wc,fp
1313

1414
[MESSAGES CONTROL]
1515
disable=

bin/new-wide-by-version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
previous version (4.1.0).
1616
"""
1717
# std imports
18-
import json
1918
import sys
19+
import json
2020

2121

2222
# List new WIDE characters at each unicode version.

bin/run_codecov.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
"""
2-
Workaround for https://github.com/codecov/codecov-python/issues/158
3-
"""
1+
"""Workaround for https://github.com/codecov/codecov-python/issues/158."""
42

53
# std imports
64
import sys
75
import time
86

9-
# local
7+
# 3rd party
108
import codecov
119

1210
RETRIES = 5
1311
TIMEOUT = 2
1412

1513

1614
def main():
17-
"""
18-
Run codecov up to RETRIES times
19-
On the final attempt, let it exit normally
20-
"""
15+
"""Run codecov up to RETRIES times On the final attempt, let it exit normally."""
2116

2217
# Make a copy of argv and make sure --required is in it
2318
args = sys.argv[1:]

bin/update-tables.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def main():
6262
do_east_asian(versions)
6363
do_zero_width(versions)
6464
do_rst_file_update()
65-
do_version_json(versions)
65+
do_unicode_versions(versions)
6666

6767

6868
def get_unicode_versions():
@@ -297,18 +297,37 @@ def do_write_table(fname, variable, table):
297297
print("complete.")
298298

299299

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

304-
with open(fname, 'r') as fp:
305-
version_data = json.load(fp)
305+
utc_now = datetime.datetime.utcnow()
306+
version_tuples_str = '\n '.join(
307+
f'"{ver}",' for ver in versions)
308+
with open(fname, 'w') as fp:
309+
fp.write(f"""\"\"\"
310+
Exports function list_versions() for unicode version level support.
306311
307-
version_data['tables'] = versions
312+
This code generated by {__file__} on {utc_now}.
313+
\"\"\"
308314
309-
with open(fname, 'w') as fp:
310-
json.dump(version_data, fp)
311-
print()
315+
316+
def list_versions():
317+
\"\"\"
318+
Return Unicode version levels supported by this module release.
319+
320+
Any of the version strings returned may be used as keyword argument
321+
``unicode_version`` to the ``wcwidth()`` family of functions.
322+
323+
:returns: Supported Unicode version numbers in ascending sorted order.
324+
:rtype: list[str]
325+
\"\"\"
326+
return (
327+
{version_tuples_str}
328+
)
329+
""")
330+
print('done.')
312331

313332

314333
if __name__ == '__main__':

bin/wcwidth-browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def _process_keystroke_movement(self, inp, idx, offset):
489489
# scroll backward 1 line
490490
offset -= self.screen.num_columns
491491
elif inp in ('e', 'j') or inp.code in (term.KEY_ENTER,
492-
term.KEY_DOWN,):
492+
term.KEY_DOWN,):
493493
# scroll forward 1 line
494494
offset = offset + self.screen.num_columns
495495
elif inp in ('f', ' ') or inp.code in (term.KEY_PGDOWN,):

setup.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ def _get_here(fname):
1616
return os.path.join(os.path.dirname(__file__), fname)
1717

1818

19-
def _get_version(fname, key='package'):
20-
import json
21-
return json.load(open(fname, 'r'))[key]
22-
23-
2419
class _SetupUpdate(setuptools.Command):
2520
# This is a compatibility, some downstream distributions might
2621
# still call "setup.py update".
@@ -49,8 +44,7 @@ def main():
4944
setuptools.setup(
5045
name='wcwidth',
5146
# NOTE: manually manage __version__ in wcwidth/__init__.py !
52-
version=_get_version(
53-
_get_here(os.path.join('wcwidth', 'version.json'))),
47+
version='0.2.5',
5448
description=(
5549
"Measures the displayed width of unicode strings in a terminal"),
5650
long_description=codecs.open(

tests/test_ucslevel.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
import wcwidth
1313

1414

15-
def test_list_versions():
16-
"""wcwidth.list_versions() returns expected value."""
17-
# given,
18-
expected = json.loads(
19-
pkg_resources.resource_string('wcwidth', 'version.json').decode('utf8')
20-
)['tables']
21-
22-
# exercise,
23-
result = wcwidth.list_versions()
24-
25-
# verify,
26-
assert result == expected
27-
28-
2915
def test_latest():
3016
"""wcwidth._wcmatch_version('latest') returns tail item."""
3117
# given,

wcwidth/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@
3030
# these always bit me, too, so I can sympathize -- this version is now manually
3131
# kept in sync with version.json to help them out. Shucks, this variable is just
3232
# for legacy, from the days before 'pip freeze' was a thing.
33-
__version__ = '0.2.4'
33+
#
34+
# We also used pkg_resources to load unicode version tables from version.json,
35+
# generated by bin/update-tables.py, but some environments are unable to
36+
# import pkg_resources for one reason or another, yikes!
37+
__version__ = '0.2.5'

wcwidth/table_wide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Wide_Eastasian table, created by bin/update-tables.py."""
2-
# Generated: 2020-06-01T15:38:29.249643
2+
# Generated: 2020-06-23T15:58:41.860748
33
WIDE_EASTASIAN = {
44
'4.1.0': (
55
# Source: EastAsianWidth-4.1.0.txt

wcwidth/table_zero.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Zero_Width table, created by bin/update-tables.py."""
2-
# Generated: 2020-06-01T15:38:31.292746
2+
# Generated: 2020-06-23T15:58:43.900697
33
ZERO_WIDTH = {
44
'4.1.0': (
55
# Source: DerivedGeneralCategory-4.1.0.txt

0 commit comments

Comments
 (0)