diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bcec1c8..9451104 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ Version 0.11.0 - Discovery is no longer automatically done when running ``vdirsyncer sync``. ``vdirsyncer discover`` now has to be explicitly called. - Add a ``.plist`` example for Mac OS X. +- Usage under Python 2 now requires a special config parameter to be set. Version 0.10.0 ============== diff --git a/tests/conftest.py b/tests/conftest.py index 08282e1..0b0774a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,7 @@ def setup_logging(): @pytest.fixture(autouse=True) def suppress_py2_warning(monkeypatch): - monkeypatch.setattr('vdirsyncer.cli._check_python2', lambda: None) + monkeypatch.setattr('vdirsyncer.cli._check_python2', lambda _: None) try: diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 846c895..5265125 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -8,7 +8,7 @@ import click import click_log -from .. import PROJECT_HOME, __version__ +from .. import PROJECT_HOME, __version__, exceptions from ..utils.compat import PY2 @@ -38,12 +38,27 @@ def catch_errors(f): return inner -def _check_python2(): - if PY2: - cli_logger.warning('Python 2 support will be dropped. Please switch ' - 'to at least Python 3.3 as soon as possible. See ' - '{home}/issues/219 for more information.' - .format(home=PROJECT_HOME)) +def _check_python2(config): + # XXX: Py2 + if not PY2: + return + + msg = ( + 'Python 2 support will be dropped. Please switch ' + 'to at least Python 3.3 as soon as possible. See ' + '{home}/issues/219 for more information.' + .format(home=PROJECT_HOME) + ) + + if not config.general.get('python2', False): + raise exceptions.UserError( + msg + ( + '\nSet python2 = true in the [general] section to get rid of ' + 'this error for now.' + ) + ) + else: + cli_logger.warning(msg) @click.group() @@ -57,11 +72,11 @@ def app(ctx, config): ''' vdirsyncer -- synchronize calendars and contacts ''' - _check_python2() from .config import load_config if not ctx.config: ctx.config = load_config(config) + _check_python2(ctx.config) main = app diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index 5ae4e5c..826284c 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -14,7 +14,7 @@ try: except ImportError: from configparser import RawConfigParser -GENERAL_ALL = frozenset(['status_path']) +GENERAL_ALL = frozenset(['status_path', 'python2']) # XXX: Py2 GENERAL_REQUIRED = frozenset(['status_path']) SECTION_NAME_CHARS = frozenset(chain(string.ascii_letters, string.digits, '_'))