Skip to content

Commit 723d2dd

Browse files
authored
Merge pull request #7 from blowekamp/make_package
Make package
2 parents cd73a02 + 9371369 commit 723d2dd

2 files changed

Lines changed: 48 additions & 12 deletions

File tree

codespell.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#! /usr/bin/env
1+
#!/usr/bin/env python3
22

33
import sys
44
import os
55
import glob
66
import argparse
77
import re
8+
from pathlib import Path
89

910
from enchant.checker import SpellChecker
1011
from enchant.tokenize import EmailFilter, URLFilter
@@ -103,7 +104,7 @@ def spell_check_file(filename, spell_checker, mimetype='',
103104
if ok_flag:
104105
continue
105106

106-
# Check for possesive words
107+
# Check for possessive words
107108

108109
if error.word.endswith("'s"):
109110
wrd = error.word[:-2]
@@ -190,14 +191,15 @@ def add_dict(enchant_dict, filename):
190191
enchant_dict.add_to_pwl(wrd)
191192

192193

193-
if __name__ == '__main__':
194-
194+
def main():
195195
args = parse_args()
196196
# print(args)
197197

198-
thisdir = os.path.dirname(os.path.abspath(__file__))
198+
initial_dct = Path(__file__) / 'additional_dictionary.txt'
199+
if not initial_dct.exists():
200+
initial_dct = None
199201

200-
sitk_dict = DictWithPWL('en_US', thisdir+'/additional_dictionary.txt')
202+
sitk_dict = DictWithPWL('en_US', initial_dct)
201203

202204
if args.dict is not None:
203205
for d in args.dict:
@@ -233,7 +235,7 @@ def add_dict(enchant_dict, filename):
233235
if os.path.isdir(f):
234236

235237
# f is a directory, so search for files inside
236-
dir_entries = glob.glob(f+'/**/*'+args.suffix, recursive=True)
238+
dir_entries = glob.glob(f + '/**/*' + args.suffix, recursive=True)
237239

238240
# spell check the files found in f
239241
for x in dir_entries:
@@ -247,7 +249,7 @@ def add_dict(enchant_dict, filename):
247249
result = spell_check_file(x, spell_checker,
248250
output_lvl=output_lvl,
249251
prefixes=prefixes)
250-
bad_words = sorted(bad_words+result)
252+
bad_words = sorted(bad_words + result)
251253
else:
252254

253255
if exclude_check(f, args.exclude):
@@ -258,7 +260,7 @@ def add_dict(enchant_dict, filename):
258260
result = spell_check_file(f, spell_checker,
259261
output_lvl=output_lvl, prefixes=prefixes)
260262

261-
bad_words = sorted(bad_words+result)
263+
bad_words = sorted(bad_words + result)
262264

263265
if not args.miss:
264266
print("\nBad words\n")
@@ -268,12 +270,16 @@ def add_dict(enchant_dict, filename):
268270
if x[0] == prev:
269271
sys.stdout.write('.')
270272
continue
271-
print("\n", x[0],": ",x[1], ", ", x[2], sep='')
273+
print("\n", x[0], ": ", x[1], ", ", x[2], sep='')
272274
prev = x[0]
273275

274276
if not args.miss:
275277
print("")
276278

277-
print (len(bad_words), "misspellings found")
278-
279+
print(len(bad_words), "misspellings found")
280+
279281
sys.exit(len(bad_words))
282+
283+
284+
if __name__ == '__main__':
285+
main()

pyproject.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "SimpleITKSpellChecking"
7+
version = "0.0.1"
8+
authors = [
9+
{ name="David Chen", email="dchen@mail.nih.gov" },
10+
]
11+
description = "A script to automatically spell checks comments of a codebase."
12+
readme = "README.md"
13+
requires-python = ">=3.8"
14+
classifiers = [
15+
"Programming Language :: Python :: 3",
16+
"License :: OSI Approved :: MIT License",
17+
"Operating System :: OS Independent",
18+
]
19+
dynamic = ["dependencies"]
20+
21+
[project.urls]
22+
"Homepage" = "https://github.com/SimpleITK/SimpleITKSpellChecking"
23+
"Bug Tracker" = "https://github.com/SimpleITK/SimpleITKSpellChecking"
24+
25+
[tool.setuptools.dynamic]
26+
dependencies = {file = ["requirements.txt"]}
27+
28+
[project.scripts]
29+
codespell = "codespell:main"
30+

0 commit comments

Comments
 (0)