Commit 21181cdd authored by Markus Shepherd's avatar Markus Shepherd 🙈
Browse files

Merge branch 'pre-commit' into 'master'

Add pre-commit hooks

Closes #76

See merge request !52
parents 389b26a4 c3deea5d
# the following line will be updated automatically from board_game_scraper.__version__
LIBRARY_VERSION=
# environment variables
LOG_LEVEL=DEBUG
LOG_SCRAPED_ITEMS=0
......
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: local
hooks:
- id: version-env
name: Writing version to .env
description: Reading library __version__ and saving it to .env
entry: pipenv run python -m board_game_scraper.version_env
language: system
always_run: true
pass_filenames: false
......@@ -30,6 +30,7 @@ twisted = "*"
black = "==20.8b1"
docker = "*"
mypy = "*"
pre-commit = "*"
psutil = "*"
pylint = "*"
pytimeparse = "*"
......
This diff is collapsed.
theme: jekyll-theme-merlot
\ No newline at end of file
theme: jekyll-theme-merlot
# -*- coding: utf-8 -*-
"""Read library __version__ and write to .env."""
import argparse
import logging
import sys
from pathlib import Path
from shutil import copyfileobj
from tempfile import TemporaryFile
from .__version__ import __version__
LOGGER = logging.getLogger(__name__)
def _parse_args():
parser = argparse.ArgumentParser(
description="Read library __version__ and write to .env."
)
parser.add_argument(
"--target",
"-t",
default=".env",
help="target file",
)
parser.add_argument(
"--variable",
"-V",
default="LIBRARY_VERSION",
help="variable name",
)
parser.add_argument(
"--verbose",
"-v",
action="count",
default=0,
help="log level (repeat for more verbosity)",
)
return parser.parse_args()
def main():
"""Read library __version__ and write to .env."""
args = _parse_args()
logging.basicConfig(
stream=sys.stderr,
level=logging.DEBUG if args.verbose > 0 else logging.INFO,
format="%(asctime)s %(levelname)-8.8s [%(name)s:%(lineno)s] %(message)s",
)
LOGGER.info(args)
target = Path(args.target).resolve()
LOGGER.info("Trying to write version %s to file <%s>...", __version__, target)
if not target.exists():
LOGGER.error("Target file <%s> does not exist, aborting", target)
sys.exit(1)
LOGGER.info("Looking for environment variable <%s>", args.variable)
with TemporaryFile("w+") as temp:
with target.open() as in_file:
for line in in_file:
if line.startswith(f"{args.variable}="):
temp.write(f"{args.variable}={__version__}\n")
else:
temp.write(line)
temp.seek(0)
with target.open("w") as out_file:
copyfileobj(temp, out_file)
LOGGER.info("Done.")
if __name__ == "__main__":
main()
version: '3.7'
version: '3.8'
services:
bga:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-bga
build: '.'
command: ['python', '-m', 'board_game_scraper', 'bga']
......@@ -17,7 +17,7 @@ services:
stop_signal: SIGINT
bgg:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-bgg
build: '.'
command: ['python', '-m', 'board_game_scraper', 'bgg']
......@@ -34,7 +34,7 @@ services:
stop_signal: SIGINT
bgg-hotness:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-bgg-hotness
build: '.'
command: ['python', '-m', 'board_game_scraper', 'bgg_hotness']
......@@ -49,7 +49,7 @@ services:
stop_signal: SIGINT
bgg-rankings:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-bgg-rankings
build: '.'
command: ['python', '-m', 'board_game_scraper', 'bgg_rankings']
......@@ -64,7 +64,7 @@ services:
stop_signal: SIGINT
bgg-geeklist:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-bgg-geeklist
build: '.'
command: ['python', '-m', 'board_game_scraper', 'bgg_geeklist', '--feeds-subdir', 'bgg_rankings']
......@@ -80,7 +80,7 @@ services:
stop_signal: SIGINT
dbpedia:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-dbpedia
build: '.'
command: ['python', '-m', 'board_game_scraper', 'dbpedia']
......@@ -95,7 +95,7 @@ services:
stop_signal: SIGINT
luding:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-luding
build: '.'
command: ['python', '-m', 'board_game_scraper', 'luding']
......@@ -110,7 +110,7 @@ services:
stop_signal: SIGINT
spielen:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-spielen
build: '.'
command: ['python', '-m', 'board_game_scraper', 'spielen']
......@@ -125,7 +125,7 @@ services:
stop_signal: SIGINT
wikidata:
image: bg-scraper:latest
image: registry.gitlab.com/recommend.games/board-game-scraper:${LIBRARY_VERSION}
container_name: bg-scraper-wikidata
build: '.'
command: ['python', '-m', 'board_game_scraper', 'wikidata']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment