-
Notifications
You must be signed in to change notification settings - Fork 19
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 #79 from ishefi/add-pre-commit-hooks
Add pre commit hooks
- Loading branch information
Showing
33 changed files
with
1,009 additions
and
492 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,24 @@ | ||
name: Hooks | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
pre-commit-hooks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
- uses: snok/install-poetry@v1 | ||
with: | ||
virtualenvs-create: false | ||
- name: Install Dependancies | ||
run: | | ||
poetry install --no-root --no-interaction | ||
- uses: pre-commit/[email protected] | ||
|
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,18 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: ruff | ||
name: ruff | ||
entry: ruff --fix | ||
language: system | ||
types: [python] | ||
- id: ruff-format | ||
name: ruff format | ||
entry: ruff format | ||
language: system | ||
types: [python] | ||
- id: mypy | ||
name: MyPy | ||
entry: mypy | ||
language: system | ||
types: [python] |
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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from omegaconf import OmegaConf | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from omegaconf import OmegaConf | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
thismodule = sys.modules[__name__] | ||
|
||
conf = OmegaConf.create() | ||
if (config_path := Path(__file__).parent.parent.resolve() / 'config.yaml').exists(): | ||
if (config_path := Path(__file__).parent.parent.resolve() / "config.yaml").exists(): | ||
conf.merge_with(OmegaConf.load(config_path)) | ||
if yaml_str := os.environ.get('YAML_CONFIG_STR'): | ||
if yaml_str := os.environ.get("YAML_CONFIG_STR"): | ||
conf.merge_with(OmegaConf.create(yaml_str)) | ||
for k, v in conf.items(): | ||
setattr(thismodule, k, v) | ||
|
||
|
||
def __getattr__(name: str) -> Any: | ||
if name in conf: | ||
return conf[name] | ||
raise AttributeError(f"module {__name__} has no attribute {name}") |
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,4 +1,4 @@ | ||
from datetime import datetime | ||
|
||
VEC_SIZE = '100f' | ||
FIRST_DATE = datetime(2022, 2, 21).date() | ||
VEC_SIZE = "100f" | ||
FIRST_DATE = datetime(2022, 2, 21).date() |
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 |
---|---|---|
@@ -1,21 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import gensim.models.keyedvectors as word2vec | ||
from motor.motor_asyncio import AsyncIOMotorClient as MongoClient | ||
from redis.asyncio import Redis | ||
from common.logger import logger | ||
|
||
from common import config | ||
from model import GensimModel | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
import motor.core | ||
|
||
|
||
def get_mongo(): | ||
def get_mongo() -> motor.core.AgnosticDatabase[Any]: | ||
return MongoClient(config.mongo).Semantle | ||
|
||
|
||
def get_redis(): | ||
def get_redis() -> Redis[Any]: | ||
return Redis.from_url(config.redis, decode_responses=True, max_connections=10) | ||
|
||
|
||
def get_model(mongo=None, has_model=False): | ||
if has_model is not None: | ||
logger.info("using model") | ||
import gensim.models.keyedvectors as word2vec | ||
return GensimModel(word2vec.KeyedVectors.load("model.mdl").wv) | ||
raise Exception('couldnt find model') | ||
def get_model() -> GensimModel: | ||
return GensimModel(word2vec.KeyedVectors.load("model.mdl").wv) |
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 @@ | ||
import numpy.typing | ||
|
||
np_float_arr = numpy.typing.NDArray[numpy.float32] |
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,9 +1,11 @@ | ||
import gdown | ||
import shutil | ||
|
||
import gdown | ||
|
||
from common.config import conf | ||
|
||
if __name__ == "__main__": | ||
url = f'https://drive.google.com/uc?id={conf.model_zip_id}' | ||
url = f"https://drive.google.com/uc?id={conf.model_zip_id}" | ||
destination = "model.zip" | ||
gdown.download(url, destination, quiet=False) | ||
shutil.unpack_archive("model.zip") |
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
Oops, something went wrong.