+ setup.py to package it

+ option to display the version
+ importing the version from git metadata
This commit is contained in:
nicobo 2020-12-20 15:45:38 +01:00
parent d84298bc59
commit 9deb1281d1
No known key found for this signature in database
GPG key ID: 2581E71C5FA5285F
3 changed files with 75 additions and 2 deletions

View file

@ -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

5
nicobot/version.py Normal file
View file

@ -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')

61
setup.py Normal file
View file

@ -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,
},
)