From 7cfede725d91d4ec7a5d40985e6ebb211264fe7d Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 00:42:14 +0800 Subject: [PATCH 01/12] feat: integrated with typer --- .github/workflows/ci.yml | 6 ++-- compose_viz/__init__.py | 2 ++ compose_viz/__main__.py | 9 +++++ compose_viz/cli.py | 59 +++++++++++++++++++++++++++++++ compose_viz/compose.py | 10 ++++++ compose_viz/parser.py | 10 ++++++ compose_viz/service.py | 13 +++++++ tests/__init__.py | 0 tests/test_cli.py | 14 ++++++++ tests/test_parse_file.py | 29 +++++++++++++++ tests/test_validate_input_file.py | 5 --- tests/test_version.py | 13 +++++++ tests/validate_input_file.py | 6 ---- 13 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 compose_viz/__init__.py create mode 100644 compose_viz/__main__.py create mode 100644 compose_viz/cli.py create mode 100644 compose_viz/compose.py create mode 100644 compose_viz/parser.py create mode 100644 compose_viz/service.py create mode 100644 tests/__init__.py create mode 100644 tests/test_cli.py create mode 100644 tests/test_parse_file.py delete mode 100644 tests/test_validate_input_file.py create mode 100644 tests/test_version.py delete mode 100644 tests/validate_input_file.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e1b848..1ac51c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ main ] + branches: [ main, dev ] pull_request: - branches: [ main ] + branches: [ main, dev ] jobs: test: @@ -91,4 +91,4 @@ jobs: run: | pip install pytest pip install pytest-cov - python tests/test_validate_input_file.py tests/validate_input_file.py tests/in/docker-compose.yaml + pytest diff --git a/compose_viz/__init__.py b/compose_viz/__init__.py new file mode 100644 index 0000000..bce9bc5 --- /dev/null +++ b/compose_viz/__init__.py @@ -0,0 +1,2 @@ +__app_name__ = "compose_viz" +__version__ = "0.1.0" diff --git a/compose_viz/__main__.py b/compose_viz/__main__.py new file mode 100644 index 0000000..6f832b4 --- /dev/null +++ b/compose_viz/__main__.py @@ -0,0 +1,9 @@ +from compose_viz import cli, __app_name__ + + +def main() -> None: + cli.app(prog_name=__app_name__) + + +if __name__ == "__main__": + main() diff --git a/compose_viz/cli.py b/compose_viz/cli.py new file mode 100644 index 0000000..49cc8f6 --- /dev/null +++ b/compose_viz/cli.py @@ -0,0 +1,59 @@ +from ast import parse +from enum import Enum +import typer +from typing import Optional +from compose_viz import __app_name__, __version__ +from compose_viz.compose import Compose +from compose_viz.parser import Parser + + +class VisualizationFormats(str, Enum): + png = "PNG" + dot = "DOT" + + +app = typer.Typer( + invoke_without_command=True, + no_args_is_help=True, + subcommand_metavar="", + add_completion=False, +) + + +def _version_callback(value: bool) -> None: + if value: + typer.echo(f"{__app_name__} {__version__}") + raise typer.Exit() + + +@app.callback() +def compose_viz( + input_path: str, + output_path: Optional[str] = typer.Option( + None, + "--output_path", + "-o", + help="Output path for the generated visualization.", + ), + format: VisualizationFormats = typer.Option( + "PNG", + "--format", + "-m", + help="Output format for the generated visualization.", + ), + _: Optional[bool] = typer.Option( + None, + "--version", + "-v", + help="Show the version of compose_viz.", + callback=_version_callback, + is_eager=True, + ) +) -> None: + parser = Parser() + compose = parser.parse(input_path) + + if compose: + typer.echo(f"Successfully parsed {input_path}") + + raise typer.Exit() diff --git a/compose_viz/compose.py b/compose_viz/compose.py new file mode 100644 index 0000000..6c65a8a --- /dev/null +++ b/compose_viz/compose.py @@ -0,0 +1,10 @@ +from typing import List +from compose_viz.service import Service + + +class Compose: + def __init__(self, services: List[Service]) -> None: + self.services = services + + def extract_networks(self) -> List[str]: + raise NotImplementedError diff --git a/compose_viz/parser.py b/compose_viz/parser.py new file mode 100644 index 0000000..1f44bbc --- /dev/null +++ b/compose_viz/parser.py @@ -0,0 +1,10 @@ +from compose_viz.compose import Compose + + +class Parser: + def __init__(self): + pass + + def parse(self, file_path: str) -> Compose: + # validate input file using `docker-compose config -q sys.argv[1]` first + raise NotImplementedError diff --git a/compose_viz/service.py b/compose_viz/service.py new file mode 100644 index 0000000..6e42483 --- /dev/null +++ b/compose_viz/service.py @@ -0,0 +1,13 @@ +from typing import List + + +class Service: + def __init__(self, name: str, image: str, ports: List[str] = [], networks: List[str] = [], volumes: List[str] = [], depends_on: List[str] = [], links: List[str] = [], extends: List[str] = []) -> None: + self.name = name + self.image = image + self.ports = ports + self.networks = networks + self.volumes = volumes + self.depends_on = depends_on + self.links = links + self.extends = extends diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..cc809fe --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,14 @@ +import pytest +from typer.testing import CliRunner +from compose_viz import cli + + +runner = CliRunner() + + +def test_cli(): + input_path = "tests/in/000001.yaml" + result = runner.invoke(cli.app, [input_path]) + + assert result.exit_code == 0 + assert f"Successfully parsed {input_path}\n" in result.stdout diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py new file mode 100644 index 0000000..4854c47 --- /dev/null +++ b/tests/test_parse_file.py @@ -0,0 +1,29 @@ +from typer.testing import CliRunner +from compose_viz.parser import Parser +from compose_viz.compose import Compose +from compose_viz.service import Service + + +def test_parse_file(): + expected: Compose = Compose([ + Service( + name='frontend', + image='awesome/webapp', + networks=['front-tier', 'back-tier'], + ), + Service( + name='monitoring', + image='awesome/monitoring', + networks=['admin'], + ), + Service( + name='backend', + image='awesome/backend', + networks=['back-tier', 'admin'], + ), + ]) + + parser = Parser() + actual = parser.parse('tests/in/000001.yaml') + + assert actual == expected diff --git a/tests/test_validate_input_file.py b/tests/test_validate_input_file.py deleted file mode 100644 index 54140c0..0000000 --- a/tests/test_validate_input_file.py +++ /dev/null @@ -1,5 +0,0 @@ -import sys -import pytest - -if __name__ == '__main__': - pytest.main([sys.argv[1]]) \ No newline at end of file diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..b1b1b49 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,13 @@ +import pytest +from typer.testing import CliRunner +from compose_viz import cli, __app_name__, __version__ + + +runner = CliRunner() + + +def test_version(): + result = runner.invoke(cli.app, ["--version"]) + + assert result.exit_code == 0 + assert f"{__app_name__} {__version__}\n" in result.stdout diff --git a/tests/validate_input_file.py b/tests/validate_input_file.py deleted file mode 100644 index 73a4f3e..0000000 --- a/tests/validate_input_file.py +++ /dev/null @@ -1,6 +0,0 @@ -import os -import sys - -def test_validate_input_file(): - process = os.system("docker-compose -f " + sys.argv[2] + " config -q") - assert process == 0 \ No newline at end of file From a444e46d9dbd5dcf76fdab07a3be32907c6128a4 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 00:47:31 +0800 Subject: [PATCH 02/12] fix: add missing requirements.txt --- .github/workflows/ci.yml | 3 +-- requirements.txt | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ac51c8..4db210e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,5 @@ jobs: - name: Validate Custom Input File run: | - pip install pytest - pip install pytest-cov + pip install -r requirements.txt pytest diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..21ff51d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pytest==7.1.1 +typer==0.4.1 From 1297b0e671c6572c98c43064728e66839dcc388f Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 14:57:06 +0800 Subject: [PATCH 03/12] chore: add release-tagged-version.yml --- .github/workflows/release-tagged-version.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/release-tagged-version.yml diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml new file mode 100644 index 0000000..ad1c11f --- /dev/null +++ b/.github/workflows/release-tagged-version.yml @@ -0,0 +1,18 @@ +--- +name: "Release Tagged Version" + +on: + push: + tags: + - "v*" + +jobs: + tagged-release: + runs-on: "ubuntu-latest" + + steps: + - name: "Release Tagged Version" + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false \ No newline at end of file From 85a2fac952766d4b4dcb95ea0d099c41f8dc7e37 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 15:24:46 +0800 Subject: [PATCH 04/12] chore: add cd.yml --- .github/workflows/cd.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..1f6a2a0 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,14 @@ +name: CD +on: + release: + types: [ created ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build and Publish to PyPi + uses: JRubics/poetry-publish@v1.10 + with: + pypi_token: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file From 607f9ed4b5e136bf605983eae142c3a84a987f15 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 15:57:04 +0800 Subject: [PATCH 05/12] feat: integrated with poetry --- .github/workflows/release-tagged-version.yml | 24 ++- poetry.lock | 191 +++++++++++++++++++ pyproject.toml | 17 ++ 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml index ad1c11f..c941a32 100644 --- a/.github/workflows/release-tagged-version.yml +++ b/.github/workflows/release-tagged-version.yml @@ -11,8 +11,30 @@ jobs: runs-on: "ubuntu-latest" steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + - name: Switch to Current Branch + run: git checkout ${{ env.BRANCH }} + + - name: Setup Python 3.10.4 + uses: actions/setup-python@v3 + with: + python-version: '3.10.4' + + - name: Setup Poetry + uses: Gr1N/setup-poetry@v7 + with: + poetry-version: 1.1.7 + run: | + poetry install + poetry build + - name: "Release Tagged Version" uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - prerelease: false \ No newline at end of file + prerelease: false + files: | + LICENSE + dist/** \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..381ddcb --- /dev/null +++ b/poetry.lock @@ -0,0 +1,191 @@ +[[package]] +name = "atomicwrites" +version = "1.4.0" +description = "Atomic file writes." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "attrs" +version = "21.4.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.extras] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] +docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] + +[[package]] +name = "click" +version = "8.1.3" +description = "Composable command line interface toolkit" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.4" +description = "Cross-platform colored terminal text." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "iniconfig" +version = "1.1.1" +description = "iniconfig: brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "packaging" +version = "21.3" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" + +[[package]] +name = "pluggy" +version = "1.0.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "py" +version = "1.11.0" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "pyparsing" +version = "3.0.8" +description = "pyparsing module - Classes and methods to define and execute parsing grammars" +category = "dev" +optional = false +python-versions = ">=3.6.8" + +[package.extras] +diagrams = ["railroad-diagrams", "jinja2"] + +[[package]] +name = "pytest" +version = "7.1.2" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} +attrs = ">=19.2.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +py = ">=1.8.2" +tomli = ">=1.0.0" + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] + +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +category = "dev" +optional = false +python-versions = ">=3.7" + +[[package]] +name = "typer" +version = "0.4.1" +description = "Typer, build great CLIs. Easy to code. Based on Python type hints." +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +click = ">=7.1.1,<9.0.0" + +[package.extras] +all = ["colorama (>=0.4.3,<0.5.0)", "shellingham (>=1.3.0,<2.0.0)"] +dev = ["autoflake (>=1.3.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)"] +doc = ["mkdocs (>=1.1.2,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "mdx-include (>=1.4.1,<2.0.0)"] +test = ["shellingham (>=1.3.0,<2.0.0)", "pytest (>=4.4.0,<5.4.0)", "pytest-cov (>=2.10.0,<3.0.0)", "coverage (>=5.2,<6.0)", "pytest-xdist (>=1.32.0,<2.0.0)", "pytest-sugar (>=0.9.4,<0.10.0)", "mypy (==0.910)", "black (>=22.3.0,<23.0.0)", "isort (>=5.0.6,<6.0.0)"] + +[metadata] +lock-version = "1.1" +python-versions = "^3.9" +content-hash = "a80ea7abd86b8e5579a192dfa02a55d2219a3a1850bad12da89c30aa42e99156" + +[metadata.files] +atomicwrites = [ + {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, + {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, +] +attrs = [ + {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, + {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, +] +click = [ + {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, + {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, +] +colorama = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] +iniconfig = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, +] +packaging = [ + {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, + {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, +] +pluggy = [ + {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, + {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, +] +py = [ + {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, + {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, +] +pyparsing = [ + {file = "pyparsing-3.0.8-py3-none-any.whl", hash = "sha256:ef7b523f6356f763771559412c0d7134753f037822dad1b16945b7b846f7ad06"}, + {file = "pyparsing-3.0.8.tar.gz", hash = "sha256:7bf433498c016c4314268d95df76c81b842a4cb2b276fa3312cfb1e1d85f6954"}, +] +pytest = [ + {file = "pytest-7.1.2-py3-none-any.whl", hash = "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c"}, + {file = "pytest-7.1.2.tar.gz", hash = "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45"}, +] +tomli = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] +typer = [ + {file = "typer-0.4.1-py3-none-any.whl", hash = "sha256:e8467f0ebac0c81366c2168d6ad9f888efdfb6d4e1d3d5b4a004f46fa444b5c3"}, + {file = "typer-0.4.1.tar.gz", hash = "sha256:5646aef0d936b2c761a10393f0384ee6b5c7fe0bb3e5cd710b17134ca1d99cff"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..44e45d3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "compose-viz" +version = "0.1.0" +description = "A docker-compose/podman-compose graph visualization tool that allows you to gernerate graph in DOT format or PNG." +authors = ["Xyphuz Wu "] +license = "MIT" + +[tool.poetry.dependencies] +python = "^3.9" +typer = "^0.4.1" + +[tool.poetry.dev-dependencies] +pytest = "^7.1.2" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" From c4b6408eaa8f044dc7aa1d24dd616f6384c82ad6 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 16:11:49 +0800 Subject: [PATCH 06/12] ci: integrated with poetry --- .github/workflows/ci.yml | 12 +++++++++--- .github/workflows/release-tagged-version.yml | 2 +- requirements.txt | 2 -- 3 files changed, 10 insertions(+), 6 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4db210e..3ba2b8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,8 +86,14 @@ jobs: docker-compose -f tests/in/111101.yaml config -q docker-compose -f tests/in/111110.yaml config -q docker-compose -f tests/in/111111.yaml config -q - + + - name: Setup Poetry + uses: Gr1N/setup-poetry@v7 + with: + poetry-version: 1.1.7 + - run: | + poetry install + - name: Validate Custom Input File run: | - pip install -r requirements.txt - pytest + poetry run python -m pytest diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml index c941a32..21e7dde 100644 --- a/.github/workflows/release-tagged-version.yml +++ b/.github/workflows/release-tagged-version.yml @@ -26,7 +26,7 @@ jobs: uses: Gr1N/setup-poetry@v7 with: poetry-version: 1.1.7 - run: | + - run: | poetry install poetry build diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 21ff51d..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest==7.1.1 -typer==0.4.1 From 6228e1062e2584ad57b2666e918ab3f00921544a Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 22:33:43 +0800 Subject: [PATCH 07/12] fix: avoid installing unnecessary root module by adding --no-root --- .github/workflows/ci.yml | 8 +++++--- .github/workflows/release-tagged-version.yml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ba2b8b..5d0ae78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,9 +91,11 @@ jobs: uses: Gr1N/setup-poetry@v7 with: poetry-version: 1.1.7 - - run: | - poetry install + + - name: Install Dependencies + run: | + poetry install --no-root - name: Validate Custom Input File run: | - poetry run python -m pytest + pytest diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml index 21e7dde..9635433 100644 --- a/.github/workflows/release-tagged-version.yml +++ b/.github/workflows/release-tagged-version.yml @@ -27,7 +27,7 @@ jobs: with: poetry-version: 1.1.7 - run: | - poetry install + poetry install --no-root poetry build - name: "Release Tagged Version" From 31e77052327a5afad532d64fb9cdb2f2c8e2d05b Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 22:35:58 +0800 Subject: [PATCH 08/12] fix: missing command for testing in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d0ae78..c40e9d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,4 +98,4 @@ jobs: - name: Validate Custom Input File run: | - pytest + poetry run python -m pytest From 3f4c41a8838b185a3570445e5056a9b212a810cc Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 22:59:25 +0800 Subject: [PATCH 09/12] chore: remove unnecessary imports --- compose_viz/cli.py | 2 -- tests/test_cli.py | 1 - tests/test_parse_file.py | 1 - tests/test_version.py | 1 - 4 files changed, 5 deletions(-) diff --git a/compose_viz/cli.py b/compose_viz/cli.py index 49cc8f6..2325329 100644 --- a/compose_viz/cli.py +++ b/compose_viz/cli.py @@ -1,9 +1,7 @@ -from ast import parse from enum import Enum import typer from typing import Optional from compose_viz import __app_name__, __version__ -from compose_viz.compose import Compose from compose_viz.parser import Parser diff --git a/tests/test_cli.py b/tests/test_cli.py index cc809fe..3f427b5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,3 @@ -import pytest from typer.testing import CliRunner from compose_viz import cli diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index 4854c47..bfc6b4a 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -1,4 +1,3 @@ -from typer.testing import CliRunner from compose_viz.parser import Parser from compose_viz.compose import Compose from compose_viz.service import Service diff --git a/tests/test_version.py b/tests/test_version.py index b1b1b49..1d2abd6 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,4 +1,3 @@ -import pytest from typer.testing import CliRunner from compose_viz import cli, __app_name__, __version__ From 6adc0abfcabbafb980a073483909bc9e26f52176 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sun, 8 May 2022 23:03:16 +0800 Subject: [PATCH 10/12] feat: integrated with poetry scripts --- compose_viz/__main__.py | 8 ++------ compose_viz/cli.py | 4 ++++ pyproject.toml | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/compose_viz/__main__.py b/compose_viz/__main__.py index 6f832b4..4065f3b 100644 --- a/compose_viz/__main__.py +++ b/compose_viz/__main__.py @@ -1,9 +1,5 @@ -from compose_viz import cli, __app_name__ - - -def main() -> None: - cli.app(prog_name=__app_name__) +from compose_viz.cli import start_cli if __name__ == "__main__": - main() + start_cli() diff --git a/compose_viz/cli.py b/compose_viz/cli.py index 2325329..d2bf1d3 100644 --- a/compose_viz/cli.py +++ b/compose_viz/cli.py @@ -55,3 +55,7 @@ def compose_viz( typer.echo(f"Successfully parsed {input_path}") raise typer.Exit() + + +def start_cli() -> None: + app(prog_name=__app_name__) diff --git a/pyproject.toml b/pyproject.toml index 44e45d3..6ae61bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,3 +15,6 @@ pytest = "^7.1.2" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +compose_viz = "compose_viz.cli:start_cli" From 14966ab00f503f4f529a39dc1e497cbac6478c9b Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Mon, 9 May 2022 00:52:20 +0800 Subject: [PATCH 11/12] style: adjust the ymls' style --- .github/workflows/cd.yml | 1 + .github/workflows/release-tagged-version.yml | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 1f6a2a0..50639c1 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,5 @@ name: CD + on: release: types: [ created ] diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml index 9635433..7ca6abc 100644 --- a/.github/workflows/release-tagged-version.yml +++ b/.github/workflows/release-tagged-version.yml @@ -1,5 +1,4 @@ ---- -name: "Release Tagged Version" +name: Release Tagged Version on: push: From d8c45c5fde44e0d2628f8c4519c7a1a95a62649c Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Sat, 14 May 2022 22:14:34 +0800 Subject: [PATCH 12/12] chore: update cd configuration --- .github/workflows/cd.yml | 6 ++++-- .github/workflows/release-tagged-version.yml | 6 ++++++ pyproject.toml | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 50639c1..0868300 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,14 +1,16 @@ name: CD on: - release: - types: [ created ] + push: + tags: + - "v*" jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Build and Publish to PyPi uses: JRubics/poetry-publish@v1.10 with: diff --git a/.github/workflows/release-tagged-version.yml b/.github/workflows/release-tagged-version.yml index 7ca6abc..3c6d547 100644 --- a/.github/workflows/release-tagged-version.yml +++ b/.github/workflows/release-tagged-version.yml @@ -5,6 +5,12 @@ on: tags: - "v*" +permissions: + id-token: "write" + contents: "write" + packages: "write" + pull-requests: "read" + jobs: tagged-release: runs-on: "ubuntu-latest" diff --git a/pyproject.toml b/pyproject.toml index 6ae61bc..3b7de75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,13 @@ name = "compose-viz" version = "0.1.0" description = "A docker-compose/podman-compose graph visualization tool that allows you to gernerate graph in DOT format or PNG." authors = ["Xyphuz Wu "] +readme = "README.md" license = "MIT" +homepage = "https://github.com/compose-viz/compose-viz" +repository = "https://github.com/compose-viz/compose-viz" +include = [ + "LICENSE", +] [tool.poetry.dependencies] python = "^3.9" @@ -17,4 +23,4 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] -compose_viz = "compose_viz.cli:start_cli" +cpv = "compose_viz.cli:start_cli"