def load_plugin(name, config, plugin_config): log.info(f"load plugin '{name}'") search_name = name search_version = None if ':' in name: search_name, search_version = name.split(':') if search_name.endswith("-plugin") == False: search_name = f"{search_name}-plugin" package = load_installed_package(search_name) if package is None: raise PluginException(f"{name}: plugin not installed") return if search_version and package.version != Version(search_version): raise PluginException( f"{name}: require version '{search_version}' but '{package.version}' found" ) try: spec = importlib.util.spec_from_file_location( "plugin", os.path.join(package.path, '__init__.py')) plugin = importlib.util.module_from_spec(spec) plugin.args = plugin_config spec.loader.exec_module(plugin) except Exception as e: print_stack() log.debug(e) raise PluginException(f"{name}: failed to load plugin")
def test_load_project(self): os.chdir('project_ok') project = army.api.project.load_project() assert project.name == "project_ok" assert project.description == "test project ok" assert project.version == Version("1.0.0")
def _search_dir(path, version_range): if os.path.exists(os.path.expanduser(path)) == False: return None for package in os.listdir(os.path.expanduser(path)): if name == package: try: pkg = _load_installed_package(os.path.join(path, package)) if version_range is None: return pkg else: version_range = VersionRange(version_range, [pkg.version]) if version_range.match(Version(pkg.version)): return pkg except Exception as e: print_stack() log.debug(e) log.error( f"{os.path.join(path, package)}: not a valid package") return None
import sys import os #sys.path.append(os.path.dirname(__name__)) from army.api.version import Version, VersionRange Version("1.0.0") in VersionRange("==1.0.0") Version("1.0.1") in VersionRange("~1.0.0") Version("1.0.0") in VersionRange("latest", ["0.0.1", "0.0.2", "1.0.0"]) print(VersionRange("==1.0.0").match(Version("1.1.0"))) print(str(VersionRange("~1.0.0"))) print(VersionRange("~1.0.0"))
def check(self, value): try: version = Version(value) except Exception as e: raise ValidatorException(f"'{value}' is not a valid version")
def version(self): return Version(self._data['version'])
import sys import os #sys.path.append(os.path.dirname(__name__)) from army.api.version import Version # print(Version("1")) # print(Version("1.2")) print(Version("1.2.3")) print(Version("1.2.3-b")) print(Version("1.2.3-dev")) # validated with https://semver.npmjs.com/ values = ["", "1.1.1.1", "1.a", "1-a"] for value in values: try: print(f"version: {value}") Version(value) assert False except AssertionError: print("Should assert !") exit(1) except Exception as e: print(format(e)) print("---") values = [ # [L<R L<=R L>R L>=R L==R ] # ["1", "1", [False, True, False, True, True ]],