Skip to content

Commit 54bdb28

Browse files
authored
Merge pull request #11 from jesseward/jesseward/archive-cleanup
cleanup before archive mode in repo
2 parents 31f98fc + 43899cc commit 54bdb28

File tree

10 files changed

+110
-33
lines changed

10 files changed

+110
-33
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.8", "3.9", "3.10"]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install flake8 pytest pytest-mock black
27+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28+
- name: Lint with flake8
29+
run: |
30+
# stop the build if there are Python syntax errors or undefined names
31+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
34+
- name: Check formatting with black
35+
run: |
36+
black --check .
37+
- name: Test with pytest
38+
run: |
39+
PYTHONPATH=. pytest tests/

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.PHONY: test lint clean
2+
3+
test:
4+
PYTHONPATH=. .venv/bin/pytest tests/
5+
6+
lint:
7+
.venv/bin/flake8 discogs_cli tests
8+
9+
clean:
10+
rm -rf .pytest_cache
11+
rm -rf discogs_cli/__pycache__
12+
rm -rf tests/__pycache__

discogs_cli/discogs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _separator(self, title):
9797
return (
9898
" -- [ "
9999
+ click.style(title, fg=Discogs.LABEL_COLOUR)
100-
+ " ] {line}".format(title=title, line="-" * (MAX - 4 - len(title) - RIGHT))
100+
+ " ] {line}".format(line="-" * (MAX - 4 - len(title) - RIGHT))
101101
)
102102

103103
def _page_artists(self, artists, page=1, end=1):
@@ -220,7 +220,8 @@ def show(self):
220220
class Artist(Discogs):
221221
"""
222222
Nightmares On Wax
223-
Members : George Evelyn [640294], Kevin Harper [427445], Robin Taylor-Firth [31653]
223+
Members : George Evelyn [640294], Kevin Harper [427445],
224+
Robin Taylor-Firth [31653]
224225
Variations : N O W, N.O.W, N.O.W., Nightmare On Wax, Nights On Wax, NoW
225226
In groups :
226227
--[ Profile ] ------------------------------------
@@ -364,6 +365,7 @@ def show(self):
364365
.get("average")
365366
)
366367
)
368+
367369
out.append(self._separator("Tracklist"))
368370
for t in self.discogs.data["tracklist"]:
369371
duration = " {0}".format(t.get("duration"))

discogs_cli/ext/utils.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import re
1717
import shlex
1818

19-
import six
2019
from prompt_toolkit.completion import Completion
2120

2221
from ..completions import META_LOOKUP
@@ -143,19 +142,6 @@ def _find_collection_matches(self, word, collection, fuzzy):
143142
name, -len(word), display=display, display_meta=display_meta
144143
)
145144

146-
def _shlex_split(self, text):
147-
"""Wrapper for shlex, because it does not seem to handle unicode in 2.6.
148-
149-
:type text: str
150-
:param text: A string to split.
151-
152-
:rtype: list
153-
:return: A list that contains words for each split element of text.
154-
"""
155-
if six.PY2:
156-
text = text.encode("utf-8")
157-
return shlex.split(text)
158-
159145
def _safe_split(self, text):
160146
"""Safely splits the input text.
161147
@@ -168,7 +154,6 @@ def _safe_split(self, text):
168154
:return: A list that contains words for each split element of text.
169155
"""
170156
try:
171-
words = self._shlex_split(text)
172-
return words
173-
except:
157+
return shlex.split(text)
158+
except ValueError:
174159
return text

discogs_cli/main.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import subprocess
44

55
import click
6-
from prompt_toolkit import prompt
6+
from prompt_toolkit import PromptSession
77
from prompt_toolkit.history import InMemoryHistory
88
from prompt_toolkit.lexers import PygmentsLexer
9-
from prompt_toolkit.styles.pygments import style_from_pygments_cls
9+
from prompt_toolkit.styles import style_from_pygments_cls
1010
from pygments.styles import get_style_by_name
1111

1212
from .__init__ import __version__
13+
1314
# from .completion import command_completer
1415
from .ext.completer import Completer
1516
from .ext.utils import TextUtils
@@ -31,28 +32,28 @@ def execute(cmd):
3132

3233
def cli():
3334
history = InMemoryHistory()
35+
session = PromptSession(history=history)
3436
style = style_from_pygments_cls(get_style_by_name("monokai"))
3537
lexer = PygmentsLexer(DiscogsCliLexer)
3638
completer = Completer(fuzzy_match=False, text_utils=TextUtils())
3739

3840
SYNTAX = "Syntax: ogs <command> [options]"
3941

40-
click.secho(" _ _ _ _ ", fg="yellow")
41-
click.secho(" __| (_)___ ___ ___ __ _ ___ ___| (_)", fg="yellow")
42-
click.secho(" / _` | / __|/ __/ _ \ / _` / __|_____ / __| | |", fg="yellow")
43-
click.secho("| (_| | \__ \ (_| (_) | (_| \__ \_____| (__| | |", fg="yellow")
44-
click.secho(" \__,_|_|___/\___\___/ \__, |___/ \___|_|_|", fg="yellow")
45-
click.secho(" |___/", fg="yellow")
42+
click.secho(r" _ _ _ _ ", fg="yellow")
43+
click.secho(r" __| (_)___ ___ ___ __ _ ___ ___| (_)", fg="yellow")
44+
click.secho(r" / _` | / __|/ __/ _ \ / _` / __|_____ / __| | |", fg="yellow")
45+
click.secho(r"| (_| | \__ \ (_| (_) | (_| \__ \_____| (__| | |", fg="yellow")
46+
click.secho(r" \__,_|_|___/\___\___/ \__, |___/ \___|_|_|", fg="yellow")
47+
click.secho(r" |___/", fg="yellow")
4648

4749
click.echo("Version:" + __version__)
4850
click.echo(SYNTAX)
4951

5052
while True:
5153
try:
52-
text = prompt(
54+
text = session.prompt(
5355
"discogs-cli >>> ",
5456
style=style,
55-
history=history,
5657
completer=completer,
5758
lexer=lexer,
5859
)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ oauthlib==3.2.2
77
prompt-toolkit==3.0.43
88
Pygments==2.17.2
99
requests==2.31.0
10-
six==1.16.0
1110
urllib3==2.1.0
1211
wcwidth==0.2.13

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"Pygments>=2.15.0",
3030
"click>=6.7",
3131
"discogs-client>=2.2.1",
32-
"prompt-toolkit>=1.0.13",
32+
"prompt-toolkit>=3.0.0",
3333
"requests>=2.31.0",
3434
],
3535
entry_points={
@@ -43,8 +43,9 @@
4343
classifiers=[
4444
"Environment :: Console",
4545
"Development Status :: 5 - Production/Stable",
46-
"Programming Language :: Python :: 2.6",
47-
"Programming Language :: Python :: 2.7",
46+
"Programming Language :: Python :: 3.8",
47+
"Programming Language :: Python :: 3.9",
48+
"Programming Language :: Python :: 3.10",
4849
"License :: OSI Approved :: MIT License",
4950
"Operating System :: OS Independent",
5051
],

tests/test_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from discogs_cli.ext.utils import TextUtils
2+
3+
4+
class TestTextUtils:
5+
def setup_method(self):
6+
self.utils = TextUtils()
7+
8+
def test_get_tokens(self):
9+
text = "ogs artist 123"
10+
tokens = self.utils.get_tokens(text)
11+
assert tokens == ["ogs", "artist", "123"]
12+
13+
def test_get_tokens_quoted(self):
14+
text = 'ogs search "massive attack"'
15+
tokens = self.utils.get_tokens(text)
16+
assert tokens == ["ogs", "search", "massive attack"]
17+
18+
def test_last_token(self):
19+
text = "ogs artist"
20+
assert self.utils._last_token(text) == "artist"
21+
22+
def test_safe_split_valid(self):
23+
text = "hello world"
24+
assert self.utils._safe_split(text) == ["hello", "world"]
25+
26+
def test_safe_split_invalid_quote(self):
27+
# shlex raises ValueError on unclosed quotes
28+
text = 'hello "world'
29+
# The updated code catches ValueError and returns the original text
30+
assert self.utils._safe_split(text) == text

tests/test_version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from discogs_cli import __version__
2+
3+
4+
def test_version():
5+
assert __version__ is not None

0 commit comments

Comments
 (0)