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
50 changes: 6 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,16 @@ on: [push, pull_request]

jobs:

test-action:
test-cli:

name: Test Github Action
name: Test CLI

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: List prerequisites non-recursively
id: non-recursive-prerequisites
uses: ./
with:
working-directory: test
target: test1
- name: Check non-recursive prerequisites
run: |
test "${{ steps.non-recursive-prerequisites.outputs.prerequisites }}" = "prereq"
echo ${{ steps.non-recursive-prerequisites.outputs.hash }}
- name: List recursive prerequisites
id: recursive-prerequisites
uses: ./
with:
working-directory: test
target: test1
flags: --recursive
- name: Check recursive prerequisites
run: |
test "${{ steps.recursive-prerequisites.outputs.prerequisites }}" = "preprereq1 preprereq2"
echo ${{ steps.recursive-prerequisites.outputs.hash }}
- name: Hash directory prerequisite
id: hash-dir-prerequisite
uses: ./
with:
working-directory: test
target: test2
flags: --recursive
- name: Check directory prerequisite hash
run: |
test "${{ steps.hash-dir-prerequisite.outputs.prerequisites }}" = "dirprereq"
test "${{ steps.hash-dir-prerequisite.outputs.hash }}" = "c64a77871513eadd52ec0e278bfbac1db866b77f66ebe91725b378b8bf43e29c"
- uses: actions/checkout@v4
- name: Install package
run: |
python -m pip install .
- name: List dependent targets non-recursively
working-directory: test
run: |
test $(list-dependent-make-targets preprereq1) = prereq
- name: List dependent targets recursively
working-directory: test
run: |
test "$(list-dependent-make-targets preprereq1 -r | xargs)" = ".DEFAULT_GOAL prereq test1"
python -m pip install .[test]
- name: Run tests
run: pytest
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# pymakeutils

A collection of CLI utilities and actions to extract information from Makefiles:
- list-make-prerequisites: List all prerequisites of a target (optionally recursively)
- list-dependent-make-targets: List all targets that depend on a certain prerequisite (optionally recursively)
A collection of CLI utilities to extract information from Makefiles:
- `list-make-prerequisites`: List all prerequisites of a target (optionally recursively)
- `list-dependent-make-targets`: List all targets that depend on a certain prerequisite (optionally recursively)

## Related GitHub Actions
- [colluca/list-make-prerequisites](https://github.com/colluca/list-make-prerequisites): List a target's prerequisites and their combined hash
- [colluca/make-prerequisites-changed](https://github.com/colluca/make-prerequisites-changed): Check whether any of a target's prerequisites changed since a base commit
40 changes: 0 additions & 40 deletions action.yml

This file was deleted.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ where = ["src"]
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

[project.optional-dependencies]
test = ["pytest"]

# Expose your scripts as console commands
[project.scripts]
list-make-prerequisites = "pymakeutils.list_make_prerequisites:main"
list-dependent-make-targets = "pymakeutils.list_dependent_make_targets:main"
list-dependent-make-targets = "pymakeutils.list_dependent_make_targets:main"

[tool.pytest.ini_options]
testpaths = ["test"]
40 changes: 40 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Tests for the list-make-prerequisites and list-dependent-make-targets CLIs.

Both CLIs are exercised as subprocesses (rather than calling their `main()`
directly) so that the tests also cover argument parsing and console-script
wiring, running against the Makefile fixtures in this directory.
"""

import subprocess
from pathlib import Path

FIXTURES_DIR = Path(__file__).parent


def run_cli(*args):
result = subprocess.run(
args, cwd=FIXTURES_DIR, capture_output=True, text=True, check=True)
return result.stdout.strip()


def test_list_prerequisites_non_recursive():
assert run_cli('list-make-prerequisites', 'test1') == 'prereq'


def test_list_prerequisites_recursive():
prerequisites = run_cli('list-make-prerequisites', 'test1', '--recursive').splitlines()
assert prerequisites == ['preprereq1', 'preprereq2']


def test_hash_directory_prerequisite():
hash_value = run_cli('list-make-prerequisites', 'test2', '--recursive', '--hash')
assert hash_value == 'c64a77871513eadd52ec0e278bfbac1db866b77f66ebe91725b378b8bf43e29c'


def test_list_dependent_targets_non_recursive():
assert run_cli('list-dependent-make-targets', 'preprereq1') == 'prereq'


def test_list_dependent_targets_recursive():
targets = run_cli('list-dependent-make-targets', 'preprereq1', '--recursive').splitlines()
assert targets == ['.DEFAULT_GOAL', 'prereq', 'test1']
Loading