Skip to content

Commit

Permalink
OD-1730: Switch to using ruff for formatting
Browse files Browse the repository at this point in the history
git diff -w is highly recommended for this patch; the only substantive
change is in the .github directory, adding the CI check for formatting
correctness.  The rest is the initial restyling.
  • Loading branch information
hlieberman committed Nov 1, 2023
1 parent 8e5c623 commit 8c81f0a
Show file tree
Hide file tree
Showing 28 changed files with 1,876 additions and 1,310 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/python-app-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
- name: Lint with ruff
run: |
ruff check .
- name: Check formatting with ruff
run: |
ruff format --check .
- name: Test with pytest
run: |
pytest
3 changes: 3 additions & 0 deletions .github/workflows/python-app-macos-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Lint with ruff
run: |
ruff check .
- name: Check formatting with ruff
run: |
ruff format --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"
19 changes: 11 additions & 8 deletions 01-Load-Automated-Archive-into-Mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from automated_archive import aa

if __name__ == "__main__":
args_obj = Args()
args = args_obj.args_for_01()
log = args_obj.logger_with_filename()
sql = Sql(args, log)

# eg: python 01-Load-Automated-Archive-into-Mysql.py -dh localhost -du root -dt dsa -dd temp_python -a AA -f /path/to/ARCHIVE_DB.pl -o .
log.info('Loading Automated Archive file "{0}" into database "{1}"'.format(args.db_input_file, args.temp_db_database))
aa.clean_and_load_data(args, log)
args_obj = Args()
args = args_obj.args_for_01()
log = args_obj.logger_with_filename()
sql = Sql(args, log)

# eg: python 01-Load-Automated-Archive-into-Mysql.py -dh localhost -du root -dt dsa -dd temp_python -a AA -f /path/to/ARCHIVE_DB.pl -o .
log.info(
'Loading Automated Archive file "{0}" into database "{1}"'.format(
args.db_input_file, args.temp_db_database
)
)
aa.clean_and_load_data(args, log)
25 changes: 12 additions & 13 deletions 02a-Load-Chapters-to-Working-Table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@

# Given an existing final chapter table, this will use the URL field and chapter location to load the chapter contents
def __current_table(table_name, db):
query = "SELECT * FROM `{0}`.`{1}`".format(args.output_database, table_name)
dict_cursor = db.cursor(cursors.DictCursor)
dict_cursor.execute(query)
return dict_cursor.fetchall()
query = "SELECT * FROM `{0}`.`{1}`".format(args.output_database, table_name)
dict_cursor = db.cursor(cursors.DictCursor)
dict_cursor.execute(query)
return dict_cursor.fetchall()


if __name__ == "__main__":
# TODO the eFiction process now loads chapters into MySQL before further processing in ODAP, all others should too
args_obj = Args()
args = args_obj.args_for_07()
log = args_obj.logger_with_filename()
sql = Sql(args, log)
chaps = Chapters(args, sql, log)
# TODO the eFiction process now loads chapters into MySQL before further processing in ODAP, all others should too
args_obj = Args()
args = args_obj.args_for_07()
log = args_obj.logger_with_filename()
sql = Sql(args, log)
chaps = Chapters(args, sql, log)


log.info("Loading chapters from {0}...".format(args.chapters_path))
chaps.populate_chapters()
log.info("Loading chapters from {0}...".format(args.chapters_path))
chaps.populate_chapters()
92 changes: 57 additions & 35 deletions 02b-Extract-Tags-From-Stories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,65 @@


if __name__ == "__main__":
"""
"""
Only for non-eFiction archives.
This script creates a table called tags in the temporary database and denormalises all the tags for each story.
This table is the basis for the Tag Wrangling sheet and is used to map the tags back to the story when the final
tables are created.
"""
args_obj = Args()
args = args_obj.args_for_02()
log = args_obj.logger_with_filename()
sql = Sql(args, log)
tags = Tags(args, sql, log)
log.info('Processing tags from stories and bookmarks table in {0}'.format(args.temp_db_database))
tags.create_tags_table()

tag_col_list = {}
stories_id_name = ""
stories_table_name = ""

# AUTOMATED ARCHIVE
if args.archive_type == 'AA':

story_table_name = input('Story table name (default: "stories"): ')
if story_table_name is None or story_table_name == '':
story_table_name = 'stories'

bookmark_table_name = input('Bookmark table name (default: "story_links"): ')
if bookmark_table_name is None or bookmark_table_name == '':
bookmark_table_name = 'story_links'

tag_columns = input('Column names containing tags \n (delimited by commas - default: "rating, tags, warnings, characters, fandoms, relationships"): ')
if tag_columns is None or tag_columns == '':
tag_columns = "rating, tags, warnings, characters, fandoms, relationships"
# fancy footwork to ensure compatibility with eFiction
tag_col_list = re.split(r", ?", tag_columns)
tag_columns_dict = dict(zip(tag_col_list, tag_col_list))
fields_with_fandom = args.fields_with_fandom.split(", ") if args.fields_with_fandom is not None else []
tags.populate_tag_table(args.temp_db_database, "id", story_table_name, tag_columns_dict, fields_with_fandom)
tags.populate_tag_table(args.temp_db_database, "id", bookmark_table_name, tag_columns_dict, fields_with_fandom, False)

log.info("Done extracting tags.")
args_obj = Args()
args = args_obj.args_for_02()
log = args_obj.logger_with_filename()
sql = Sql(args, log)
tags = Tags(args, sql, log)
log.info(
"Processing tags from stories and bookmarks table in {0}".format(
args.temp_db_database
)
)
tags.create_tags_table()

tag_col_list = {}
stories_id_name = ""
stories_table_name = ""

# AUTOMATED ARCHIVE
if args.archive_type == "AA":
story_table_name = input('Story table name (default: "stories"): ')
if story_table_name is None or story_table_name == "":
story_table_name = "stories"

bookmark_table_name = input('Bookmark table name (default: "story_links"): ')
if bookmark_table_name is None or bookmark_table_name == "":
bookmark_table_name = "story_links"

tag_columns = input(
'Column names containing tags \n (delimited by commas - default: "rating, tags, warnings, characters, fandoms, relationships"): '
)
if tag_columns is None or tag_columns == "":
tag_columns = "rating, tags, warnings, characters, fandoms, relationships"
# fancy footwork to ensure compatibility with eFiction
tag_col_list = re.split(r", ?", tag_columns)
tag_columns_dict = dict(zip(tag_col_list, tag_col_list))
fields_with_fandom = (
args.fields_with_fandom.split(", ")
if args.fields_with_fandom is not None
else []
)
tags.populate_tag_table(
args.temp_db_database,
"id",
story_table_name,
tag_columns_dict,
fields_with_fandom,
)
tags.populate_tag_table(
args.temp_db_database,
"id",
bookmark_table_name,
tag_columns_dict,
fields_with_fandom,
False,
)

log.info("Done extracting tags.")
Loading

0 comments on commit 8c81f0a

Please sign in to comment.