-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from marchdf/update
Major rework
- Loading branch information
Showing
13 changed files
with
203 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
max-complexity = 10 | ||
select = C,E,F,W,B,B950,N,D | ||
ignore = E203,E302,E501,W503,C901,FS003 | ||
docstring-convention = numpy | ||
exclude = | ||
.git, | ||
__pycache__, | ||
*.egg-info, | ||
.nox, | ||
.pytest_cache, | ||
.mypy_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: book-list-CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
concurrency: | ||
group: ${{github.ref}}-${{github.head_ref}}-ci | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
CI: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ['3.11'] | ||
poetry-version: ['1.7'] | ||
defaults: | ||
run: | ||
working-directory: ${{github.workspace}} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{matrix.python-version}} | ||
- name: Run image | ||
uses: abatilo/[email protected] | ||
with: | ||
poetry-version: ${{matrix.poetry-version}} | ||
- name: Install Dependencies using Poetry | ||
run: poetry install | ||
- name: Formatting with black | ||
run: poetry run black --check . | ||
- name: Sort imports with isort | ||
run: poetry run isort --check-only --diff . | ||
- name: Lint with flake8 | ||
run: poetry run flake8 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
old | ||
.DS_Store | ||
__pycache__ | ||
poetry.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""book-list.""" | ||
|
||
__version__ = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Executable for book-list package.""" | ||
|
||
import book_list.alphabetize as al | ||
|
||
if __name__ == "__main__": | ||
al.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Alphabetize a list of books. | ||
A simple script to parse lists of books and alphabetize based on the | ||
author last name. | ||
""" | ||
|
||
import os | ||
import time | ||
from datetime import timedelta | ||
|
||
import pandas as pd | ||
|
||
|
||
def main(): | ||
"""Alphabetize a list of books.""" | ||
start = time.time() | ||
|
||
# Setup | ||
tmpfile = "tmp.md" | ||
basedir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
ifile = f"{basedir}/data/read_books.md" | ||
ofile = f"{basedir}/data/read_books_alpha.md" | ||
|
||
# Parse the list of books | ||
df = pd.read_csv( | ||
ifile, | ||
sep="|", | ||
skiprows=3, # skip markdown header | ||
header=None, | ||
usecols=[0, 1, 2, 3, 4], # dont take extra columns | ||
names=["name", "title", "status", "date", "own"], | ||
) | ||
|
||
# Get the first and last names | ||
names = df["name"].str.split() | ||
df["first_name"] = [" ".join(n[:-1]) for n in names] | ||
df["last_name"] = [n[-1] for n in names] | ||
|
||
# sort based on last name | ||
df = df.sort_values( | ||
by=["last_name", "first_name", "title", "date", "status", "own"] | ||
) | ||
|
||
# Save to file | ||
df.to_csv( | ||
tmpfile, | ||
sep="|", | ||
index=False, | ||
columns=["name", "title", "status", "date", "own"], | ||
header=False, | ||
) | ||
|
||
# Add header lines from original table | ||
with open(ifile) as f: | ||
h1 = f.readline() | ||
h2 = f.readline() | ||
h3 = f.readline() | ||
|
||
ftmp = open(tmpfile, "r") | ||
with open(tmpfile, "r") as ftmp, open(ofile, "w") as of: | ||
of.write(h1.rstrip() + " (alphabetized)\n") | ||
of.write(h2) | ||
of.write(h3) | ||
for line in ftmp.readlines(): | ||
of.write(line) | ||
|
||
# Remove temporary file | ||
os.remove(tmpfile) | ||
|
||
# output timer | ||
end = time.time() - start | ||
print(f"Elapsed time {timedelta(seconds=end)} (or {end:f} seconds)") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
[tool.poetry] | ||
name = "book-list" | ||
version = "0.1.0" | ||
description = "Lists of read books and recommendations" | ||
authors = ["Marc Henry de Frahan <[email protected]>"] | ||
license = "GPL-3.0" | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
pandas = "^2.1.3" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
isort = "^5.12.0" | ||
black = "^23.11.0" | ||
flake8 = "^6.1.0" | ||
flake8-bugbear = "^23.12.2" | ||
pep8-naming = "^0.13.3" | ||
flake8-docstrings = "^1.7.0" | ||
flake8-use-fstring = "^1.4" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.poetry.scripts] | ||
alphabetize = "book_list.alphabetize:main" | ||
|
||
[tool.black] | ||
line-length = 88 | ||
target-version = ['py310'] | ||
preview = true | ||
include = '\.pyi?$' | ||
exclude = ''' | ||
( | ||
/( | ||
\.eggs # exclude a few common directories in the | ||
| \.git # root of the project | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
)/ | ||
) | ||
''' | ||
|
||
[tool.isort] | ||
profile = "black" | ||
multi_line_output = 3 | ||
include_trailing_comma = true | ||
force_grid_wrap = 0 | ||
use_parentheses = true | ||
line_length = 88 |
This file was deleted.
Oops, something went wrong.