Skip to content

Latest commit

 

History

History
251 lines (206 loc) · 8.88 KB

.Prothiel.md

File metadata and controls

251 lines (206 loc) · 8.88 KB

HarmonAI

Description

HarmonAIは、リポジトリの名前、Githubのオーナー名、パッケージ名から、PyPIとGithubのshields.ioバッジのHTMLコードを生成し、READMEファイルのテンプレートを出力するためのPythonライブラリです。このライブラリは、パッケージとしてインポートして使用することも、コマンドラインインターフェース(CLI)から直接使用することもできます。

File Structure

- harmon_ai/
  - __init__.py
  - harmon_ai.py
  - cli.py
  - templates/
    - __init__.py
    - badges_template.html
    - readme_template.md
- tests/
  - __init__.py
  - test_harmon_ai.py
- setup.py
- README.md
- requirements.txt

Source Code

harmon_ai/init.py

from .harmon_ai import HarmonAI

harmon_ai/harmon_ai.py

import os

class HarmonAI:
    @staticmethod
    def generate_readme(repo_name, owner_name, package_name, icon_url, title, subtitle, important_message, sections_content):
        with open(os.path.join(os.path.dirname(__file__), "templates", "readme_template.md"), "r") as file:
            template = file.read()

        badge_template = HarmonAI.generate_badges(repo_name, owner_name, package_name)

        template = template.replace("{repo_name}", repo_name)
        template = template.replace("{owner_name}", owner_name)
        template = template.replace("{package_name}", package_name)
        template = template.replace("{icon_url}", icon_url)
        template = template.replace("{title}", title)
        template = template.replace("{subtitle}", subtitle)
        template = template.replace("{badges}", badge_template)
        template = template.replace("{important_message}", important_message)
        template = template.replace("{sections_content}", sections_content)

        return template

    @staticmethod
    def generate_badges(repo_name, owner_name, package_name):
        with open(os.path.join(os.path.dirname(__file__), "templates", "badges_template.html"), "r") as file:
            template = file.read()

        template = template.replace("{repo_name}", repo_name)
        template = template.replace("{owner_name}", owner_name)
        template = template.replace("{package_name}", package_name)

        return template

harmon_ai/cli.py

import argparse
from .harmon_ai import HarmonAI

def main():
    parser = argparse.ArgumentParser(description="Generate README template and badges for a GitHub repository.")
    parser.add_argument("repo_name", help="Name of the GitHub repository")
    parser.add_argument("owner_name", help="GitHub username of the repository owner")
    parser.add_argument("package_name", help="Name of the package")
    parser.add_argument("icon_url", help="URL of the icon to display in the README")
    parser.add_argument("title", help="Title of the project")
    parser.add_argument("subtitle", help="Subtitle of the project")
    parser.add_argument("important_message", help="Important message to display in the README")
    parser.add_argument("sections_content", help="Content of the README sections (introduction, demo, getting_started, updates, contributing, license, acknowledgements) in markdown format")

    args = parser.parse_args()

    readme_template = HarmonAI.generate_readme(
        args.repo_name,
        args.owner_name,
        args.package_name,
        args.icon_url,
        args.title,
        args.subtitle,
        args.important_message,
        args.sections_content
    )

    print(readme_template)

if __name__ == "__main__":
    main()

harmon_ai/templates/init.py

# Empty file

harmon_ai/templates/badges_template.html

<img alt="PyPI - Version" src="https://img.shields.io/pypi/v/{package_name}">
<img alt="PyPI - Format" src="https://img.shields.io/pypi/format/{package_name}">
<img alt="PyPI - Implementation" src="https://img.shields.io/pypi/implementation/{package_name}">
<img alt="PyPI - Status" src="https://img.shields.io/pypi/status/{package_name}">
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dd/{package_name}">
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dw/{package_name}">
<a href="https://github.com/{owner_name}/{repo_name}" title="Go to GitHub repo"><img src="https://img.shields.io/static/v1?label={repo_name}&message={owner_name}&color=blue&logo=github"></a>
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/{owner_name}/{repo_name}">
<a href="https://github.com/{owner_name}/{repo_name}"><img alt="forks - {owner_name}" src="https://img.shields.io/github/forks/{repo_name}/{owner_name}?style=social"></a>
<a href="https://github.com/{owner_name}/{repo_name}"><img alt="GitHub Last Commit" src="https://img.shields.io/github/last-commit/{owner_name}/{repo_name}"></a>
<a href="https://github.com/{owner_name}/{repo_name}"><img alt="GitHub Top Language" src="https://img.shields.io/github/languages/top/{owner_name}/{repo_name}"></a>
<img alt="GitHub Release" src="https://img.shields.io/github/v/release/{owner_name}/{repo_name}?color=red">
<img alt="GitHub Tag" src="https://img.shields.io/github/v/tag/{owner_name}/{repo_name}?sort=semver&color=orange">
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/{owner_name}/{repo_name}/publish-to-pypi.yml">

harmon_ai/templates/readme_template.md

<p align="center">
<img src="{icon_url}" width="100%">
<br>
<h1 align="center">{title}</h1>
<h2 align="center">
  {subtitle}

  {badges}

</h2>

</p>

>[!IMPORTANT]
>{important_message}

{sections_content}

tests/init.py

# Empty file

tests/test_harmon_ai.py

import unittest
from harmon_ai import HarmonAI

class TestHarmonAI(unittest.TestCase):
    def test_generate_badges(self):
        repo_name = "test-repo"
        owner_name = "test-owner"
        package_name = "test-package"
        
        with open("harmon_ai/templates/badges_template.html", "r") as file:
            expected_output = file.read()

        expected_output = expected_output.replace("{repo_name}", repo_name)
        expected_output = expected_output.replace("{owner_name}", owner_name)
        expected_output = expected_output.replace("{package_name}", package_name)
        
        result = HarmonAI.generate_badges(repo_name, owner_name, package_name)
        self.assertEqual(result, expected_output)

    def test_generate_readme(self):
        repo_name = "test-repo"
        owner_name = "test-owner"
        package_name = "test-package"
        icon_url = "https://example.com/icon.png"
        title = "Test Title"
        subtitle = "Test Subtitle"
        important_message = "This is an important message."
        
        sections_content = '''
    ## Introduction
    This is the introduction.

    ## Demo
    This is the demo.

    ## Getting Started
    This is how to get started.

    ## Updates
    These are the updates.

    ## Contributing
    This is how to contribute.

    ## License
    This is the license.

    ## Acknowledgements
    These are the acknowledgements.
'''
        
        with open("harmon_ai/templates/readme_template.md", "r") as file:
            expected_output = file.read()

        expected_output = expected_output.replace("{repo_name}", repo_name)
        expected_output = expected_output.replace("{owner_name}", owner_name)
        expected_output = expected_output.replace("{package_name}", package_name)
        expected_output = expected_output.replace("{icon_url}", icon_url)
        expected_output = expected_output.replace("{title}", title)
        expected_output = expected_output.replace("{subtitle}", subtitle)
        expected_output = expected_output.replace("{badges}", HarmonAI.generate_badges(repo_name, owner_name, package_name))
        expected_output = expected_output.replace("{important_message}", important_message)
        expected_output = expected_output.replace("{sections_content}", sections_content)
        
        result = HarmonAI.generate_readme(repo_name, owner_name, package_name, icon_url, title, subtitle, important_message, sections_content)
        self.assertEqual(result, expected_output)

if __name__ == "__main__":
    unittest.main()

setup.py

from setuptools import setup, find_packages

setup(
    name="harmon_ai",
    version="0.1.0",
    packages=find_packages(),
    include_package_data=True,
    install_requires=[
        # Add any dependencies here
    ],
    entry_points={
        "console_scripts": [
            "harmon-ai = harmon_ai.cli:main"
        ]
    },
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
    ],
)