From 00fdabed327b661ca31cb044f4e47d0b7ee94a9c Mon Sep 17 00:00:00 2001 From: Manuel Barkhau Date: Sun, 9 Dec 2018 15:57:04 +0100 Subject: [PATCH] py27 compat fixes --- .gitignore | 1 + .gitlab-ci.yml | 1 + docker_base.Dockerfile | 2 ++ makefile | 4 ++-- makefile.extra.make | 27 +++++++++++++++++++++++++++ requirements/pypi.txt | 1 + src/pycalver/config.py | 14 +++++++++----- 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 219b19c..617d8b9 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ public/ .pytest_cache/ .ipynb_checkpoints/ package-lock.json +compat_test/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d990623..58c78ed 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,7 @@ unit: - make lint - make mypy - make test + - make test_compat coverage: '/^(TOTAL|src).*?(\d+\%)$/' artifacts: paths: diff --git a/docker_base.Dockerfile b/docker_base.Dockerfile index 8587294..9c8006c 100644 --- a/docker_base.Dockerfile +++ b/docker_base.Dockerfile @@ -59,5 +59,7 @@ RUN conda clean --all --yes && \ FROM registry.gitlab.com/mbarkhau/bootstrapit/root +RUN apt-get install --yes mercurial; + COPY --from=builder /opt/conda/ /opt/conda/ COPY --from=builder /vendor/ /vendor diff --git a/makefile b/makefile index d8079d3..7434a77 100644 --- a/makefile +++ b/makefile @@ -323,7 +323,7 @@ pylint: ## Run pytest unit and integration tests .PHONY: test -test: +test: $(COMPAT_TEST_FILES) @rm -rf ".pytest_cache"; @rm -rf "src/__pycache__"; @rm -rf "test/__pycache__"; @@ -346,7 +346,7 @@ test: for i in $${!env_paths[@]}; do \ env_py=$${env_paths[i]}/bin/python; \ $${env_py} -m pip install --upgrade build/test_wheel/*.whl; \ - ENV=$${ENV-dev} $${env_py} -m pytest test/; \ + ENV=$${ENV-dev} $${env_py} -m pytest --verbose compat_test/; \ done; @rm -rf ".pytest_cache"; diff --git a/makefile.extra.make b/makefile.extra.make index 7f637e0..0d25ea6 100644 --- a/makefile.extra.make +++ b/makefile.extra.make @@ -7,3 +7,30 @@ serve: echo "Not Implemented" + +COMPAT_TEST_FILES = $(shell ls -1 test/*.py | awk '{ printf " compat_"$$0 }') + +compat_test/%.py: test/%.py + @mkdir -p compat_test/; + $(DEV_ENV)/bin/lib3to6 $< > $@.tmp; + mv $@.tmp $@; + + +## Run pytest integration tests +.PHONY: test_compat +test_compat: $(COMPAT_TEST_FILES) + rm -rf compat_test/fixtures; + mkdir -p compat_test/fixtures; + cp -R test/fixtures compat_test/ + + # install the package and run the test suite against it. + mkdir -p build/test_wheel; + $(DEV_ENV_PY) setup.py bdist_wheel --dist-dir build/test_wheel; + + IFS=' ' read -r -a env_paths <<< "$(CONDA_ENV_PATHS)"; \ + for i in $${!env_paths[@]}; do \ + env_py=$${env_paths[i]}/bin/python; \ + $${env_py} -m pip install --upgrade build/test_wheel/*.whl; \ + PYTHONPATH="" ENV=$${ENV-dev} \ + $${env_py} -m pytest --verbose compat_test/; \ + done; diff --git a/requirements/pypi.txt b/requirements/pypi.txt index 56bf91f..2076469 100644 --- a/requirements/pypi.txt +++ b/requirements/pypi.txt @@ -11,3 +11,4 @@ pathlib2 typing click toml +six diff --git a/src/pycalver/config.py b/src/pycalver/config.py index 6abfc96..52bfce4 100644 --- a/src/pycalver/config.py +++ b/src/pycalver/config.py @@ -7,6 +7,7 @@ import io import os +import six import toml import configparser import typing as typ @@ -35,10 +36,13 @@ class ProjectContext(typ.NamedTuple): def init_project_ctx(project_path: typ.Union[str, pl.Path, None] = ".") -> ProjectContext: """Initialize ProjectContext from a path.""" - if isinstance(project_path, str): - path = pl.Path(project_path) - else: + if isinstance(project_path, pl.Path): path = project_path + elif project_path is None: + path = pl.Path(".") + else: + # assume it's a str/unicode + path = pl.Path(project_path) if (path / "pyproject.toml").exists(): config_filepath = path / "pyproject.toml" @@ -86,7 +90,7 @@ def _debug_str(cfg: Config) -> str: f"tag={cfg.tag}", f"commit={cfg.commit}", f"push={cfg.push}", - f"file_patterns={{", + "file_patterns={", ] for filepath, patterns in cfg.file_patterns.items(): @@ -152,7 +156,7 @@ def _parse_cfg(cfg_buffer: typ.TextIO) -> RawConfig: for option, default_val in BOOL_OPTIONS.items(): val: OptionVal = raw_cfg.get(option, default_val) - if isinstance(val, str): + if isinstance(val, six.text_type): val = val.lower() in ("yes", "true", "1", "on") raw_cfg[option] = val