Skip to content

Commit 38a65c4

Browse files
authored
Merge pull request #60 from python-parsy/github-actions-linters
Fixes to workflows to use black, cleanups
2 parents d44ee36 + 83d503e commit 38a65c4

15 files changed

+98
-147
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
env_vars: PYTHON
4646
fail_ci_if_error: true
4747

48-
isort:
48+
linters:
4949
runs-on: ubuntu-latest
5050

5151
steps:
@@ -57,55 +57,24 @@ jobs:
5757
- uses: actions/cache@v2
5858
with:
5959
path: ~/.cache/pip
60-
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements-isort.txt') }}
60+
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements-linters.txt') }}
6161
- name: Install deps
6262
run: |
6363
python -m pip install --upgrade pip
64-
pip install -r tests/requirements-isort.txt
64+
pip install -r tests/requirements-linters.txt
6565
- name: Run isort
6666
run: |
6767
isort --version
6868
isort -c .
69-
70-
flake8:
71-
runs-on: ubuntu-latest
72-
73-
steps:
74-
- uses: actions/checkout@v2
75-
- name: Set up Python
76-
uses: actions/setup-python@v2
77-
with:
78-
python-version: "3.9"
79-
- uses: actions/cache@v2
80-
with:
81-
path: ~/.cache/pip
82-
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements-flake8.txt') }}
83-
- name: Install deps
84-
run: |
85-
python -m pip install --upgrade pip
86-
pip install -r tests/requirements-flake8.txt
8769
- name: Run flake8
70+
if: failure() || success()
8871
run: |
8972
flake8 --version
90-
flake8
91-
92-
check-manifest:
93-
runs-on: ubuntu-latest
94-
95-
steps:
96-
- uses: actions/checkout@v2
97-
- name: Set up Python
98-
uses: actions/setup-python@v2
99-
with:
100-
python-version: "3.9"
101-
- uses: actions/cache@v2
102-
with:
103-
path: ~/.cache/pip
104-
key: ${{ runner.os }}-pip-${{ hashFiles('test/requirements-check-manifest.txt') }}
105-
- name: Install deps
106-
run: |
107-
python -m pip install --upgrade pip
108-
pip install -r tests/requirements-check-manifest.txt
10973
- name: Run check-manifest
74+
if: failure() || success()
11075
run: |
11176
check-manifest
77+
- uses: psf/black@stable
78+
with:
79+
version: "22.3.0"
80+
if: failure() || success()

.pre-commit-config.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ repos:
1414
hooks:
1515
- id: isort
1616
language_version: python3.9
17-
- repo: https://github.com/rtts/djhtml
18-
rev: v1.4.9
19-
hooks:
20-
- id: djhtml
21-
entry: djhtml -t 2 -i
22-
language_version: python3.9
2317
- repo: https://github.com/ikamensh/flynt/
2418
rev: '0.69'
2519
hooks:
@@ -43,7 +37,7 @@ repos:
4337
- id: autopep8
4438
language_version: python3.9
4539
- repo: https://github.com/psf/black
46-
rev: 21.8b0
40+
rev: 22.3.0
4741
hooks:
4842
- id: black
4943
language_version: python3

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
if sys.version_info < (3, 7):
66
# Python 3.6 and below don't have `dataclasses`
7-
collect_ignore = ['examples/sql_select.py']
7+
collect_ignore = ["examples/sql_select.py"]

docs/conf.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# parsy documentation build configuration file, created by
54
# sphinx-quickstart on Mon Sep 25 22:24:17 2017.
@@ -33,33 +32,33 @@
3332
# Add any Sphinx extension module names here, as strings. They can be
3433
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3534
# ones.
36-
extensions = ['sphinx.ext.viewcode']
35+
extensions = ["sphinx.ext.viewcode"]
3736

3837
# Add any paths that contain templates here, relative to this directory.
39-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
4039

4140
# The suffix(es) of source filenames.
4241
# You can specify multiple suffix as a list of string:
4342
#
4443
# source_suffix = ['.rst', '.md']
45-
source_suffix = '.rst'
44+
source_suffix = ".rst"
4645

4746
# The master toctree document.
48-
master_doc = 'index'
47+
master_doc = "index"
4948

5049
# General information about the project.
51-
project = 'parsy'
52-
copyright = '2017, Jeanine Adkisson, Luke Plant'
53-
author = 'Jeanine Adkisson'
50+
project = "parsy"
51+
copyright = "2017, Jeanine Adkisson, Luke Plant"
52+
author = "Jeanine Adkisson"
5453

5554
# The version info for the project you're documenting, acts as replacement for
5655
# |version| and |release|, also used in various other places throughout the
5756
# built documents.
5857
#
5958
# The short X.Y version.
60-
version = '2.0'
59+
version = "2.0"
6160
# The full version, including alpha/beta/rc tags.
62-
release = '2.0-dev'
61+
release = "2.0-dev"
6362

6463
# The language for content autogenerated by Sphinx. Refer to documentation
6564
# for a list of supported languages.
@@ -71,10 +70,10 @@
7170
# List of patterns, relative to source directory, that match files and
7271
# directories to ignore when looking for source files.
7372
# This patterns also effect to html_static_path and html_extra_path
74-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7574

7675
# The name of the Pygments (syntax highlighting) style to use.
77-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7877

7978
# If true, `todo` and `todoList` produce output, else they produce nothing.
8079
todo_include_todos = False
@@ -85,7 +84,7 @@
8584
# The theme to use for HTML and HTML Help pages. See the documentation for
8685
# a list of builtin themes.
8786
#
88-
html_theme = 'default'
87+
html_theme = "default"
8988

9089
# Theme options are theme-specific and customize the look and feel of a theme
9190
# further. For a list of options available for each theme, see the
@@ -96,13 +95,13 @@
9695
# Add any paths that contain custom static files (such as style sheets) here,
9796
# relative to this directory. They are copied after the builtin static files,
9897
# so a file named "default.css" will overwrite the builtin "default.css".
99-
html_static_path = ['_static']
98+
html_static_path = ["_static"]
10099

101100

102101
# -- Options for HTMLHelp output ------------------------------------------
103102

104103
# Output file base name for HTML help builder.
105-
htmlhelp_basename = 'parsydoc'
104+
htmlhelp_basename = "parsydoc"
106105

107106

108107
# -- Options for LaTeX output ---------------------------------------------
@@ -111,15 +110,12 @@
111110
# The paper size ('letterpaper' or 'a4paper').
112111
#
113112
# 'papersize': 'letterpaper',
114-
115113
# The font size ('10pt', '11pt' or '12pt').
116114
#
117115
# 'pointsize': '10pt',
118-
119116
# Additional stuff for the LaTeX preamble.
120117
#
121118
# 'preamble': '',
122-
123119
# Latex figure (float) alignment
124120
#
125121
# 'figure_align': 'htbp',
@@ -129,19 +125,15 @@
129125
# (source start file, target name, title,
130126
# author, documentclass [howto, manual, or own class]).
131127
latex_documents = [
132-
(master_doc, 'parsy.tex', 'parsy Documentation',
133-
'Jeanine Adkisson', 'manual'),
128+
(master_doc, "parsy.tex", "parsy Documentation", "Jeanine Adkisson", "manual"),
134129
]
135130

136131

137132
# -- Options for manual page output ---------------------------------------
138133

139134
# One entry per manual page. List of tuples
140135
# (source start file, name, description, authors, manual section).
141-
man_pages = [
142-
(master_doc, 'parsy', 'parsy Documentation',
143-
[author], 1)
144-
]
136+
man_pages = [(master_doc, "parsy", "parsy Documentation", [author], 1)]
145137

146138

147139
# -- Options for Texinfo output -------------------------------------------
@@ -150,7 +142,5 @@
150142
# (source start file, target name, title, author,
151143
# dir menu entry, description, category)
152144
texinfo_documents = [
153-
(master_doc, 'parsy', 'parsy Documentation',
154-
author, 'parsy', 'One line description of project.',
155-
'Miscellaneous'),
145+
(master_doc, "parsy", "parsy Documentation", author, "parsy", "One line description of project.", "Miscellaneous"),
156146
]

examples/json.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343

4444

4545
def test():
46-
assert json_doc.parse(
47-
r"""
46+
assert (
47+
json_doc.parse(
48+
r"""
4849
{
4950
"int": 1,
5051
"string": "hello",
@@ -53,13 +54,15 @@ def test():
5354
"nested": {"x": "y"}
5455
}
5556
"""
56-
) == {
57-
"int": 1,
58-
"string": "hello",
59-
"a list": [1, 2, 3],
60-
"escapes": "\n",
61-
"nested": {"x": "y"},
62-
}
57+
)
58+
== {
59+
"int": 1,
60+
"string": "hello",
61+
"a list": [1, 2, 3],
62+
"escapes": "\n",
63+
"nested": {"x": "y"},
64+
}
65+
)
6366

6467

6568
if __name__ == "__main__":

examples/simple_eval.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,54 @@
22

33

44
def lexer(code):
5-
whitespace = regex(r'\s*')
5+
whitespace = regex(r"\s*")
66
integer = digit.at_least(1).concat().map(int)
7-
float_ = (
8-
digit.many() + string('.').result(['.']) + digit.many()
9-
).concat().map(float)
10-
parser = whitespace >> ((
11-
float_ | integer | regex(r'[()*/+-]')
12-
) << whitespace).many()
7+
float_ = (digit.many() + string(".").result(["."]) + digit.many()).concat().map(float)
8+
parser = whitespace >> ((float_ | integer | regex(r"[()*/+-]")) << whitespace).many()
139
return parser.parse(code)
1410

1511

1612
def eval_tokens(tokens):
1713
# This function parses and evaluates at the same time.
1814

19-
lparen = match_item('(')
20-
rparen = match_item(')')
15+
lparen = match_item("(")
16+
rparen = match_item(")")
2117

2218
@generate
2319
def additive():
2420
res = yield multiplicative
25-
sign = match_item('+') | match_item('-')
21+
sign = match_item("+") | match_item("-")
2622
while True:
27-
operation = yield sign | success('')
23+
operation = yield sign | success("")
2824
if not operation:
2925
break
3026
operand = yield multiplicative
31-
if operation == '+':
27+
if operation == "+":
3228
res += operand
33-
elif operation == '-':
29+
elif operation == "-":
3430
res -= operand
3531
return res
3632

3733
@generate
3834
def multiplicative():
3935
res = yield simple
40-
op = match_item('*') | match_item('/')
36+
op = match_item("*") | match_item("/")
4137
while True:
42-
operation = yield op | success('')
38+
operation = yield op | success("")
4339
if not operation:
4440
break
4541
operand = yield simple
46-
if operation == '*':
42+
if operation == "*":
4743
res *= operand
48-
elif operation == '/':
44+
elif operation == "/":
4945
res /= operand
5046
return res
5147

5248
@generate
5349
def number():
54-
sign = yield match_item('+') | match_item('-') | success('+')
55-
value = yield test_item(
56-
lambda x: isinstance(x, (int, float)), 'number')
57-
return value if sign == '+' else -value
50+
sign = yield match_item("+") | match_item("-") | success("+")
51+
value = yield test_item(lambda x: isinstance(x, (int, float)), "number")
52+
return value if sign == "+" else -value
5853

5954
expr = additive
6055
simple = (lparen >> expr << rparen) | number
@@ -67,8 +62,9 @@ def simple_eval(expr):
6762

6863

6964
import pytest # noqa isort:skip
65+
7066
test_item = pytest.mark.skip(test_item) # This is not a test
7167

7268

73-
if __name__ == '__main__':
69+
if __name__ == "__main__":
7470
print(simple_eval(input()))

examples/simple_logo_lexer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
from parsy import eof, regex, seq, string, string_from, whitespace
1212

1313
command = string_from("fd", "bk", "rt", "lt")
14-
number = regex(r'[0-9]+').map(int)
15-
optional_whitespace = regex(r'\s*')
14+
number = regex(r"[0-9]+").map(int)
15+
optional_whitespace = regex(r"\s*")
1616
eol = string("\n")
17-
line = seq(optional_whitespace >> command,
18-
whitespace >> number,
19-
(eof | eol | (whitespace >> eol)).result("\n"))
17+
line = seq(
18+
optional_whitespace >> command,
19+
whitespace >> number,
20+
(eof | eol | (whitespace >> eol)).result("\n"),
21+
)
2022
flatten_list = lambda ls: sum(ls, [])
2123
lexer = line.many().map(flatten_list)

0 commit comments

Comments
 (0)