Skip to content

Commit 68d9dbe

Browse files
committed
refactor(replace python dependcy management tool setup.py to poetry): refactor code
1 parent 57202a4 commit 68d9dbe

File tree

7 files changed

+138
-130
lines changed

7 files changed

+138
-130
lines changed

.coveragerc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[run]
2-
omit = */test_*.py
2+
omit =
3+
*/tests/*
4+
*/site-packages/*
5+
*/distutils/*

.github/workflows/build.yaml renamed to .github/workflows/ci.yaml

+15-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ defaults:
1111
shell: bash
1212

1313
jobs:
14-
black-formatting-check:
15-
name: Check formatting
16-
runs-on: 'ubuntu-latest'
17-
steps:
18-
- uses: actions/checkout@v2.3.4
19-
- uses: actions/setup-python@v2.2.2
20-
- uses: psf/black@stable
2114
build:
2215
name: Build tool
2316
runs-on: ${{ matrix.os }}
@@ -74,5 +67,18 @@ jobs:
7467
poetry install --no-interaction
7568
- name: Run tests
7669
run: poetry run pytest -v
77-
- name: Build artifacts
78-
run: poetry build
70+
71+
Release:
72+
needs: build
73+
# https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482
74+
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && !contains(github.event.head_commit.message, 'chore(release):')
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v2
78+
with:
79+
fetch-depth: 0
80+
- name: Python Semantic Release
81+
uses: relekang/python-semantic-release@master
82+
with:
83+
github_token: ${{ secrets.GITHUB_TOKEN }}
84+
pypi_token: ${{ secrets.PYPI_TOKEN }}

pindo_cli/__init__.py

+1-96
Original file line numberDiff line numberDiff line change
@@ -1,96 +1 @@
1-
import click
2-
import click_spinner
3-
4-
from pindo_cli.http import Token, RefreshToken, Register, SMS, Balance, Organization
5-
6-
7-
@click.group()
8-
@click.option('--debug/--no-debug', default=False)
9-
@click.version_option(None, "--version", "-v")
10-
def cli(debug):
11-
"""
12-
Pindo CLI
13-
A simple Command Line Interface that allow you to create an account
14-
and request a token for using Pindo API
15-
"""
16-
17-
18-
@cli.command() # @cli, not @click!
19-
@click.option(
20-
'--username', '-u', prompt=True, help='Please enter your username')
21-
@click.option(
22-
'--password', '-p',
23-
prompt=True, hide_input=True, help='Please enter your password')
24-
def token(username, password):
25-
"""
26-
Request a token for using Pindo API.
27-
"""
28-
click.echo('token...')
29-
with click_spinner.spinner():
30-
click.echo(Token(username, password))
31-
32-
33-
@cli.command() # @cli, not @click!
34-
@click.option(
35-
'--username', '-u', prompt=True, help='Please enter your username')
36-
@click.option(
37-
'--password', '-p',
38-
prompt=True, hide_input=True, help='Please enter your password')
39-
def refresh_token(username, password):
40-
"""
41-
Refresh a Token.
42-
"""
43-
click.echo('token...')
44-
with click_spinner.spinner():
45-
click.echo(RefreshToken(username, password))
46-
47-
48-
@cli.command()
49-
@click.option(
50-
'--username', '-u', prompt=True, help='Please enter your username')
51-
@click.option(
52-
'--email', '-e', prompt=True, help='Please enter your email')
53-
@click.option(
54-
'--password', '-p', prompt=True, hide_input=True, confirmation_prompt=True,
55-
help='Please enter your password')
56-
def register(username, email, password):
57-
"""
58-
Create a new Pindo account.
59-
"""
60-
click.echo(Register(username, email, password))
61-
62-
63-
@cli.command()
64-
@click.option('--token', prompt=True, help='API Token')
65-
@click.option(
66-
'--to', prompt=True, help='Receiver phone number (+250xxxxxx)',
67-
default='+250785383100')
68-
@click.option(
69-
'--text', prompt=True, help='Message to send', default='Hello Pindo')
70-
@click.option('--sender', prompt=True, default='Pindo', help='Sender name')
71-
def sms(token, to, text, sender):
72-
"""
73-
Send a test message
74-
"""
75-
click.echo(SMS(token, to, text, sender))
76-
77-
78-
@cli.command()
79-
@click.option('--token', prompt=True, help='API Token')
80-
def balance(token):
81-
"""
82-
Get account balance
83-
"""
84-
click.echo(Balance(token))
85-
86-
87-
@cli.command()
88-
@click.option('--token', prompt=True, help='API Token')
89-
@click.option('--name', prompt=True, help='Organization name')
90-
@click.option('--webhook_url', prompt=True, help='Webhook URL. Eg (https://pindo.io/dlr)')
91-
@click.option('--retries_count', prompt=True, type=(int), help='SMS retries count settings')
92-
def org(token, name, webhook_url, retries_count):
93-
"""
94-
Organization
95-
"""
96-
click.echo(Organization(token, name, webhook_url, retries_count))
1+
__version__ = '0.1.0'

pindo_cli/cli.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import click
2+
import click_spinner
3+
4+
from pindo_cli.http import Token, RefreshToken, Register, SMS, Balance, Organization
5+
6+
7+
@click.group()
8+
@click.option('--debug/--no-debug', default=False)
9+
@click.version_option(None, "--version", "-v")
10+
def cli(debug):
11+
"""
12+
Pindo CLI
13+
A simple Command Line Interface that allow you to create an account
14+
and request a token for using Pindo API
15+
"""
16+
17+
18+
@cli.command() # @cli, not @click!
19+
@click.option(
20+
'--username', '-u', prompt=True, help='Please enter your username')
21+
@click.option(
22+
'--password', '-p',
23+
prompt=True, hide_input=True, help='Please enter your password')
24+
def token(username, password):
25+
"""
26+
Request a token for using Pindo API.
27+
"""
28+
click.echo('token...')
29+
with click_spinner.spinner():
30+
click.echo(Token(username, password))
31+
32+
33+
@cli.command() # @cli, not @click!
34+
@click.option(
35+
'--username', '-u', prompt=True, help='Please enter your username')
36+
@click.option(
37+
'--password', '-p',
38+
prompt=True, hide_input=True, help='Please enter your password')
39+
def refresh_token(username, password):
40+
"""
41+
Refresh a Token.
42+
"""
43+
click.echo('token...')
44+
with click_spinner.spinner():
45+
click.echo(RefreshToken(username, password))
46+
47+
48+
@cli.command()
49+
@click.option(
50+
'--username', '-u', prompt=True, help='Please enter your username')
51+
@click.option(
52+
'--email', '-e', prompt=True, help='Please enter your email')
53+
@click.option(
54+
'--password', '-p', prompt=True, hide_input=True, confirmation_prompt=True,
55+
help='Please enter your password')
56+
def register(username, email, password):
57+
"""
58+
Create a new Pindo account.
59+
"""
60+
click.echo(Register(username, email, password))
61+
62+
63+
@cli.command()
64+
@click.option('--token', prompt=True, help='API Token')
65+
@click.option(
66+
'--to', prompt=True, help='Receiver phone number (+250xxxxxx)',
67+
default='+250785383100')
68+
@click.option(
69+
'--text', prompt=True, help='Message to send', default='Hello Pindo')
70+
@click.option('--sender', prompt=True, default='Pindo', help='Sender name')
71+
def sms(token, to, text, sender):
72+
"""
73+
Send a test message
74+
"""
75+
click.echo(SMS(token, to, text, sender))
76+
77+
78+
@cli.command()
79+
@click.option('--token', prompt=True, help='API Token')
80+
def balance(token):
81+
"""
82+
Get account balance
83+
"""
84+
click.echo(Balance(token))
85+
86+
87+
@cli.command()
88+
@click.option('--token', prompt=True, help='API Token')
89+
@click.option('--name', prompt=True, help='Organization name')
90+
@click.option('--webhook_url', prompt=True, help='Webhook URL. Eg (https://pindo.io/dlr)')
91+
@click.option('--retries_count', prompt=True, type=(int), help='SMS retries count settings')
92+
def org(token, name, webhook_url, retries_count):
93+
"""
94+
Organization
95+
"""
96+
click.echo(Organization(token, name, webhook_url, retries_count))

poetry.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[virtualenvs]
2+
in-project = true

pyproject.toml

+11-15
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ packages = [
2424
{ include = "pindo_cli" }
2525
]
2626

27-
[tool.black]
28-
exclude = '''
29-
/(
30-
\.eggs
31-
| \.git
32-
| \.venv
33-
| \.env
34-
| build
35-
| dist
36-
| \.mypy_cache
37-
)\
38-
'''
27+
[tool.semantic_release]
28+
version_variable = [
29+
"pindo_cli/__init__.py:__version__",
30+
"pyproject.toml:version"
31+
]
32+
branch = "master"
33+
upload_to_pypi = true
34+
upload_to_release = true
35+
build_command = "pip install poetry && poetry build"
3936

4037
[tool.poetry.dependencies]
4138
python = "^3.7"
@@ -52,10 +49,9 @@ tomlkit = "^0.7.0"
5249
coverage = {version = "^5.5", extras = ["toml"]}
5350
flake8 = "^3.9.2"
5451
flake8-bugbear = "^21.4.3"
55-
black = "^21.5b0"
5652

5753
[tool.coverage.run]
58-
omit = [".*", "*/site-packages/*"]
54+
omit = [".*", "*/site-packages/*", "*/distutils/*", "*/tests/*"]
5955

6056
[tool.coverage.report]
6157
fail_under = 100
@@ -65,4 +61,4 @@ requires = ["poetry-core>=1.0.0"]
6561
build-backend = "poetry.core.masonry.api"
6662

6763
[tool.poetry.scripts]
68-
pindo = 'pindo_cli:cli'
64+
pindo = 'pindo_cli.cli:cli'

tests/test_cli.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from click.testing import CliRunner
33
from pkg_resources import get_distribution
44

5-
import pindo_cli
5+
import pindo_cli.cli as pindo
66

77

88
@pytest.fixture(scope="module")
@@ -11,34 +11,34 @@ def runner():
1111

1212

1313
def test_pindo_cli(runner):
14-
result = runner.invoke(pindo_cli.cli, ['--help'])
14+
result = runner.invoke(pindo.cli, ['--help'])
1515
assert result.exit_code == 0
1616
assert 'Pindo CLI' in result.output
1717

1818

1919
def test_command_token(runner):
20-
result = runner.invoke(pindo_cli.token, ['-u', 'abc', '-p', 'cbd'])
20+
result = runner.invoke(pindo.token, ['-u', 'abc', '-p', 'cbd'])
2121
assert result.exit_code == 0
2222
assert 'message' in result.output
2323

2424

2525
def test_command_refresh_token(runner):
26-
result = runner.invoke(pindo_cli.refresh_token, ['-u', 'abc', '-p', 'cbd'])
26+
result = runner.invoke(pindo.refresh_token, ['-u', 'abc', '-p', 'cbd'])
2727
assert result.exit_code == 0
2828
assert 'message' in result.output
2929

3030

3131
def test_command_register(runner):
3232
result = runner.invoke(
33-
pindo_cli.register,
33+
pindo.register,
3434
['-u', 'ken', '-e', 'remy@bar.io', '-p', 'bar'])
3535
assert result.exit_code == 0
3636
assert 'message' in result.output
3737

3838

3939
def test_command_sms(runner):
4040
result = runner.invoke(
41-
pindo_cli.sms, [
41+
pindo.sms, [
4242
'--token', 'oeiroeoeioeoiroe',
4343
'--to', '+250785383100',
4444
'--text', 'Hello Pindo',
@@ -50,22 +50,22 @@ def test_command_sms(runner):
5050

5151
def test_command_(runner):
5252
result = runner.invoke(
53-
pindo_cli.balance, [
53+
pindo.balance, [
5454
'--token', 'oeiroeoeioeoiroe',
5555
])
5656
assert result.exit_code == 0
5757
assert 'message' in result.output
5858

5959

6060
def test_pindo_cli_version_flag(runner):
61-
result = runner.invoke(pindo_cli.cli, ['--version', "-v"])
61+
result = runner.invoke(pindo.cli, ['--version', "-v"])
6262
assert result.exit_code == 0
6363
assert get_distribution('pindo-cli').version in result.output
6464

6565

6666
def test_command_org(runner):
6767
result = runner.invoke(
68-
pindo_cli.org, [
68+
pindo.org, [
6969
'--token', 'oeiroeoeioeoiroe',
7070
'--name', 'Pindo',
7171
'--webhook_url', 'https://pindo.io/webhook',

0 commit comments

Comments
 (0)