Skip to content

Modernize Project with Packaging, Docker, and CI/CD#2

Merged
GrecAndrei merged 3 commits into
mainfrom
copilot/fix-1b4e6f3e-db95-4e86-9b8d-1b6d5ceb15c4
Sep 14, 2025
Merged

Modernize Project with Packaging, Docker, and CI/CD#2
GrecAndrei merged 3 commits into
mainfrom
copilot/fix-1b4e6f3e-db95-4e86-9b8d-1b6d5ceb15c4

Conversation

Copilot AI commented Sep 14, 2025

Copy link
Copy Markdown
Contributor

This PR modernizes the duckduckgo-cli project by introducing standard Python packaging, Docker containerization, and automated CI/CD testing, making it more robust, easier to install, and simpler to contribute to.

🏗️ Modern Python Packaging

Replaced the script-based installation with a pyproject.toml file following modern Python standards:

  • Added proper package structure with duckduckgo_cli module
  • Configured entry point for ddg-cli command
  • Updated dependencies and build system configuration
  • Made the package installable with pip install .

🐳 Docker Support

Added containerization support for consistent deployment:

  • Created Dockerfile for easy containerized usage
  • Fixed dependency issues (added missing typing_extensions)
  • Resolved f-string syntax compatibility issues
  • Container now supports: docker build -t ddg-cli . && docker run ddg-cli search "query"

🔄 CI/CD Pipeline

Introduced automated testing with GitHub Actions:

  • Added .github/workflows/ci.yml for continuous integration
  • Tests compatibility across Python 3.8, 3.9, 3.10, 3.11
  • Automated pytest execution on push and pull requests

🧪 Enhanced Testing

Modernized the test infrastructure:

  • Converted existing tests to pytest format
  • Fixed test imports and structure for package compatibility
  • All 7 tests now pass with simple pytest command
  • Tests validate search functionality, display formatting, and manager components

⚙️ Configuration Improvements

Updated configuration management to follow XDG standards:

  • Changed config path from ~/.ddgs_config.ini to ~/.config/duckduckgo-cli/config.ini
  • Maintained backward compatibility with fallback imports
  • Added proper directory creation for config files

📚 Documentation Updates

Refreshed installation and usage documentation:

  • Updated README with new pip install . and Docker installation methods
  • Added troubleshooting for modern setup
  • Updated examples to reflect new CLI structure
  • Documented the new package architecture

🧹 Cleanup

Removed obsolete files and dependencies:

  • Deleted install.sh, setup.sh, and Makefile (replaced by pip/setuptools)
  • Updated import paths for proper package installation
  • Fixed f-string syntax errors for Python 3.10+ compatibility

✅ Verification

The modernized project now supports:

# Modern installation
pip install .

# Simple CLI usage
ddg-cli search "python programming" --results 5

# Docker usage
docker build -t ddg-cli .
docker run ddg-cli search "containerization"

# Testing
pytest

All functionality remains intact while significantly improving the development and deployment experience. The CLI maintains full backward compatibility with existing features like search history, bookmarks, multiple output formats, and filtering capabilities.

This pull request was created as a result of the following prompt from Copilot chat.

Task: Modernize Project with Packaging, Docker, and CI/CD

This pull request will introduce several key improvements to modernize the duckduckgo-cli project, making it more robust, easier to install, and simpler to contribute to.

1. Add Standard Python Packaging with pyproject.toml

To align with modern Python standards, we will replace the script-based installation with a pyproject.toml file.

Action:

  • Create a pyproject.toml file in the project root with the following contents:
    [build-system]
    requires = ["setuptools>=61.0"]
    build-backend = "setuptools.build_meta"
    
    [project]
    name = "duckduckgo-cli"
    version = "1.1.0"
    authors = [
      { name="GrecAndrei", email="your-email@example.com" },
    ]
    description = "A feature-rich command-line interface for DuckDuckGo search."
    readme = "README.md"
    requires-python = ">=3.8"
    classifiers = [
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ]
    dependencies = [
        "requests",
    ]
    
    [project.urls]
    "Homepage" = "https://github.com/GrecAndrei/duckduckgo-cli"
    "Bug Tracker" = "https://github.com/GrecAndrei/duckduckgo-cli/issues"
    
    [project.scripts]
    ddg-cli = "ddgs:main"
  • Note: The main script ddgs will need to be converted into a module and have its code placed within a main() function to work with the project.scripts entry point.

2. Introduce Docker for Containerization

To provide a consistent and isolated environment, we will add a Dockerfile.

Action:

  • Create a Dockerfile in the project root:
    # Use an official Python runtime as a parent image
    FROM python:3.10-slim
    
    # Set the working directory in the container
    WORKDIR /app
    
    # Copy the project files into the container
    COPY . .
    
    # Install the project and its dependencies
    RUN pip install .
    
    # Set the entrypoint for the container
    ENTRYPOINT ["ddg-cli"]
    
    # Default command to show help (optional)
    CMD ["--help"]

3. Set Up a CI Workflow with GitHub Actions

To ensure code quality and stability, we will automate testing.

Action:

  • Create the directory .github/workflows/.
  • Inside this directory, create a ci.yml file:
    name: CI
    
    on:
      push:
        branches: [ "main" ]
      pull_request:
        branches: [ "main" ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
        strategy:
          matrix:
            python-version: ["3.8", "3.9", "3.10", "3.11"]
    
        steps:
        - uses: actions/checkout@v3
    
        - name: Set up Python ${{ matrix.python-version }}
          uses: actions/setup-python@v4
          with:
            python-version: ${{ matrix.python-version }}
    
        - name: Install dependencies
          run: |
            python -m pip install --upgrade pip
            pip install .
            pip install pytest # For running tests
    
        - name: Run tests
          run: |
            pytest

4. Update the README.md and Clean Up

The documentation needs to reflect these new installation methods. The old, now-obsolete scripts should be removed.

Action:

  • Update README.md:
    • Replace the Installation section with instructions for pip install . and Docker (docker build -t ddg-cli . and docker run ddg-cli search "hello").
    • Remove references to setup.sh and install.sh.
  • Delete Obsolete Files:
    • Remove install.sh.
    • Remove setup.sh.
    • Remove Makefile as its functionality is replaced by pip and standard Python tooling.

5. Code Refactoring for Entry Point

The main script ddgs needs to be updated to be a proper Python module with a main function that the pyproject.toml can use as an entry point.

Action:

  • Modify the ddgs script to be importable and have a main() function that contains the argument parsing and command logic.
  • Ensure sys.path modifications are no longer needed, as pip install . handles the path correctly.
  • Update src/config.py to use Path.home() / ".config" / "duckduckgo-cli" / "config.ini" as the configuration file path to follow the XDG standard.
  • Update tests to be runnable with pytest from the root directory. This may involve removing relative path manipulations.

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 14, 2025 09:20
…, and pytest tests

Co-authored-by: GrecAndrei <190305710+GrecAndrei@users.noreply.github.com>
… modernization

Co-authored-by: GrecAndrei <190305710+GrecAndrei@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance Project with Packaging, Docker, and CI/CD Modernize Project with Packaging, Docker, and CI/CD Sep 14, 2025
Copilot AI requested a review from GrecAndrei September 14, 2025 09:25
@GrecAndrei GrecAndrei marked this pull request as ready for review September 14, 2025 09:26
@GrecAndrei GrecAndrei merged commit 529ca59 into main Sep 14, 2025
5 of 8 checks passed
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.

2 participants