Skip to content

Commit

Permalink
Merge pull request #52 from deric/ci
Browse files Browse the repository at this point in the history
Use flit to build the package, add simple test
  • Loading branch information
hatarist committed Sep 14, 2023
2 parents 586cee4 + 53d00ac commit 6309899
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches:
- master
pull_request:
branches: [ master ]

jobs:
test:
name: Run tests on ${{ matrix.py }}
runs-on: ubuntu-22.04
strategy:
matrix:
py:
- "3.11"
- "3.10"
- "3.9"
- "3.8"
- "3.7"
- "pypy-3.9"
- "pypy-3.8"
- "pypy-3.7"

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.py }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
check-latest: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip flit
flit install --deps=develop
- name: Lint with flake8
run: flake8 clickhouse_cli --count --max-complexity=31 --show-source --statistics
- name: Test with pytest
run: pytest --cov=clickhouse_cli
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
*.egg-info
dist
build
.coverage
.tox/*
.python-version
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
install: clean
python setup.py install
PYTHON=`which python`

dev:
$(PYTHON) -m pip install --upgrade pip flit
$(PYTHON) -m flit install --deps=develop

build: clean
$(PYTHON) -m flit build

install: build
$(PYTHON) -m flit install --deps=production

clean:
$(PYTHON) setup.py clean
find . -name '*.pyc' -delete
find . -name '*~' -delete
rm -rf clickhouse_cli.egg-info build dist

test:
tox

register:
python setup.py register -r pypi
$(PYTHON) setup.py register -r pypi

upload:
python setup.py sdist upload -r pypi
$(PYTHON) setup.py sdist upload -r pypi
16 changes: 16 additions & 0 deletions clickhouse_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
#
"""Entrypoint module for `python -m clickhouse_cli`.
Why does this file exist, and why __main__? For more info, read:
- https://www.python.org/dev/peps/pep-0338/
- https://docs.python.org/2/using/cmdline.html#cmdoption-m
- https://docs.python.org/3/using/cmdline.html#cmdoption-m
"""

import sys

from clickhouse_cli.cli import run_cli

if __name__ == '__main__':
sys.exit(run_cli())
1 change: 1 addition & 0 deletions clickhouse_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def run_cli(host, port, user, password, arg_password, database, settings, query,
host, port, user, password, database, settings, format, format_stdin, multiline, stacktrace, vi_mode, cookie, insecure
)
cli.run(query, data_input)
return 0


if __name__ == '__main__':
Expand Down
69 changes: 69 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "clickhouse-cli"
description = "A third-party client for the Clickhouse DBMS server."
authors = [{name = "Igor Hatarist", email = "igor@hatari.st"}]
readme = "README.md"
dynamic = ["version"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Database",
"Topic :: Software Development",
]
requires-python = ">=3.7"
dependencies = [
"click>=6.6",
"prompt-toolkit>=2.0",
"pygments>=2.1.3",
"requests>=2.11.1",
"sqlparse>=0.2.2",
]

[project.urls]
Home = "https://github.com/hatarist/clickhouse-cli"
Documentation = "https://github.com/hatarist/clickhouse-cli"
Source = "https://github.com/hatarist/clickhouse-cli"
Tracker = "https://github.com/hatarist/clickhouse-cli/issues"

[project.scripts]
clickhouse-cli = "clickhouse_cli.cli:run_cli"

[project.optional-dependencies]
dev = [
"flake8",
"build",
]
test = [
"pytest",
"pytest-cov",
]
doc = [
"sphinx",
]
tox = [
"virtualenv",
"tox",
]

[tool.flit.sdist]
include = [
"tests/*.py",
"LICENSE.txt",
"Makefile",
"tox.ini",
]
Empty file added tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from clickhouse_cli.cli import run_cli


def test_main_help():
# Call with the --help option as a basic sanity check.
with pytest.raises(SystemExit) as exinfo:
run_cli(["--help", ])
assert exinfo.value.code == 0
25 changes: 25 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tox]
skip_missing_interpreters = True
envlist =
py37
py38
py39
py310
py311
flake8

[testenv]
deps =
pytest
pytest-cov
commands =
pytest --cov=clickhouse_cli {posargs}

[testenv:flake8]
deps =
flake8
commands =
flake8 clickhouse_cli tests setup.py

[flake8]
extend-ignore = E501

0 comments on commit 6309899

Please sign in to comment.