-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
133 lines (111 loc) · 4.73 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
"""
Package setup.
Set me up with `python setup.py bdist_wheel --universal`
"""
import io
import json
import os
from setuptools import setup
# Get long description from readme
with io.open("README.md", "rt", encoding="utf8") as readmefile:
README = readmefile.read()
# Convert emojilib json file to python dictionary, so we don't have the parse
# penalty at runtime
# The dir where this file is located is relative to the root dir (where the
# tox.ini file is located). Our tox setup will inject an env variable with that
# path, because we do isolated tox builds in non-root folders eg when running in
# parallel
SETUP_RUN_DIR = os.environ.get("TOX_INI_DIR", os.path.dirname(__file__))
def get_gemoji_db_data(root_dir):
"""get a dictionary of emoji data from the gemoji database."""
emoji_dict = {}
# Load the gemoji database as a baseline
with io.open(
os.path.join(root_dir, "gemoji/db/emoji.json"),
"rt",
encoding="utf8",
) as gemoji_db:
gemoji_db_data = json.load(gemoji_db)
# create the dictionary of emojis, keyed by canonical name
for emoji in gemoji_db_data:
# the emoji canonical name; can contain spaces, replace with _
name = "_".join(emoji["description"].split(" "))
emoji_dict[name] = {
# the unicode codepoint sequence itself
"emoji": emoji["emoji"],
# any aliases the gemoji lib provides
"aliases": tuple(emoji["aliases"]),
}
return emoji_dict
def generate_emoji_db(root_dir, outfile="emoji_fzf/emoji_fzf_emojilib.py"):
"""generate the emoji_fzf_emojilib.py file from the gemoji and emojilib databases."""
emoji_dict = {}
emoji_dict.update(get_gemoji_db_data(root_dir))
# merge the aliases from the emojilib database
# 1. load the json
with io.open(
os.path.join(root_dir, "emojilib/dist/emoji-en-US.json"),
"rt",
encoding="utf8",
) as emojilib_db:
emojilib_db_data = json.load(emojilib_db)
# 2. dictionary, keyed by codepoint, of aliases
emojilib_db_by_codepoint = {}
for codepoint, aliases in emojilib_db_data.items():
emojilib_db_by_codepoint[codepoint] = tuple(aliases)
# 3. iterate over the gemoji dictionary, updating any common codepoint with the
# aliases in the emojilib dictionary. use set() to eliminate duplicates (no
# lexical de-duping tho)
for key, val in emoji_dict.items():
additional_aliases = emojilib_db_by_codepoint.pop(val["emoji"], tuple())
# pylint: disable=unnecessary-dict-index-lookup
emoji_dict[key]["aliases"] = tuple(set(val["aliases"] + additional_aliases))
# 4. add in any emojilib entries that weren't in the gemoji database
for codepoint, (name, *aliases) in emojilib_db_by_codepoint.items():
# some of these have spaces, sub in '_' to make it work nicer with fzf
# preview
name = name.replace(" ", "_")
emoji_dict[name] = {"emoji": codepoint, "aliases": tuple(aliases)}
with open(outfile, "w", encoding="utf-8") as genfile:
genfile.write(
"""# -*- coding: utf-8 -*-
\"\"\"
Emoji python alias file, autogenerated.
\"\"\"
"""
)
genfile.write("EMOJIS = {}".format(emoji_dict))
if __name__ == "__main__":
generate_emoji_db(SETUP_RUN_DIR)
setup(
# I think using `-` instead of `_` is more user-friendly, but due to python
# import directives not allowing `-`, keep everything consistent with `_`.
name="emoji-fzf",
version="0.9.0",
description="Emoji searcher for use with fzf",
author="Noah Pendleton",
author_email="[email protected]",
url="https://github.com/noahp/emoji-fzf",
project_urls={
"Code": "https://github.com/noahp/emoji-fzf",
"Issue tracker": "https://github.com/noahp/emoji-fzf/issues",
},
long_description=README,
long_description_content_type="text/markdown",
install_requires=["click"],
# using markdown as pypi description:
# https://dustingram.com/articles/2018/03/16/markdown-descriptions-on-pypi
setup_requires=["setuptools>=38.6.0", "wheel>=0.31.0", "twine>=1.11.0"],
packages=["emoji_fzf"],
entry_points={"console_scripts": ["emoji-fzf = emoji_fzf.emoji_fzf:cli"]},
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
],
)