Skip to content

Commit

Permalink
OD-1730: Switch to using ruff for linting.
Browse files Browse the repository at this point in the history
This also grandfathers in the current errors.
  • Loading branch information
hlieberman committed Nov 1, 2023
1 parent 3ac05af commit 8e5c623
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/python-app-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ jobs:
shell: bash
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
- name: Lint with ruff
run: |
# 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
ruff check .
- name: Test with pytest
run: |
pytest
9 changes: 3 additions & 6 deletions .github/workflows/python-app-macos-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ jobs:
shell: bash
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
- name: Lint with ruff
run: |
# 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
ruff check .
- name: Test with pytest - exclude MySQL integration tests
run: |
pytest --ignore "test/test_multitag_mapping.py" --ignore "test/test_percent_symbol.py" --ignore "test/test_tags_length.py" --ignore "test/test_step_05.py"
2 changes: 1 addition & 1 deletion 05-Create-Open-Doors-Tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def main(args, log):
bookmark_authors = final.original_table('item_authors',
f"WHERE item_id={bookmark['id']} and item_type='story_link'")
final_bookmarks.append(final.story_to_final_without_tags(bookmark, bookmark_authors, False))
if final_bookmarks: final.insert_into_final('story_links', final_bookmarks)
if final_bookmarks: final.insert_into_final('story_links', final_bookmarks) # noqa: E701

# AUTHORS
log.info("Copying authors to final table {0}.authors, cleaning emails and removing authors with no works...".format(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pyxdg==0.27
pyyaml==5.4
colorlog==4.2.1
prompt_toolkit==3.0.38
ruff==0.1.3
2 changes: 1 addition & 1 deletion shared_python/FinalTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _escape_unescape(self, item):
def _value(self, row):
value = []
for item in row:
if type(item) is str:
if type(item) is str: # noqa: E721
value.append('"' + self._escape_unescape(item) + '"')
elif type(item) is datetime.datetime:
value.append('"' + str(item) + '"')
Expand Down
2 changes: 1 addition & 1 deletion shared_python/Tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def populate_tag_table(self, database_name, story_id_col_name, table_name, tag_c
if story_tags_row[col] is not None:
for val in re.split(r", ?", story_tags_row[col]):
if val != '':
if type(tag_col_lookup[col]) is str: # Probably AA or a custom archive
if type(tag_col_lookup[col]) is str: # noqa: E721 # Probably AA or a custom archive
cleaned_tag = val.encode('utf-8').replace("'", "\'").strip()

values.append('({0}, "{1}", "{2}", "{3}")'
Expand Down
4 changes: 2 additions & 2 deletions xx-Remove-emails-from-Open-Doors-Tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def ask_user_for_action(match) -> str:
while True:
try:
return return_from_list(match)
except:
except: # noqa: E722
response = input(
f"\n{raw_email} ([W]hitelist, [B]lacklist) ([A]ddress, [D]omain) [C]ontext [R]ewrite domain >\n\t"
).lower()
Expand Down Expand Up @@ -130,7 +130,7 @@ def replace_func(email):
addresses[raw_email] = False
try:
return return_from_list(email)
except:
except: # noqa: E722
return ask_user_for_action(email)

cleared_text = email_regex.sub(replace_func, text)
Expand Down

0 comments on commit 8e5c623

Please sign in to comment.