Skip to content

Commit

Permalink
Merge pull request #2 from Felixoid/actions
Browse files Browse the repository at this point in the history
Add actions, tests. Fix building
  • Loading branch information
Felixoid authored Apr 25, 2020
2 parents 8f447cc + 9d6e771 commit 6c05e45
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 14 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Python package

on:
- push
- pull_request

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Python package](https://github.com/Felixoid/clickhouse-plantuml/workflows/Python%20package/badge.svg)

# PlantUML generator for ClickHouse tables

This is a very early version of diagrams generator. It parses `system.tables` table and produces [PlantUML](https://plantuml.com) diagrams source. Here's example of produced diagram:
Expand Down
5 changes: 2 additions & 3 deletions clickhouse_plantuml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from .column import Column
from .table import Table
from .tables import Tables
from .version import __version__


__all__ = ['Client', 'Column', 'Table', 'Tables']

VERSION = (0, 1)
__all__ = ['Client', 'Column', 'Table', 'Tables', '__version__']
3 changes: 3 additions & 0 deletions clickhouse_plantuml/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python

__version__ = '0.1.0'
28 changes: 17 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
#!/usr/bin/env python

from setuptools import setup, find_packages # type: ignore

try:
from clickhouse_plantuml import VERSION
except ModuleNotFoundError:
# Dirty hack to allow `pip install .` in virtualenv
VERSION = (0, 1)
pkg_name = 'clickhouse_plantuml'

with open('{}/version.py'.format(pkg_name)) as f:
for line in f:
if line.startswith('__version__'):
delim = '"' if '"' in line else "'"
__version__ = line.split(delim)[1]

with open('README.md') as f:
long_description = f.read()

setup(
name='clickhouse-plantuml',
version='.'.join(str(d) for d in VERSION),
name=pkg_name,
version=__version__, # noqa: F821 from exec
description='Generates PlantUML diagrams for clickhouse databases',
long_description=long_description,
long_description_content_type="text/markdown",
url='http://github.com/Felixoid/clickhouse-plantuml',
author='Mikhail f. Shiryaev',
author_email='mr.felixoid@gmail.com',
license='License :: OSI Approved :: Apache Software License',
install_requires=['clickhouse-driver'],
packages=find_packages(),
classifiers=[
'Database',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
Expand All @@ -31,15 +35,17 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Scientific/Engineering :: Information Analysis',
'Topic :: Scientific/Engineering :: Visualisatino',
'Topic :: Database',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Scientific/Engineering :: Visualization',
'Topic :: Software Development :: Documentation',
'Topic :: Software Development :: Libraries',
],
python_requires='>=3',
data_files=[('', ['LICENSE', 'example.png'])],
entry_points={
'console_scripts': [
'clickhouse-plantuml = clickhouse_plantuml.__main__:main'
]
}
},
)
Empty file added tests/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions tests/test_plantuml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from clickhouse_plantuml import plantuml


class TestPlantuml(unittest.TestCase):

def test_plantuml_header(self):
assert plantuml.plantuml_header() == '''@startuml
!define Table(x) class x << (T,mistyrose) >>
!define View(x) class x << (V,lightblue) >>
!define MaterializedView(x) class x << (m,orange) >>
!define Distributed(x) class x << (D,violet) >>
hide empty methods
hide stereotypes
skinparam classarrowcolor gray
'''

def test_plantuml_footer(self):
assert plantuml.plantuml_footer() == '@enduml'

def test_table_macros(self):
assert plantuml.table_macros('MaterializedView') == 'MaterializedView'
assert plantuml.table_macros('View') == 'View'
assert plantuml.table_macros('Distributed') == 'Distributed'
assert plantuml.table_macros('SomeRandEngine') == 'Table'

0 comments on commit 6c05e45

Please sign in to comment.