From 7a701662c17467a9eb3402cf8641a7dd15f5ad1c Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:13:55 -0700 Subject: make fmt --- fuzzycat/utils.py | 2 ++ tests/test_utils.py | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fuzzycat/utils.py b/fuzzycat/utils.py index bd7ceed..8e1ffb0 100644 --- a/fuzzycat/utils.py +++ b/fuzzycat/utils.py @@ -19,6 +19,7 @@ CHEM_FORMULA = re.compile(r"([A-Z]{1,2}[0-9]{1,2})+") ParsedPages = collections.namedtuple("ParsedPages", "start end count") + def es_compat_hits_total(resp): """ Given a search response dict, support ES6 and ES7 style total value. See: @@ -32,6 +33,7 @@ def es_compat_hits_total(resp): except TypeError: return resp["hits"]["total"] + def parse_page_string(s): """ Parse typical page strings, e.g. 150-180. diff --git a/tests/test_utils.py b/tests/test_utils.py index 24be9d1..381c44e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -99,11 +99,22 @@ def test_zstdlines(): with open(fn) as f: assert [s.strip() for s in f.readlines()] == list(zstdlines(zfn)) + def test_es_compat_hits_total(): cases = ( - ({"hits": {"total": 6}}, 6), - ({"hits": {"total": {"value": 7, "relation": "eq"}}}, 7), + ({ + "hits": { + "total": 6 + } + }, 6), + ({ + "hits": { + "total": { + "value": 7, + "relation": "eq" + } + } + }, 7), ) for r, expected in cases: assert es_compat_hits_total(r) == expected - -- cgit v1.2.3 From b5cc554f37f2b695bb1ca1884fb56110d22ddf02 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:14:48 -0700 Subject: makefile: change 'deps' to be simple --dev --deploy When I ran 'make deps' as-is, my pipenv mutated the Pipfile and started re-locking. This project isn't using 'black' any more, so don't need the --pre flag. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5a684f9..bd57d45 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,7 @@ help: ## Print info about all commands .PHONY: deps deps: ## Install dependencies from setup.py into pipenv - # We need to use --pre, because e.g. black is considered a pre-release - # version, https://github.com/microsoft/vscode-python/issues/5171 - pipenv install --pre '-e .[dev]' + pipenv install --dev --deploy .PHONY: fmt fmt: ## Apply import sorting and yapf source formatting on all files -- cgit v1.2.3 From 8fced92526fde1d13c2417d01d224de45582443b Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:15:53 -0700 Subject: makefile: run common commands inside pipenv --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index bd57d45..a6159f4 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,9 @@ deps: ## Install dependencies from setup.py into pipenv .PHONY: fmt fmt: ## Apply import sorting and yapf source formatting on all files - isort --atomic fuzzycat/* - yapf -p -i -r fuzzycat/* - yapf -p -i -r tests + pipenv run isort --atomic fuzzycat/* + pipenv run yapf -p -i -r fuzzycat/* + pipenv run yapf -p -i -r tests .PHONY: dist dist: ## Create source distribution and wheel @@ -32,19 +32,19 @@ xar: ## Create a XAR standalone package (https://github.com/facebookincubator/xa .PHONY: cov cov: ## Run coverage report - pytest --cov=fuzzycat fuzzycat/*.py tests/ # --cov-report annotate:cov_annotate --cov-report html + pipenv run pytest --cov=fuzzycat fuzzycat/*.py tests/ # --cov-report annotate:cov_annotate --cov-report html .PHONY: test test: ## Run coverage report - pytest -o log_cli=true -s -vvv fuzzycat/*.py tests/*.py + pipenv run pytest -o log_cli=true -s -vvv fuzzycat/*.py tests/*.py .PHONY: lint lint: $(PY_FILES) ## Run pylint - pylint fuzzycat + pipenv run pylint fuzzycat .PHONY: mypy mypy: ## Run mypy checks - mypy --strict $$(find fuzzycat -name "*py") + pipenv run mypy --strict $$(find fuzzycat -name "*py") .PHONY: clean clean: ## Clean all artifacts -- cgit v1.2.3 From 710ed6a0378e9d21b916d7a832d30c89156bffb0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:30:21 -0700 Subject: gitlab CI: try 'make deps' and 'make test' --- .gitlab-ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d838ef2..60b11b4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,12 +7,10 @@ stages: before_script: - pip3 install --upgrade pip - - pip3 install pytest tests: stage: test script: - - python3 --version - - pipenv install - - pipenv run pytest -vv -s - + - python3 --version && pipenv --version + - make deps + - make test -- cgit v1.2.3 From 4949511ccaffdc270f1c6306e3df5d356e9edbe0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:36:06 -0700 Subject: upgrade to python3.8 --- Pipfile | 2 +- Pipfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Pipfile b/Pipfile index 4cc4c45..4f69c9e 100644 --- a/Pipfile +++ b/Pipfile @@ -32,4 +32,4 @@ regex = "*" zstandard = "*" [requires] -python_version = "3.7" +python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index c6a6acb..8fd364d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,11 +1,11 @@ { "_meta": { "hash": { - "sha256": "7ec5c05a87af980633df5c5f2a36b29ec2e0aa031b278d9c241dcb675447f35f" + "sha256": "e0423004017b8118e93adf9af4ffd96faa8572db2c03578153adf9b6af4c8c8c" }, "pipfile-spec": 6, "requires": { - "python_version": "3.7" + "python_version": "3.8" }, "sources": [ { -- cgit v1.2.3 From 79b6476827f80ed86019804b7293ff1a8fd4af9a Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:57:58 -0700 Subject: dynaconf: switch to fuzzycat.config import across project This is the recommended way to use dynaconf. --- fuzzycat/config.py | 4 ++++ fuzzycat/matching.py | 2 +- tests/test_matching.py | 3 +-- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 fuzzycat/config.py diff --git a/fuzzycat/config.py b/fuzzycat/config.py new file mode 100644 index 0000000..61050d1 --- /dev/null +++ b/fuzzycat/config.py @@ -0,0 +1,4 @@ + +from dynaconf import Dynaconf + +settings = Dynaconf(envvar_prefix="FUZZYCAT") diff --git a/fuzzycat/matching.py b/fuzzycat/matching.py index 9ccb62b..55a5833 100644 --- a/fuzzycat/matching.py +++ b/fuzzycat/matching.py @@ -13,8 +13,8 @@ from fatcat_openapi_client.rest import ApiException from fuzzycat.entities import entity_from_dict, entity_from_json from fuzzycat.utils import es_compat_hits_total +from fuzzycat.config import settings -settings = Dynaconf(envvar_prefix="FUZZYCAT") FATCAT_API_URL = settings.get("FATCAT_API_URL", "https://api.fatcat.wiki/v0") diff --git a/tests/test_matching.py b/tests/test_matching.py index 7d8b7af..56999e6 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -1,14 +1,13 @@ from fuzzycat.matching import anything_to_entity, match_release_fuzzy +from fuzzycat.config import settings from fatcat_openapi_client import ReleaseEntity import pytest import elasticsearch import logging -from dynaconf import Dynaconf logger = logging.getLogger('test_matching') logger.setLevel(logging.DEBUG) -settings = Dynaconf(envvar_prefix="FUZZYCAT") FATCAT_SEARCH_URL = settings.get("FATCAT_SEARCH_URL", "https://search.fatcat.wiki:443") -- cgit v1.2.3