diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 90ccbaaa30..d377023813 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -27,6 +27,7 @@ jobs: git config --global user.email "action@github.com" git config --global user.name "GitHub Action" ./scripts/test + shell: bash - name: Upload coverage to Codecov if: runner.os == 'Linux' uses: codecov/codecov-action@v1.0.3 diff --git a/commitizen/bump.py b/commitizen/bump.py index f571e6a04b..7b621a6e1c 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -1,3 +1,4 @@ +import os import re from collections import OrderedDict from itertools import zip_longest @@ -155,7 +156,9 @@ def update_version_in_files( """ # TODO: separate check step and write step for location in files: - filepath, _, regex = location.partition(":") + drive, tail = os.path.splitdrive(location) + path, _, regex = tail.partition(":") + filepath = drive + path if not regex: regex = _version_to_regex(current_version) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index bc43032036..06dc908dcc 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -1,3 +1,4 @@ +import os from logging import getLogger from typing import List, Optional @@ -230,9 +231,15 @@ def __call__(self): # noqa: C901 }, ) changelog_cmd() + file_names = [] + for file_name in version_files: + drive, tail = os.path.splitdrive(file_name) + path, _, regex = tail.partition(":") + path = drive + path if path != "" else drive + regex + file_names.append(path) git_add_changelog_and_version_files_command = ( f"git add {changelog_cmd.file_name} " - f"{' '.join(file_name.partition(':')[0] for file_name in version_files)}" + f"{' '.join(name for name in file_names)}" ) c = cmd.run(git_add_changelog_and_version_files_command) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 58f6814ba3..2ce8ed4d64 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -40,7 +40,7 @@ def _valid_command_argument(self): arg is not None for arg in (self.commit_msg_file, self.commit_msg, self.rev_range) ) - if num_exclusive_args_provided == 0 and not os.isatty(0): + if num_exclusive_args_provided == 0 and not sys.stdin.isatty(): self.commit_msg: Optional[str] = sys.stdin.read() elif num_exclusive_args_provided != 1: raise InvalidCommandArgumentError( diff --git a/scripts/format b/scripts/format index 47b2b90f44..9d300e964b 100755 --- a/scripts/format +++ b/scripts/format @@ -1,9 +1,7 @@ -#!/bin/sh -e +#!/usr/bin/env sh +set -e export PREFIX="poetry run python -m " -if [ -d 'venv' ] ; then - export PREFIX="venv/bin/" -fi set -x diff --git a/scripts/test b/scripts/test index 11131cd209..ea5a318988 100755 --- a/scripts/test +++ b/scripts/test @@ -1,14 +1,13 @@ -#!/bin/sh -e +#!/usr/bin/env sh +set -e -export PREFIX="poetry run python -m " -if [ -d 'venv' ] ; then - export PREFIX="venv/bin/" -fi +export PREFIX='poetry run python -m ' +export REGEX='^(?![.]|venv).*' ${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ ${PREFIX}black commitizen tests --check ${PREFIX}isort --check-only commitizen tests ${PREFIX}flake8 commitizen/ tests/ ${PREFIX}mypy commitizen/ tests/ -${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 +${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 --match-dir='"${REGEX}"' ${PREFIX}commitizen check --rev-range origin/master.. diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 7374e5aa52..81b4f9d1b4 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -302,9 +302,10 @@ def test_bump_when_version_inconsistent_in_version_files( tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("100.999.10000") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file.write( f"{tmp_commitizen_cfg_file.read()}\n" - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{tmp_version_file_string}"]' ) create_file_and_commit("feat: new file") @@ -323,9 +324,10 @@ def test_bump_files_only(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("0.1.0") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file.write( f"{tmp_commitizen_cfg_file.read()}\n" - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{tmp_version_file_string}"]' ) create_file_and_commit("feat: new user interface") @@ -355,10 +357,11 @@ def test_bump_local_version(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("4.5.1+0.1.0") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file.write( f"[tool.commitizen]\n" 'version="4.5.1+0.1.0"\n' - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{tmp_version_file_string}"]' ) create_file_and_commit("feat: new user interface") diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 131aaaad44..6fa8d5008a 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -65,7 +65,7 @@ def test_init_without_setup_pre_commit_hook(tmpdir, mocker, config): def test_init_when_config_already_exists(config, capsys): # Set config path - path = "tests/pyproject.toml" + path = os.sep.join(["tests", "pyproject.toml"]) config.add_path(path) commands.Init(config)() diff --git a/tests/conftest.py b/tests/conftest.py index 64a5652f1a..bb18531699 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,7 +28,7 @@ def tmp_commitizen_project(tmp_git_project): def _get_gpg_keyid(signer_mail): _new_key = cmd.run(f"gpg --list-secret-keys {signer_mail}") _m = re.search( - rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", + r"[a-zA-Z0-9 \[\]-_]*\n[ ]*([0-9A-Za-z]*)\n[\na-zA-Z0-9 \[\]-_<>@]*", _new_key.out, ) return _m.group(1) if _m else None @@ -42,7 +42,8 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): # create a temporary GPGHOME to store a temporary keyring. # Home path must be less than 104 characters gpg_home = tempfile.TemporaryDirectory(suffix="_cz") - os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring + if os.name != "nt": + os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring # create a key (a keyring will be generated within GPUPGHOME) c = cmd.run( diff --git a/tests/test_bump_create_commit_message.py b/tests/test_bump_create_commit_message.py index ee1f1f768c..b4bcf9631a 100644 --- a/tests/test_bump_create_commit_message.py +++ b/tests/test_bump_create_commit_message.py @@ -1,3 +1,4 @@ +import os import sys from pathlib import Path from textwrap import dedent @@ -55,7 +56,10 @@ def test_bump_pre_commit_changelog(tmp_commitizen_project, mocker, freezer, retr """ ) cmd.run("git add -A") - cmd.run("git commit -m 'fix: _test'") + if os.name == "nt": + cmd.run('git commit -m "fix: _test"') + else: + cmd.run("git commit -m 'fix: _test'") cmd.run("pre-commit install") cli.main() # Pre-commit fixed last line adding extra indent and "\" char @@ -93,7 +97,10 @@ def test_bump_pre_commit_changelog_fails_always( """ ) cmd.run("git add -A") - cmd.run("git commit -m 'feat: forbid changelogs'") + if os.name == "nt": + cmd.run('git commit -m "feat: forbid changelogs"') + else: + cmd.run("git commit -m 'feat: forbid changelogs'") cmd.run("pre-commit install") with pytest.raises(exceptions.BumpCommitFailedError): cli.main() diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 3113638003..0c37bf538c 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -15,9 +15,9 @@ def _copy_sample_file_to_tmpdir( tmpdir: LocalPath, source_filename: str, dest_filename: str ) -> str: - tmp_file = tmpdir.join(dest_filename) - copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", str(tmp_file)) - return str(tmp_file) + tmp_file = str(tmpdir.join(dest_filename)).replace("\\", "/") + copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", tmp_file) + return tmp_file @pytest.fixture(scope="function") diff --git a/tests/test_cli.py b/tests/test_cli.py index 383d7a18cf..68a9c04a23 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,4 @@ +import os import subprocess import sys @@ -84,6 +85,10 @@ def test_commitizen_debug_excepthook(capsys): assert "NotAGitProjectError" in str(excinfo.traceback[0]) +@pytest.mark.skipif( + os.name == "nt", + reason="`argcomplete` does not support Git Bash on Windows.", +) def test_argcomplete_activation(): """ This function is testing the one-time activation of argcomplete for diff --git a/tests/test_git.py b/tests/test_git.py index ca51c8f2cd..cc1f4cf3c9 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -206,7 +206,10 @@ def test_is_staging_clean_when_updating_file(tmp_commitizen_project): cmd.run("touch test_file") cmd.run("git add test_file") - cmd.run("git commit -m 'add test_file'") + if os.name == "nt": + cmd.run('git commit -m "add test_file"') + else: + cmd.run("git commit -m 'add test_file'") cmd.run("echo 'test' > test_file") assert git.is_staging_clean() is True