Skip to content

feat(package): restructure project to use PEP 621, CLI, and modular src layout#46

Merged
obeone merged 14 commits into
mainfrom
pyproject
Jul 6, 2025
Merged

feat(package): restructure project to use PEP 621, CLI, and modular src layout#46
obeone merged 14 commits into
mainfrom
pyproject

Conversation

@obeone
Copy link
Copy Markdown
Owner

@obeone obeone commented Jul 6, 2025

  • Move source files from src/ to crawler_to_md/ for modern modular package structure.
  • Replace requirements.txt with pyproject.toml using PEP 621 metadata and setuptools_scm for dynamic versioning.
  • Add CLI entry point "crawler-to-md" providing command line usage.
  • Update imports in source and tests to match new package layout.
  • Add .github workflow for publishing to PyPI, update .gitignore for Python cache and tool files.
  • Replace main.py with cli.py, now referenced by entry point.
  • Update Dockerfile to use package install and new layout.
  • Rewrite README to reflect CLI usage, modern install, and pipx recommendation.
  • Update dependencies, code style tools, and test configuration for ruff/pytest.
  • Remove requirements.txt, adjust for pyproject.toml-based dependency management.

Summary by CodeRabbit

  • New Features

    • Added automated workflow for building and publishing the package to PyPI.
    • Introduced a centralized project configuration file for dependencies and tooling.
  • Improvements

    • Updated Dockerfile for enhanced security, caching, and multi-stage builds.
    • Improved CLI usability with better argument handling and default paths.
    • Enhanced documentation with updated installation and usage instructions.
    • Updated .gitignore to exclude additional cache and metadata files.
  • Bug Fixes

    • Improved link extraction robustness in the scraper to handle various href formats.
  • Refactor

    • Standardized import paths and code formatting across modules and tests.
    • Improved logging and output messaging for clarity.
  • Chores

    • Removed requirements.txt in favor of pyproject.toml.
    • Updated test imports and formatting for consistency.

obeone added 14 commits July 5, 2025 11:21
…xt to pyproject.toml

- Move Python source files from `src/` to `crawler_to_md/`
- Rename `main.py` to `crawler_to_md/cli.py` and update internal imports
- Update all imports in codebase to reflect new module layout
- Remove requirements.txt in favor of a PEP 621-compliant pyproject.toml with dependencies and CLI entrypoint
- Update .gitignore for Python/package build artifacts (.egg-info, .pytest_cache, .ruff_cache)
- Revise README to reflect new install and usage instructions
- Add initial test file under tests/
- Adjust code formatting and docstrings for improved clarity

This commit prepares the package for proper pip installation and CLI invocation as `crawler-to-md`.
…just dependencies

- Switch to dynamic versioning with setuptools_scm
- Update project description and author information
- Replace trafilatura with markitdown in dependencies
- Add setuptools_scm to build requirements
- Add tool.setuptools_scm configuration
…estPyPI

Adds a workflow that builds Python packages on release and publishes to PyPI. Includes optional publishing to TestPyPI when running on the main branch.
Replaced imports from src.* to crawler_to_md.* throughout test files for consistency with package structure. Adjusted whitespace and minor variable naming for code clarity and style. Added assertions for non-None results in scraper tests. No changes to test logic.
- Removed unused trafilatura import and duplicate imports
- Organized import statements
- Adjusted whitespace and formatting for improved readability in Scraper class
Removes redundant Scraper instantiation and adjusts error handling to use argparse's parser.error when no URL is provided.
…ency management

- Switch to multi-stage build with clear base, builder, and final stages
- Replace pip with uv for Python package installation
- Implement non-root user for improved security
- Improve caching and layer ordering for build efficiency
- Pass APP_VERSION via environment for setuptools-scm compatibility
- Set leaner final entrypoint using uv-installed binary
- Remove unused/obsolete instructions related to pip and Python path
…t path

Changes default --cache-folder value to ~/.cache/crawler-to-md and ensures user paths are expanded using os.path.expanduser.
…ot user

- Change cache directory from /app/cache to /home/app/.cache/crawler-to-md
- Ensure directory is owned by the app user and update VOLUME accordingly
- Create home directory for app user with -m flag
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 6, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a new pyproject.toml for unified project configuration and dependency management, restructures the Dockerfile for multi-stage builds and non-root security, adds a GitHub Actions workflow for automatic PyPI publishing, and removes the legacy requirements.txt. Code and tests are refactored for consistent imports, improved CLI handling, and modernized documentation.

Changes

File(s) Change Summary
.github/workflows/publish-to-pypi.yaml Added a GitHub Actions workflow to build and publish the package to PyPI and optionally to TestPyPI, triggered on release publication.
.gitignore Updated to ignore *.egg-info, .pytest_cache, and .ruff_cache for broader Python and tooling compatibility.
Dockerfile Refactored into multi-stage (base, builder, final); uses non-root user, uv for dependency management, improved caching, and direct CLI entrypoint.
pyproject.toml Introduced as the new project configuration, defining metadata, dependencies, build system, entrypoints, and tool settings for Ruff and pytest.
requirements.txt Deleted; dependency management is now handled via pyproject.toml.
README.md Updated installation and usage instructions for pipx and CLI usage, modernized requirements, and improved clarity throughout.
crawler_to_md/cli.py Refactored imports, improved argument parsing, expanded default cache path, unified URL handling, improved output messaging, and error reporting.
crawler_to_md/database_manager.py Minor import reordering and whitespace cleanup; no logic changes.
crawler_to_md/export_manager.py Reformatted imports and docstrings, removed unused imports, adjusted output folder logic, and improved formatting.
crawler_to_md/log_setup.py Removed unused import, reformatted docstrings and log formatter, improved readability with no logic changes.
crawler_to_md/scraper.py Reorganized and added imports, improved link extraction robustness, reformatted docstrings, clarified logging, and renamed variables for clarity.
crawler_to_md/utils.py Activated import of log_setup, reformatted docstrings, improved debug logging in URL functions, and reformatted filename construction.
tests/test_database_manager.py Updated import path for DatabaseManager to new package structure.
tests/test_export_manager.py Reorganized imports, updated import paths, reformatted function calls, and improved variable naming in assertions.
tests/test_scraper.py Updated imports to new package structure, improved test readability, added assertions, and ensured mocks target correct modules.
tests/test_utils.py Changed import of utils to new package structure.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (crawler-to-md)
    participant DatabaseManager
    participant Scraper
    participant ExportManager

    User->>CLI (crawler-to-md): Run with URLs and options
    CLI (crawler-to-md)->>DatabaseManager: Initialize with db_path
    CLI (crawler-to-md)->>Scraper: Start scraping with URLs
    Scraper->>DatabaseManager: Insert links and pages
    Scraper->>ExportManager: Export markdown files
    ExportManager->>User: Provide output file paths
Loading
sequenceDiagram
    participant GitHub
    participant GitHub Actions
    participant PyPI
    participant TestPyPI

    GitHub->>GitHub Actions: Publish Release Event
    GitHub Actions->>GitHub Actions: Build and package Python project
    GitHub Actions->>PyPI: Publish package (using secrets)
    alt On main branch
        GitHub Actions->>TestPyPI: Publish package (using TestPyPI secrets)
    end
Loading

Poem

In the warren of code, a new path we tread,
With pyproject.toml and Docker ahead.
No more requirements.txt to chase,
Our builds are secure, our tests in place.
The CLI now hops with a friendlier tone—
Publish to PyPI, our project has grown!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53fbf4d and d6e0868.

📒 Files selected for processing (16)
  • .github/workflows/publish-to-pypi.yaml (1 hunks)
  • .gitignore (1 hunks)
  • Dockerfile (1 hunks)
  • README.md (3 hunks)
  • crawler_to_md/cli.py (6 hunks)
  • crawler_to_md/database_manager.py (2 hunks)
  • crawler_to_md/export_manager.py (6 hunks)
  • crawler_to_md/log_setup.py (4 hunks)
  • crawler_to_md/scraper.py (10 hunks)
  • crawler_to_md/utils.py (4 hunks)
  • pyproject.toml (1 hunks)
  • requirements.txt (0 hunks)
  • tests/test_database_manager.py (1 hunks)
  • tests/test_export_manager.py (2 hunks)
  • tests/test_scraper.py (5 hunks)
  • tests/test_utils.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@obeone obeone merged commit 490ffaa into main Jul 6, 2025
2 of 4 checks passed
@obeone obeone deleted the pyproject branch July 13, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant