From 80428e1bbff00de5cafdf7eb571ac7a1cb97ff69 Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Thu, 14 Jul 2022 19:18:16 -0700 Subject: [PATCH] Switch to pyproject.toml --- gptc/__main__.py | 81 +++++++++++++++++++++++++----------------------- pyproject.toml | 29 +++++++++++++++++ setup.py | 17 ---------- 3 files changed, 72 insertions(+), 55 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/gptc/__main__.py b/gptc/__main__.py index cfabe87..2e01389 100644 --- a/gptc/__main__.py +++ b/gptc/__main__.py @@ -6,48 +6,53 @@ import json import sys import gptc -parser = argparse.ArgumentParser( - description="General Purpose Text Classifier", prog="gptc" -) -subparsers = parser.add_subparsers(dest="subparser_name", required=True) +def main(): + parser = argparse.ArgumentParser( + description="General Purpose Text Classifier", prog="gptc" + ) + subparsers = parser.add_subparsers(dest="subparser_name", required=True) -compile_parser = subparsers.add_parser("compile", help="compile a raw model") -compile_parser.add_argument("model", help="raw model to compile") -compile_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1) + compile_parser = subparsers.add_parser("compile", help="compile a raw model") + compile_parser.add_argument("model", help="raw model to compile") + compile_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1) -classify_parser = subparsers.add_parser("classify", help="classify text") -classify_parser.add_argument("model", help="compiled model to use") -classify_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1) -group = classify_parser.add_mutually_exclusive_group() -group.add_argument( - "-j", - "--json", - help="output confidence dict as JSON (default)", - action="store_true", -) -group.add_argument( - "-c", - "--category", - help="output most likely category or `None`", - action="store_true", -) + classify_parser = subparsers.add_parser("classify", help="classify text") + classify_parser.add_argument("model", help="compiled model to use") + classify_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1) + group = classify_parser.add_mutually_exclusive_group() + group.add_argument( + "-j", + "--json", + help="output confidence dict as JSON (default)", + action="store_true", + ) + group.add_argument( + "-c", + "--category", + help="output most likely category or `None`", + action="store_true", + ) -args = parser.parse_args() + args = parser.parse_args() -with open(args.model, "r") as f: - model = json.load(f) + with open(args.model, "r") as f: + model = json.load(f) -if args.subparser_name == "compile": - print(json.dumps(gptc.compile(model, args.max_ngram_length))) -else: - classifier = gptc.Classifier(model, args.max_ngram_length) - - if sys.stdin.isatty(): - text = input("Text to analyse: ") + if args.subparser_name == "compile": + print(json.dumps(gptc.compile(model, args.max_ngram_length))) else: - text = sys.stdin.read() + classifier = gptc.Classifier(model, args.max_ngram_length) - if args.category: - print(classifier.classify(text)) - else: - print(json.dumps(classifier.confidence(text))) + if sys.stdin.isatty(): + text = input("Text to analyse: ") + else: + text = sys.stdin.read() + + if args.category: + print(classifier.classify(text)) + else: + print(json.dumps(classifier.confidence(text))) + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..666d2da --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[build-system] +requires = ["setuptools>=61.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "gptc" +version = "2.0.0" +description = "General-purpose text classifier" +readme = "README.md" +authors = [{ name = "Samuel Sloniker", email = "sam@kj7rrv.com"}] +license = { file = "LICENSE" } +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Development Status :: 5 - Production/Stable", + "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", + "Operating System :: OS Independent", +] +dependencies = [] +requires-python = ">=3.7" + +[project.urls] +Homepage = "https://git.kj7rrv.com/kj7rrv/gptc" + +[project.scripts] +gptc = "gptc.__main__:main" + +[tool.setuptools] +packages = ["gptc"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 54f4336..0000000 --- a/setup.py +++ /dev/null @@ -1,17 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() -setuptools.setup( - name="gptc", - version="2.0.0", - description="General-purpose text classifier", - long_description=long_description, - long_description_content_type="text/markdown", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - ], - python_requires=">=3.6", -)