-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add supported packages to README automatically
- Loading branch information
Showing
4 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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,31 @@ | ||
import importlib | ||
import importlib.util | ||
from pathlib import Path | ||
|
||
readme_file = Path(__file__).resolve().parent.parent / "README.md" | ||
# Import the DEPENDENCY_MAPPING from the db.py file directly | ||
db_file = Path(__file__).resolve().parent.parent / "src/sync_pre_commit_lock/db.py" | ||
spec = importlib.util.spec_from_file_location("db", db_file) | ||
db = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(db) | ||
DEPENDENCY_MAPPING = db.DEPENDENCY_MAPPING | ||
|
||
|
||
# Generate the markdown content | ||
markdown_content = "<!-- @generated by scripts/db_md.py -->\n" + "\n".join( | ||
f"- [{package}]({data['repo']})" for package, data in DEPENDENCY_MAPPING.items() | ||
) | ||
|
||
# Update the README file | ||
with readme_file.open("r+") as f: | ||
readme_content = f.read() | ||
start_comment = "<!-- GENERATED-PACKAGES-LIST -->" | ||
end_comment = "<!-- END-GENERATED-PACKAGES-LIST -->" | ||
start_index = readme_content.find(start_comment) + len(start_comment) | ||
end_index = readme_content.find(end_comment) | ||
updated_readme_content = readme_content[:start_index] + "\n" + markdown_content + "\n" + readme_content[end_index:] | ||
f.seek(0) | ||
f.write(updated_readme_content) | ||
f.truncate() | ||
|
||
print("Supported packages list has been added to the README file.") # noqa: T201 |
This file contains 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