Skip to content

Commit

Permalink
Merge pull request #8 from demodrive-ai/sp/tests-cleanup
Browse files Browse the repository at this point in the history
tests, publish action
  • Loading branch information
chartotu19 authored Dec 27, 2024
2 parents d55ef40 + 2b32873 commit 3b08b77
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 148 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
python-version: ["3.9","3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -46,8 +46,8 @@ jobs:
- name: Install project
run: poetry install --no-interaction

# - name: Run tests
# run: poetry run pytest -v --cov=docs_actions --cov-report=xml
- name: Run tests
run: poetry run pytest -v --cov=docs_actions --cov-report=xml

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/deploy-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy to PyPI

on:
release:
types: [published]
workflow_dispatch:

jobs:
deploy:
name: Deploy to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/llms-txt-action
permissions:
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.5
virtualenvs-create: true
virtualenvs-in-project: true

- name: Build package
run: poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ runs:
shell: bash
run: |
cd ${{ github.action_path }}
poetry run python src/llms-txt-action/main.py
poetry run python -m llms_txt_action.entrypoint
# - name: Commit changes
# shell: bash
# env:
Expand Down
File renamed without changes.
24 changes: 19 additions & 5 deletions src/llms_txt_action/main.py → llms_txt_action/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def str2bool(v):

def generate_documentation( # noqa: PLR0913
docs_dir: str = "site",
sitemap_path: str = "sitemap.xml",
generate_md_files: bool | None = None,
generate_llms_txt: bool | None = None,
generate_llms_full_txt: bool | None = None,
Expand All @@ -40,6 +41,7 @@ def generate_documentation( # noqa: PLR0913
Args:
----
docs_dir: Directory containing HTML documentation
sitemap_path: Path to the sitemap.xml file relative to docs_dir
generate_md_files: Whether to keep generated markdown files
generate_llms_txt: Whether to generate llms.txt
generate_llms_full_txt: Whether to generate full llms.txt
Expand All @@ -60,11 +62,13 @@ def generate_documentation( # noqa: PLR0913
# Set defaults if None
generate_md_files = True if generate_md_files is None else generate_md_files
generate_llms_txt = True if generate_llms_txt is None else generate_llms_txt
generate_llms_full_txt = True if generate_llms_full_txt is None else generate_llms_full_txt # noqa: E501
generate_llms_full_txt = (
True if generate_llms_full_txt is None else generate_llms_full_txt
)

if generate_llms_txt:
with Path(f"{docs_dir}/{llms_txt_name}").open("w") as f:
f.write(generate_docs_structure(docs_dir))
f.write(generate_docs_structure(f"{docs_dir}/{sitemap_path}"))
logger.info("llms.txt file generated at %s", f"{docs_dir}/{llms_txt_name}")

if generate_llms_full_txt:
Expand All @@ -73,7 +77,10 @@ def generate_documentation( # noqa: PLR0913
markdown_files,
f"{docs_dir}/{llms_full_txt_name}",
)
logger.info("llms_full.txt file generated at %s", f"{docs_dir}/{llms_full_txt_name}") # noqa: E501
logger.info(
"llms_full.txt file generated at %s",
f"{docs_dir}/{llms_full_txt_name}",
)

if not generate_md_files:
logger.info("Deleting MD files as generate_md_files is set to False")
Expand All @@ -88,7 +95,7 @@ def generate_documentation( # noqa: PLR0913
def main():
"""Parse arguments and run generate_documentation."""
parser = argparse.ArgumentParser(
description="Generate markdown and llms.txt files from HTML documentation."
description="Generate markdown and llms.txt files from HTML documentation.",
)
parser.add_argument(
"--docs-dir",
Expand All @@ -110,7 +117,8 @@ def main():
parser.add_argument(
"--generate-llms-full-txt",
type=str2bool,
default=os.environ.get("INPUT_GENERATE_LLMS_FULL_TXT", "true").lower() == "true",
default=os.environ.get("INPUT_GENERATE_LLMS_FULL_TXT", "true").lower()
== "true",
help="Whether to generate full llms.txt [default: true]",
)
parser.add_argument(
Expand All @@ -123,10 +131,16 @@ def main():
default=os.environ.get("INPUT_LLMS_FULL_TXT_NAME", "llms_full.txt"),
help="Name of the full llms.txt file [default: llms_full.txt]",
)
parser.add_argument(
"--sitemap-path",
default=os.environ.get("INPUT_SITEMAP_PATH", "sitemap.xml"),
help="Path relative to docs_dir to the sitemap.xml file [default: sitemap.xml]",
)

args = parser.parse_args()
generate_documentation(
docs_dir=args.docs_dir,
sitemap_path=args.sitemap_path,
generate_md_files=args.generate_md_files,
generate_llms_txt=args.generate_llms_txt,
generate_llms_full_txt=args.generate_llms_full_txt,
Expand Down
8 changes: 4 additions & 4 deletions src/llms_txt_action/utils.py → llms_txt_action/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def html_to_markdown(input_file: Path) -> str:
""" # noqa: D401
doc_converter = DocumentConverter()
conversion_result = doc_converter.convert(input_file)

print(conversion_result)
print("selvam")
logger.info(conversion_result)
if conversion_result.status == ConversionStatus.SUCCESS:
markdown_content = conversion_result.document.export_to_markdown()
# Fast string search for first heading using find()
index = markdown_content.find("\n#")
return markdown_content[index + 1 :] if index >= 0 else markdown_content
msg = f"Failed to convert {input_file}: {conversion_result.errors}"
raise RuntimeError(
msg,
)
raise RuntimeError(msg)


def convert_html_to_markdown(input_path: str) -> list:
Expand Down
Loading

0 comments on commit 3b08b77

Please sign in to comment.