Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ jobs:
id: select_matrix
# Select full matrix when scheduled or when releasing, and normal matrix
# otherwise. The matrix is defined as a JSON string.
# This technique documented in:
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional
# TODO: Find a way to define this with less escapes.
run: |
if [[ "${{ github.event_name }}" == "schedule" || "${{ github.head_ref }}" =~ ^release_ ]]; then \
echo "::set-output name=matrix::{ \
echo "matrix={ \
\"os\": [ \"ubuntu-latest\", \"macos-latest\", \"windows-latest\" ], \
\"python-version\": [ \"3.9\", \"3.10\", \"3.11\", \"3.12\", \"3.13\", \"3.14\" ], \
\"package_level\": [ \"minimum\", \"latest\" ] \
}"; \
}" >> $GITHUB_OUTPUT; \
else \
echo "::set-output name=matrix::{ \
echo "matrix={ \
\"os\": [ \"ubuntu-latest\" ], \
\"python-version\": [ \"3.9\", \"3.14\" ], \
\"package_level\": [ \"minimum\", \"latest\" ], \
Expand All @@ -59,7 +61,7 @@ jobs:
\"package_level\": \"latest\" \
} \
] \
}"; \
}" >> $GITHUB_OUTPUT; \
fi
- name: Show matrix in JSON
run: echo '${{ steps.select_matrix.outputs.matrix }}'
Expand All @@ -75,22 +77,6 @@ jobs:
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
steps:
- name: Set run type (normal, scheduled, release)
id: set-run-type
uses: actions/github-script@v9
with:
result-encoding: string
script: |
var result
if ("${{ github.event_name }}" == "schedule") {
result = "scheduled"
} else if ("${{ github.head_ref }}".match(/^release_/)) {
result = "release"
} else {
result = "normal"
}
console.log(result)
return result
- name: Checkout repo
uses: actions/checkout@v6
with:
Expand Down Expand Up @@ -125,31 +111,26 @@ jobs:
- name: Display environment
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make env
- name: Display initial Python packages
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make pip_list
- name: Display platform
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make platform
- name: Development setup
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make develop
- name: Show installed package versions
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make pip_list
- name: Show package dependency tree
Expand All @@ -159,32 +140,27 @@ jobs:
- name: Run flake8
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make flake8
- name: Run ruff
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make ruff
- name: Run pylint
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make pylint
- name: Run test
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
# TESTCASES: a value for pytest -k
run: |
make test
- name: Run check_reqs
env:
PACKAGE_LEVEL: ${{ matrix.package_level }}
RUN_TYPE: ${{ steps.set-run-type.outputs.result }}
run: |
make check_reqs

Expand Down
17 changes: 3 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ else
endif
endif

# Run type (normal, scheduled, release, local)
ifndef RUN_TYPE
RUN_TYPE := local
endif

# Python major and minor version as a short identifier
pymn := $(shell $(PYTHON_CMD) -c "import sys; sys.stdout.write(f'py{sys.version_info[0]}{sys.version_info[1]}')")

Expand Down Expand Up @@ -134,8 +129,7 @@ help:
@echo "Environment variables:"
@echo " TESTCASES=... - Testcase filter for pytest -k"
@echo " TESTOPTS=... - Options for pytest"
@echo " PACKAGE_LEVEL - Package level to be used for installing dependent Python"
@echo " packages in 'install' and 'develop' targets:"
@echo " PACKAGE_LEVEL - Package level to be used for installing dependent Python packages:"
@echo " latest - Latest package versions available on Pypi"
@echo " minimum - Minimum versions as defined in minimum-constraints*.txt"
@echo " Optional, defaults to 'latest'."
Expand All @@ -151,6 +145,7 @@ all: develop flake8 ruff pylint check_reqs test

.PHONY: check
check: flake8 ruff pylint
@echo "Makefile: $@ done."

.PHONY: platform
platform:
Expand Down Expand Up @@ -205,33 +200,27 @@ flake8: $(done_dir)/flake8_$(pymn)_$(PACKAGE_LEVEL).done
@echo "Makefile: $@ done."

$(done_dir)/flake8_$(pymn)_$(PACKAGE_LEVEL).done: $(done_dir)/develop_$(pymn)_$(PACKAGE_LEVEL).done $(flake8_rc_file) $(check_py_files)
@echo "Makefile: Running Flake8"
rm -f $@
flake8 --config $(flake8_rc_file) $(check_py_files)
echo "done" >$@
@echo "Makefile: Done running Flake8"

.PHONY: ruff
ruff: $(done_dir)/ruff_$(pymn)_$(PACKAGE_LEVEL).done
@echo "Makefile: $@ done."

$(done_dir)/ruff_$(pymn)_$(PACKAGE_LEVEL).done: $(done_dir)/develop_$(pymn)_$(PACKAGE_LEVEL).done $(ruff_rc_file) $(check_py_files)
@echo "Makefile: Running Ruff"
rm -f $@
ruff check --unsafe-fixes --config $(ruff_rc_file) $(check_py_files)
echo "done" >$@
@echo "Makefile: Done running Ruff"

.PHONY: pylint
pylint: $(done_dir)/pylint_$(pymn)_$(PACKAGE_LEVEL).done
@echo "Makefile: $@ done."

$(done_dir)/pylint_$(pymn)_$(PACKAGE_LEVEL).done: $(done_dir)/develop_$(pymn)_$(PACKAGE_LEVEL).done $(pylint_rc_file) $(check_py_files)
@echo "Makefile: Running Pylint"
rm -f $@
pylint $(pylint_opts) --rcfile=$(pylint_rc_file) --output-format=text $(check_py_files)
echo "done" >$@
@echo "Makefile: Done running Pylint"

.PHONY: check_reqs
check_reqs: $(done_dir)/check_reqs_$(pymn)_$(PACKAGE_LEVEL).done
Expand All @@ -251,7 +240,7 @@ endif

.PHONY: test
test: $(done_dir)/develop_$(pymn)_$(PACKAGE_LEVEL).done $(test_py_files)
PYTHONPATH=. pytest $(pytest_general_opts) $(pytest_test_opts) $(test_dir)/function
pytest $(pytest_general_opts) $(pytest_test_opts) $(test_dir)/function
@echo "Makefile: $@ done."

.PHONY: clean
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The generated Python project features the following:
* Selection of the license to be used for the new project.
* Support for publishing the package to Pypi and the documentation to ReadTheDocs.
* Use of semantic versioning (M.N.P).
* Several feature flags for controlling optional features.

## Usage

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""
Tests with using cookiecutter.
Tests for creating repos with cookiecutter.
"""

import os
import re
import subprocess
import tempfile
import shutil

import pytest

from ..utils.utils import path_info, run_args

# Controls whether the output directory is kept for debugging
KEEP_OUT_DIR = False
Expand All @@ -18,30 +18,12 @@
DEBUG = False


def path_info(file_path):
"""
Return information about the existence of the specified file path and
its parent directories until one exists.
"""
lines = ""
if os.path.isfile(file_path):
lines += f"path_info: File exists: {file_path}\n"
elif os.path.isdir(file_path):
lines += f"path_info: Directory exists: {file_path}\n"
else:
lines += f"path_info: Does not exist: {file_path}\n"
parent_path = os.path.dirname(file_path)
if parent_path != file_path:
lines += path_info(parent_path)
return lines


TESTCASES_CC_CREATE = [
# Testcases for test_cc_create()

# Each testcase is a tuple of:
# * desc (str): Brief oneline description of the testcase.
# * input_parms (dict): Non-default input paraneters for cookiecutter.
# * input_parms (dict): Non-default input parameters for cookiecutter.
# * exp_out_dir (str): Path names of expected output directory.
# * exp_files_present (list of str): Path names of files that are expected
# to exist in case of success.
Expand Down Expand Up @@ -797,7 +779,7 @@ def test_cc_create(
exp_lines_absent, exp_rc, exp_stdout_pattern, exp_stderr_pattern):
# pylint: disable=unused-argument
"""
Test creation of cookiecutter projects.
Test creation of repos with cookiecutter.
"""

# The template directory, using the git submodule
Expand All @@ -810,17 +792,8 @@ def test_cc_create(
try:
parm_args = [f"{name}={value}" for name, value in input_parms.items()]
args = ["cookiecutter", "--no-input", template_dir] + parm_args
if DEBUG:
print(f"Debug: args={args!r}")

try:
result = subprocess.run(
args, cwd=tmp_dir, capture_output=True, text=True, check=False,
timeout=30)
except IOError as exc:
raise AssertionError(
f"Cannot run command with args: {args}, "
f"{exc.__class__.__name__}: {exc}")
result = run_args(args=args, cwd=tmp_dir)

assert result.returncode == exp_rc, (
f"Unexpected exit code: {result.returncode} (expected: {exp_rc})\n"
Expand Down
Loading
Loading