From 6be91ed61b64689c03feeec7ee6d8cf1a038699c Mon Sep 17 00:00:00 2001 From: Tibor Arpas Date: Tue, 30 May 2023 13:46:19 +0200 Subject: [PATCH] Add ignore_dependencies configuration option and bump version to 2.0.9dev0 --- testmon/__init__.py | 2 +- testmon/common.py | 18 ++++++++++++------ testmon/pytest_testmon.py | 7 ++++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/testmon/__init__.py b/testmon/__init__.py index dfe15f5..2d578d6 100644 --- a/testmon/__init__.py +++ b/testmon/__init__.py @@ -1,2 +1,2 @@ """PYTEST_DONT_REWRITE""" -VERSION = "2.0.8" +VERSION = "2.0.9dev0" diff --git a/testmon/common.py b/testmon/common.py index f892b43..09bafdc 100644 --- a/testmon/common.py +++ b/testmon/common.py @@ -7,7 +7,7 @@ def get_system_packages_raw(): return ( - f"{pkg.metadata['Name']} {pkg.version}" + (pkg.metadata["Name"], pkg.version) for pkg in importlib.metadata.distributions() ) @@ -15,9 +15,7 @@ def get_system_packages_raw(): import pkg_resources def get_system_packages_raw(): - return ( - f"{pkg.project_name} {pkg.version}" for pkg in pkg_resources.working_set - ) + return ((pkg.project_name, pkg.version) for pkg in pkg_resources.working_set) from pathlib import Path @@ -35,8 +33,16 @@ def get_logger(name): logger = get_logger(__name__) -def get_system_packages(): - return ", ".join(sorted(set(get_system_packages_raw()))) +def get_system_packages(ignore=None): + return ", ".join( + sorted( + { + f"{package} {version}" + for (package, version) in get_system_packages_raw() + if not ignore or not package in ignore + } + ) + ) def drop_patch_version(system_packages): diff --git a/testmon/pytest_testmon.py b/testmon/pytest_testmon.py index a1065ae..9924e2a 100644 --- a/testmon/pytest_testmon.py +++ b/testmon/pytest_testmon.py @@ -111,6 +111,7 @@ def pytest_addoption(parser): ) parser.addini("environment_expression", "environment expression", default="") + parser.addini("ignore_dependencies", "ignore dependencies", default=[]) parser.addini("testmon_url", "URL of the testmon.net api server.") parser.addini("tmnet_api_key", "testmon api key") @@ -131,7 +132,11 @@ def init_testmon_data(config): environment = config.getoption("environment_expression") or eval_environment( config.getini("environment_expression") ) - system_packages = get_system_packages() + ignore_dependencies_str = config.getini("ignore_dependencies") + ignore_dependencies = ( + ignore_dependencies_str.split("\n") if ignore_dependencies_str else None + ) + system_packages = get_system_packages(ignore=ignore_dependencies) url = config.getini("testmon_url") rpc_proxy = None