diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6d51f183..e1f078ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,12 +26,12 @@ jobs: - name: Python info shell: bash -l {0} run: | - which python3 - python3 --version + which python + python --version - name: Install dependencies run: | - python3 -m pip install --upgrade pip setuptools - python3 -m pip install .[dev] + python -m pip install --upgrade pip setuptools + python -m pip install .[dev] - name: Run pytest run: | - pytest -v + python -m pytest -v diff --git a/README.dev.md b/README.dev.md index f2debd1c..c7bc7c99 100644 --- a/README.dev.md +++ b/README.dev.md @@ -10,7 +10,7 @@ We recommend installing `cookiecutter` in user space as per `cookiecutter`'s ins install `cookiecutter` for every new project. ```shell -python3 -m pip install --user --upgrade cookiecutter +python -m pip install --user --upgrade cookiecutter ``` ### Get your own copy of the repository @@ -30,17 +30,17 @@ run the tests later. ```shell # Create a virtual environment, e.g. with -python3 -m venv env +python -m venv env # activate virtual environment source env/bin/activate # make sure to have a recent version of pip and setuptools -python3 -m pip install --upgrade pip setuptools +python -m pip install --upgrade pip setuptools # (from the project root directory) # install development dependencies -python3 -m pip install --no-cache-dir .[dev] +python -m pip install --no-cache-dir .[dev] ``` ## Running the tests diff --git a/tests/test_project.py b/tests/test_project.py index 1c377bf6..c1b56c73 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -1,14 +1,11 @@ import os import subprocess -from pathlib import Path -from shutil import which from sys import platform from typing import Sequence import pytest IS_WINDOWS = platform.startswith('win') -IS_WINDOWS_CI = IS_WINDOWS and os.environ.get('CI', False) def test_project_folder(cookies): @@ -33,17 +30,11 @@ def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProces @pytest.fixture def project_env_bin_dir(tmp_path): - if IS_WINDOWS_CI: - # Creating virtualenv does not work on Windows CI, - # falling back to using current pip3 dir - pip = Path(which('pip3')) - bin_dir = pip.parent - else: - env_output = run(['python3', '-m', 'venv', 'env'], tmp_path) - assert env_output.returncode == 0 - bin_dir = str(tmp_path / 'env' / 'bin') - if IS_WINDOWS: - bin_dir = str(tmp_path / 'env' / 'Scripts') + env_output = run(['python', '-m', 'venv', 'env'], tmp_path) + assert env_output.returncode == 0 + bin_dir = str(tmp_path / 'env' / 'bin') + if IS_WINDOWS: + bin_dir = str(tmp_path / 'env' / 'Scripts') return str(bin_dir) + os.sep @@ -52,9 +43,9 @@ def baked_with_development_dependencies(cookies, project_env_bin_dir): result = cookies.bake() assert result.exit_code == 0 bin_dir = project_env_bin_dir - latest_pip_output = run([f'{bin_dir}pip3', 'install', '--upgrade', 'pip', 'setuptools'], result.project) + latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], result.project) assert latest_pip_output.returncode == 0 - pip_output = run([f'{bin_dir}pip3', 'install', '--editable', '.[dev]'], result.project) + pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], result.project) assert pip_output.returncode == 0 return result.project @@ -62,7 +53,7 @@ def baked_with_development_dependencies(cookies, project_env_bin_dir): def test_pytest(baked_with_development_dependencies, project_env_bin_dir): project_dir = baked_with_development_dependencies bin_dir = project_env_bin_dir - result = run([f'{bin_dir}pytest'], project_dir) + result = run([f'{bin_dir}python', '-m', 'pytest'], project_dir) assert result.returncode == 0 assert '== 3 passed in' in result.stdout @@ -98,9 +89,6 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir): subsubpackage.mkdir() (subsubpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8") - if IS_WINDOWS_CI: - # On Windows CI python and pip executable are in different paths - bin_dir = '' # sdist and bdist_wheel both call build command to create build/ dir # So instead of looking in distribution archives we can look in build/ dir result = run([f'{bin_dir}python', 'setup.py', 'build'], project_dir) diff --git a/{{cookiecutter.directory_name}}/.github/workflows/build.yml b/{{cookiecutter.directory_name}}/.github/workflows/build.yml index e202f1b6..cda7e41a 100644 --- a/{{cookiecutter.directory_name}}/.github/workflows/build.yml +++ b/{{cookiecutter.directory_name}}/.github/workflows/build.yml @@ -27,16 +27,16 @@ jobs: - name: Python info shell: bash -l {0} run: | - which python3 - python3 --version + which python + python --version - name: Upgrade pip and install dependencies run: | - python3 -m pip install --upgrade pip setuptools - python3 -m pip install .[dev,publishing] + python -m pip install --upgrade pip setuptools + python -m pip install .[dev,publishing] - name: Run unit tests - run: pytest -v + run: python -m pytest -v - name: Verify that we can build the package - run: python3 setup.py sdist bdist_wheel + run: python setup.py sdist bdist_wheel lint: name: Linting build @@ -52,12 +52,12 @@ jobs: - name: Python info shell: bash -l {0} run: | - which python3 - python3 --version + which python + python --version - name: Upgrade pip and install dependencies run: | - python3 -m pip install --upgrade pip setuptools - python3 -m pip install .[dev,publishing] + python -m pip install --upgrade pip setuptools + python -m pip install .[dev,publishing] - name: Check style against standards using prospector run: prospector - name: Check import order diff --git a/{{cookiecutter.directory_name}}/.github/workflows/documentation.yml b/{{cookiecutter.directory_name}}/.github/workflows/documentation.yml index a9f7b367..09bb41f8 100644 --- a/{{cookiecutter.directory_name}}/.github/workflows/documentation.yml +++ b/{{cookiecutter.directory_name}}/.github/workflows/documentation.yml @@ -23,12 +23,12 @@ jobs: - name: Python info shell: bash -l {0} run: | - which python3 - python3 --version + which python + python --version - name: Upgrade pip and install dependencies run: | - python3 -m pip install --upgrade pip setuptools - python3 -m pip install .[dev,publishing] + python -m pip install --upgrade pip setuptools + python -m pip install .[dev,publishing] - name: Install pandoc using apt run: sudo apt install pandoc - name: Build documentation diff --git a/{{cookiecutter.directory_name}}/.github/workflows/sonarcloud.yml b/{{cookiecutter.directory_name}}/.github/workflows/sonarcloud.yml index 9f7c945c..59aeb90e 100644 --- a/{{cookiecutter.directory_name}}/.github/workflows/sonarcloud.yml +++ b/{{cookiecutter.directory_name}}/.github/workflows/sonarcloud.yml @@ -25,14 +25,14 @@ jobs: - name: Python info shell: bash -l {0} run: | - which python3 - python3 --version + which python + python --version - name: Install dependencies - run: python3 -m pip install .[dev] + run: python -m pip install .[dev] - name: Check style against standards using prospector run: prospector --zero-exit --output-format grouped --output-format pylint:pylint-report.txt - name: Run unit tests with coverage - run: pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml tests/ + run: python -m pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml tests/ - name: Correct coverage paths run: sed -i "s+$PWD/++g" coverage.xml - name: SonarCloud Scan diff --git a/{{cookiecutter.directory_name}}/README.dev.md b/{{cookiecutter.directory_name}}/README.dev.md index 6277b263..9b48b4e4 100644 --- a/{{cookiecutter.directory_name}}/README.dev.md +++ b/{{cookiecutter.directory_name}}/README.dev.md @@ -6,19 +6,19 @@ If you're looking for user documentation, go [here](README.md). ```shell # Create a virtual environment, e.g. with -python3 -m venv env +python -m venv env # activate virtual environment source env/bin/activate # make sure to have a recent version of pip and setuptools -python3 -m pip install --upgrade pip setuptools +python -m pip install --upgrade pip setuptools # (from the project root directory) # install {{ cookiecutter.package_name }} as an editable package -python3 -m pip install --no-cache-dir --editable . +python -m pip install --no-cache-dir --editable . # install development dependencies -python3 -m pip install --no-cache-dir --editable .[dev] +python -m pip install --no-cache-dir --editable .[dev] ``` Afterwards check that the install directory is present in the `PATH` environment variable. @@ -156,22 +156,22 @@ cd $(mktemp -d {{ cookiecutter.package_name }}.XXXXXX) git clone {{ cookiecutter.repository }} . # prepare a clean virtual environment and activate it -python3 -m venv env +python -m venv env source env/bin/activate # make sure to have a recent version of pip and setuptools -python3 -m pip install --upgrade pip setuptools +python -m pip install --upgrade pip setuptools # install runtime dependencies and publishing dependencies -python3 -m pip install --no-cache-dir . -python3 -m pip install --no-cache-dir .[publishing] +python -m pip install --no-cache-dir . +python -m pip install --no-cache-dir .[publishing] # clean up any previously generated artefacts rm -rf {{ cookiecutter.package_name }}.egg-info rm -rf dist # create the source distribution and the wheel -python3 setup.py sdist bdist_wheel +python setup.py sdist bdist_wheel # upload to test pypi instance (requires credentials) twine upload --repository-url https://test.pypi.org/legacy/ dist/* @@ -187,14 +187,14 @@ In a new terminal, without an activated virtual environment or an env directory: cd $(mktemp -d {{ cookiecutter.package_name }}-test.XXXXXX) # prepare a clean virtual environment and activate it -python3 -m venv env +python -m venv env source env/bin/activate # make sure to have a recent version of pip and setuptools -pip install --upgrade pip setuptools +python -m pip install --upgrade pip setuptools # install from test pypi instance: -python3 -m pip -v install --no-cache-dir \ +python -m pip -v install --no-cache-dir \ --index-url https://test.pypi.org/simple/ \ --extra-index-url https://pypi.org/simple {{ cookiecutter.package_name }} ```