Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Makefile help command to work on all platforms #335

Merged
merged 3 commits into from
Jan 11, 2024
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
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)
Loading