-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Yapsictomy - part 1: botplugins and flows (#1219)
* Intermediate state. * Added a separate plugin info dataclass * add dataclasses as dep from python < 3.7 * version2array -> version2tuple * version2tuple -> version2array * Pass on PluginInfo * temp * another pass, running not working * State where it starts to load plugins * Cleanup for flows. * A little bit more tests pass. * Every tests passes except flows. * Working on flows * All tests passes. * make the linter happy. * Dataclasses backport doesn't support 3.4+3.5. * remove 3.4 and 3.5 * error in the travis.yml.
Showing
17 changed files
with
489 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from configparser import ConfigParser | ||
from dataclasses import dataclass | ||
from errbot.utils import version2tuple | ||
from pathlib import Path | ||
from typing import Tuple, List | ||
from configparser import Error as ConfigParserError | ||
|
||
VersionType = Tuple[int, int, int] | ||
|
||
|
||
@dataclass | ||
class PluginInfo: | ||
name: str | ||
module: str | ||
doc: str | ||
core: bool | ||
python_version: VersionType | ||
errbot_minversion: VersionType | ||
errbot_maxversion: VersionType | ||
dependencies: List[str] | ||
location: Path = None | ||
|
||
@staticmethod | ||
def load(plugfile_path: Path) -> 'PluginInfo': | ||
with plugfile_path.open(encoding='utf-8') as plugfile: | ||
return PluginInfo.load_file(plugfile, plugfile_path) | ||
|
||
@staticmethod | ||
def load_file(plugfile, location: Path) -> 'PluginInfo': | ||
cp = ConfigParser() | ||
cp.read_file(plugfile) | ||
pi = PluginInfo.parse(cp) | ||
pi.location = location | ||
return pi | ||
|
||
@staticmethod | ||
def parse(config: ConfigParser) -> 'PluginInfo': | ||
""" | ||
Throws ConfigParserError with a meaningful message if the ConfigParser doesn't contain the minimal | ||
information required. | ||
""" | ||
name = config.get('Core', 'Name') | ||
module = config.get('Core', 'Module') | ||
core = config.get('Core', 'Core', fallback='false').lower() == 'true' | ||
doc = config.get('Documentation', 'Description', fallback=None) | ||
|
||
python_version = config.get('Python', 'Version', fallback=None) | ||
# Old format backward compatibility | ||
if python_version: | ||
if python_version in ('2+', '3'): | ||
python_version = (3, 0, 0) | ||
elif python_version == '2': | ||
python_version = (2, 0, 0) | ||
else: | ||
try: | ||
python_version = tuple(version2tuple(python_version)[0:3]) # We can ignore the alpha/beta part. | ||
except ValueError as ve: | ||
raise ConfigParserError('Invalid Python Version format: %s (%s)' % (python_version, ve)) | ||
|
||
min_version = config.get("Errbot", "Min", fallback=None) | ||
max_version = config.get("Errbot", "Max", fallback=None) | ||
try: | ||
if min_version: | ||
min_version = version2tuple(min_version) | ||
except ValueError as ve: | ||
raise ConfigParserError('Invalid Errbot min version format: %s (%s)' % (min_version, ve)) | ||
|
||
try: | ||
if max_version: | ||
max_version = version2tuple(max_version) | ||
except ValueError as ve: | ||
raise ConfigParserError('Invalid Errbot max version format: %s (%s)' % (max_version, ve)) | ||
depends_on = config.get('Core', 'DependsOn', fallback=None) | ||
deps = [name.strip() for name in depends_on.split(',')] if depends_on else [] | ||
|
||
return PluginInfo(name, module, doc, core, python_version, min_version, max_version, deps) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import sys | ||
|
||
import pytest | ||
from io import StringIO | ||
from pathlib import Path | ||
from errbot.plugin_info import PluginInfo | ||
|
||
plugfile_base = Path(__file__).absolute().parent / 'config_plugin' | ||
plugfile_path = plugfile_base / 'config.plug' | ||
|
||
|
||
def test_load_from_plugfile_path(): | ||
pi = PluginInfo.load(plugfile_path) | ||
assert pi.name == 'Config' | ||
assert pi.module == 'config' | ||
assert pi.doc is None | ||
assert pi.python_version == (3, 0, 0) | ||
assert pi.errbot_minversion is None | ||
assert pi.errbot_maxversion is None | ||
|
||
|
||
@pytest.mark.parametrize('test_input,expected', [ | ||
('2', (2, 0, 0)), | ||
('2+', (3, 0, 0)), | ||
('3', (3, 0, 0)), | ||
('1.2.3', (1, 2, 3)), | ||
('1.2.3-beta', (1, 2, 3)), | ||
]) | ||
def test_python_version_parse(test_input, expected): | ||
f = StringIO(""" | ||
[Core] | ||
Name = Config | ||
Module = config | ||
[Python] | ||
Version = %s | ||
""" % test_input) | ||
|
||
assert PluginInfo.load_file(f, None).python_version == expected | ||
|
||
|
||
def test_doc(): | ||
f = StringIO(""" | ||
[Core] | ||
Name = Config | ||
Module = config | ||
[Documentation] | ||
Description = something | ||
""") | ||
|
||
assert PluginInfo.load_file(f, None).doc == 'something' | ||
|
||
|
||
def test_errbot_version(): | ||
f = StringIO(""" | ||
[Core] | ||
Name = Config | ||
Module = config | ||
[Errbot] | ||
Min = 1.2.3 | ||
Max = 4.5.6-beta | ||
""") | ||
info = PluginInfo.load_file(f, None) | ||
assert info.errbot_minversion == (1, 2, 3, sys.maxsize) | ||
assert info.errbot_maxversion == (4, 5, 6, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters