-
Notifications
You must be signed in to change notification settings - Fork 13
Simple Hook: Add License #66
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5652bc5
Added addlicense hook and test
6b1f295
Fixed test_addlicense
e6a8f37
Updated README
8e66864
Updated makefile and tested against hatch
61abf41
Changed Makefile to use uv and added EditorConfig
c9215c1
Changed addlicense to spdx_license
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| root = true | ||
| [*.toml] | ||
| indent_style = space | ||
| indent_size = 8 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| .PHONY: test | ||
|
|
||
| test: | ||
| poetry run coverage run --source=entangled -m pytest | ||
| poetry run coverage xml | ||
| poetry run coverage report | ||
| poetry run mypy | ||
| uv run coverage run --source=entangled -m pytest | ||
| uv run coverage xml | ||
| uv run coverage report | ||
| uv run mypy | ||
|
|
||
| docs: | ||
| poetry run mkdocs build | ||
| uv run mkdocs build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from ..document import CodeBlock | ||
| from .base import HookBase | ||
|
|
||
|
|
||
| class Hook(HookBase): | ||
| def on_read(self, code: CodeBlock): | ||
| lines = code.source.splitlines() | ||
| if lines and "SPDX-License-Identifier" in lines[0]: | ||
| code.header = lines[0] | ||
| code.source = "\n".join(lines[1:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from entangled.markdown_reader import read_markdown_string | ||
| from entangled.hooks.spdx_license import Hook as SPDXLicense | ||
| from entangled.tangle import tangle_ref, AnnotationMethod | ||
| from entangled.code_reader import CodeReader | ||
| from entangled.commands.stitch import stitch_markdown | ||
|
|
||
| input_md = """ | ||
| A C file with a license! | ||
|
|
||
| ``` {.c file=test.c} | ||
| // SPDX-License-Identifier: MIT | ||
| #include <stdio.h> | ||
|
|
||
| int main() { | ||
| printf("Hello, World!\n"); | ||
| return 0; | ||
| } | ||
| ``` | ||
| """ | ||
|
|
||
| output_test_c = """// SPDX-License-Identifier: MIT | ||
| /* ~/~ begin <<-#test.c>>[init] */ | ||
| #include <stdio.h> | ||
|
|
||
| int main() { | ||
| printf("Hello, World!\n"); | ||
| return 0; | ||
| } | ||
| /* ~/~ end */ | ||
| """ | ||
|
|
||
| output_test_c_modified = """// SPDX-License-Identifier: MIT | ||
| # ~/~ begin <<-#test.c>>[init] | ||
|
|
||
| int main() { | ||
| printf("Hello, World!\n"); | ||
| return 0; | ||
| } | ||
| # ~/~ end | ||
| """ | ||
|
|
||
| input_md_modified = """ | ||
| A C file with a license! | ||
|
|
||
| ``` {.c file=test.c} | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| int main() { | ||
| printf("Hello, World!\n"); | ||
| return 0; | ||
| } | ||
| ``` | ||
| """ | ||
|
|
||
|
|
||
| def test_spdx_license(): | ||
| hooks = [SPDXLicense(SPDXLicense.Config())] | ||
| refs, content = read_markdown_string(input_md, hooks=hooks) | ||
| assert "test.c" in refs | ||
| print(next(refs["test.c"])) | ||
| assert next(refs["test.c"]).header == "// SPDX-License-Identifier: MIT" | ||
| code_content, _ = tangle_ref(refs, "test.c", AnnotationMethod.STANDARD) | ||
| print(code_content.strip()) | ||
| print(output_test_c.strip()) | ||
| assert code_content.strip() == output_test_c.strip() | ||
|
|
||
| cr = CodeReader("test.c", refs) | ||
| cr.run(output_test_c_modified) | ||
| md_content = stitch_markdown(refs, content) | ||
| assert md_content.strip() == input_md_modified.strip() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename the hook to
spdx_license; I don't like arbitrary verbs in variable names