Skip to content

Commit

Permalink
Update Makefile help command to work on all platforms (#335)
Browse files Browse the repository at this point in the history
* update python script and variable reference so help printing works on all platforms

* add blank make command testing output of available commands

* add test for makefile help text
  • Loading branch information
chrisjkuch authored Jan 11, 2024
1 parent b0c3758 commit 8aa2417
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions tests/conda_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ then
sudo chown -R $USER /usr/local/miniconda
fi

make
make create_environment
conda activate $PROJECT_NAME
make requirements
Expand Down
1 change: 1 addition & 0 deletions tests/pipenv_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ source $CCDS_ROOT/test_functions.sh

# navigate to the generated project and run make commands
cd $1
make
make create_environment

# can happen outside of environment since pipenv knows based on Pipfile
Expand Down
8 changes: 7 additions & 1 deletion tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def verify_files(root, config):

def verify_makefile_commands(root, config):
"""Actually shell out to bash and run the make commands for:
- blank command listing commands
- create_environment
- requirements
Ensure that these use the proper environment.
Expand Down Expand Up @@ -171,9 +172,14 @@ def verify_makefile_commands(root, config):
# normally hidden by pytest except in failure we want this displayed
print("PATH=", os.getenv("PATH"))
print("\n======================= STDOUT ======================")
print(result.stdout.decode(encoding))
stdout_output = result.stdout.decode(encoding)
print(stdout_output)

print("\n======================= STDERR ======================")
print(result.stderr.decode(encoding))

# Check that makefile help ran successfully
assert "Available rules:" in stdout_output
assert "clean Delete all compiled Python files" in stdout_output

assert result_returncode == 0
1 change: 1 addition & 0 deletions tests/virtualenv_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ then
source `which virtualenvwrapper.sh`
fi

make
make create_environment

# workon not sourced
Expand Down
14 changes: 6 additions & 8 deletions {{ cookiecutter.repo_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,13 @@ data: requirements
.DEFAULT_GOAL := help

define PRINT_HELP_PYSCRIPT
import re, sys

for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
import re, sys; \
lines = '\n'.join([line for line in sys.stdin]); \
matches = re.findall(r'\n## (.*)\n[\s\S]+?\n([a-zA-Z_-]+):', lines); \
print('Available rules:\n'); \
print('\n'.join(['{:25}{}'.format(*reversed(match)) for match in matches]))
endef
export PRINT_HELP_PYSCRIPT

help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
@python -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST)

0 comments on commit 8aa2417

Please sign in to comment.