From 9deb1281d12954cf3c0f48c5d1e1e7d42668ff68 Mon Sep 17 00:00:00 2001 From: nicobo Date: Sun, 20 Dec 2020 15:45:38 +0100 Subject: [PATCH] + setup.py to package it + option to display the version + importing the version from git metadata --- nicobot/bot.py | 11 +++++++-- nicobot/version.py | 5 ++++ setup.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 nicobot/version.py create mode 100644 setup.py diff --git a/nicobot/bot.py b/nicobot/bot.py index 3257a62..e108950 100644 --- a/nicobot/bot.py +++ b/nicobot/bot.py @@ -7,13 +7,17 @@ import os import signal import sys - from .console import ConsoleChatter from .jabber import JabberChatter from .signalcli import SignalChatter from .stealth import StealthChatter +# There are other options but this one is the most efficient here +# https://github.com/pypa/setuptools_scm#retrieving-package-version-at-runtime +from .version import version as __version__ + + class Bot: """ Bot foundation @@ -87,7 +91,7 @@ class ArgsHelper: # Bootstrap options parser.add_argument("--config-file", "-c", "--config", dest="config_file", default=self.config_file, help="YAML configuration file.") parser.add_argument("--config-dir", "-C", dest="config_dir", default=self.config_dir, help="Directory where to find configuration files by default.") - parser.add_argument('--verbosity', '-V', dest='verbosity', default=self.verbosity, help="Log level") + parser.add_argument('--verbosity', '-v', dest='verbosity', default=self.verbosity, help="Log level") # Chatter-generic arguments parser.add_argument("--backend", "-b", dest="backend", choices=['console','jabber','signal'], default=self.backend, help="Chat backend to use") parser.add_argument("--input-file", "-i", dest="input_file", default=self.input_file, help="File to read messages from (one per line)") @@ -96,6 +100,9 @@ class ArgsHelper: parser.add_argument('--stealth', dest='stealth', action="store_true", default=self.stealth, help="Activate stealth mode on any chosen chatter") # Misc. options parser.add_argument("--debug", "-d", action="store_true", dest='debug', default=False, help="Activate debug logs (overrides --verbosity)") + # Needs the .git metadata or some variables to be able to return the version, otherwise throws an error + # See https://github.com/pypa/setuptools_scm + parser.add_argument("--version", "-V", action="version", version=__version__) return parser diff --git a/nicobot/version.py b/nicobot/version.py new file mode 100644 index 0000000..d02fbf4 --- /dev/null +++ b/nicobot/version.py @@ -0,0 +1,5 @@ +# coding: utf-8 +# file generated by setuptools_scm +# don't change, don't track in version control +version = '0.1.dev58+g75840b0.d20201220' +version_tuple = (0, 1, 'dev58+g75840b0', 'd20201220') diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..62a554e --- /dev/null +++ b/setup.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +def local_scheme(version): + return "" + +setuptools.setup( + name="nicobot", # Replace with your own username + author="nicobo", + author_email="nicobo@users.noreply.github.com", + description="A collection of 🤟 cool 🤟 chat bots", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/nicolabs/nicobot", + packages=setuptools.find_packages(), + classifiers=[ + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Development Status :: 3 - Alpha', + 'Topic :: Communications :: Chat' + ], + python_requires='>=3.4.2', + # TODO This duplicates requirements-build.txt ? + setup_requires=['setuptools-scm'], + # TODO This duplicates requirements-runtime.txt + # Is runnning setup.py enough to replace pip install -r requirements-runtime.txt ? + install_requires=[ + ##### Requirements for signalcli ##### + 'python-i18n', + ###### Requirements for transbot ##### + 'python-i18n', + # https://requests.readthedocs.io/en/master/ + 'requests', + # https://github.com/cvzi/flag + 'emoji-country-flag', + # https://pyyaml.org/wiki/PyYAMLDocumentation + 'pyyaml', + ###### Requirements for jabber ##### + 'slixmpp-omemo', + ], + entry_points={ + 'console_scripts': [ + 'askbot=nicobot.askbot:run', + 'transbot=nicobot.transbot:run', + ], + }, + # Extracts version from SCM ; https://github.com/pypa/setuptools_scm/ + use_scm_version = { + "write_to": "nicobot/version.py", + # Only enable to upload local versions to test repo + # See https://mixstersite.wordpress.com/2019/12/31/setuptools-with-testpypi-error-invalid-version-pep-440/ + # and https://github.com/pypa/setuptools_scm#user-content-version-number-construction + #"local_scheme": local_scheme, + }, +)