Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use nimble-python #168

Merged
merged 17 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"_copy_without_render": [
"*.github"
],
"_template": "https://github.com/MartinBernstorff/swift-python-cookiecutter",
"_template": "https://github.com/MartinBernstorff/nimble-python-cookiecutter",
"author": "Martin Bernstorff",
"copyright_year": "2023",
"email": "martinbernstorfff@gmail.com",
"email": "martinbernstorff@gmail.com",
"friendly_name": "Personal Mnemonic Medium",
"github_repo": "personal-mnemonic-medium",
"github_user": "MartinBernstorff",
"license": "MIT",
"package_name": "personal_mnemonic_medium",
Expand Down
9 changes: 5 additions & 4 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"template": "https://github.com/MartinBernstorff/swift-python-cookiecutter",
"commit": "525b1f682621953d7ef9deb6ad6cf7359ebd43c8",
"template": "https://github.com/MartinBernstorff/nimble-python-cookiecutter",
"commit": "80b90f37d8ce87ffb1ab97cf2b518fc0fd431dfb",
"checkout": null,
"context": {
"cookiecutter": {
"project_name": "personal-mnemonic-medium",
"package_name": "personal_mnemonic_medium",
"friendly_name": "Personal Mnemonic Medium",
"author": "Martin Bernstorff",
"email": "martinbernstorfff@gmail.com",
"email": "martinbernstorff@gmail.com",
"github_user": "MartinBernstorff",
"github_repo": "personal-mnemonic-medium",
"version": "0.0.0",
"copyright_year": "2023",
"license": "MIT",
"_copy_without_render": [
"*.github"
],
"_template": "https://github.com/MartinBernstorff/swift-python-cookiecutter"
"_template": "https://github.com/MartinBernstorff/nimble-python-cookiecutter"
}
},
"directory": null
Expand Down
68 changes: 35 additions & 33 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"charliermarsh.ruff",
"ms-python.black-formatter",
"ms-azuretools.vscode-docker",
"ms-vscode.makefile-tools",
"github.vscode-github-actions"
]
}
},
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"postStartCommand": "pip install -e ."
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile",
"cacheFrom": "ghcr.io/martinbernstorff/personal-mnemonic-medium-devcontainer:latest"
},
// "features": {},
"customizations": {
"vscode": {
"extensions": [
"GitHub.copilot",
"charliermarsh.ruff",
"ms-python.python",
"ms-python.vscode-pylance",
"GitHub.vscode-pull-request-github",
"ms-vscode.makefile-tools",
"github.vscode-github-actions",
]
}
},
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"postStartCommand": "make install"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line to run commands after the container is created.
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
8 changes: 0 additions & 8 deletions .github/pull_request_template.md

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/dependabot_automerge.yml

This file was deleted.

25 changes: 14 additions & 11 deletions .github/workflows/validate.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# GitHub action to check if pre-commit has been run. Runs from .pre-commit-config.yaml, where the pre-commit actions are.

name: validate
# This workflow will install Python dependencies, run pytests and run notebooks
# then it will in python 3.9 (ubuntu-latest) create a badge with the coverage
# and add it to the PR. This badge will be updated if the PR is updated.

name: Tests
on:
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
build-and-test:
permissions: write-all
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
cancel-in-progress: true
Expand All @@ -22,14 +24,15 @@ jobs:
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
username: MartinBernstorff
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pre-build dev container image
uses: devcontainers/[email protected]
with:
imageName: ghcr.io/martinbernstorff/personal-mnemonic-medium
cacheFrom: ghcr.io/martinbernstorff/personal-mnemonic-medium
push: always
imageName: ghcr.io/martinbernstorff/personal-mnemonic-medium-devcontainer
# cacheFrom: ghcr.io/martinbernstorff/personal-mnemonic-medium-devcontainer:latest
push: filter
refFilterForPush: refs/heads/main
runCmd:
make validate
make validate
19 changes: 0 additions & 19 deletions .vscode/launch.json

This file was deleted.

17 changes: 12 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"python.analysis.typeCheckingMode": "strict",
"python.testing.pytestArgs": [
"tests"
"personal_mnemonic_medium"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.typeCheckingMode": "strict",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"explorer.excludeGitIgnore": false,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/BUILD": true
},
"python.formatting.provider": "none"
"python.analysis.diagnosticMode": "workspace"
}
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ FROM python:3.11-bookworm

# Set the working directory to /app
WORKDIR /app
RUN pip install pyright
RUN pyright .

# Install deps
COPY pyproject.toml ./
RUN pip install .[dev]
RUN pip install .[tests]
RUN pip install --upgrade .[dev]
RUN pip install --upgrade .[tests]

# Ensure pyright builds correctly.
# If run in make validate, it is run in parallel, which breaks its installation.
RUN pyright .

# Install the entire app
COPY . /app
RUN pip install -e .
52 changes: 33 additions & 19 deletions application/main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
from collections import defaultdict
from pathlib import Path
from time import sleep
from typing import Annotated, Any, Dict
from typing import Annotated, Any

import sentry_sdk
import typer
from functionalpy import Seq
from personal_mnemonic_medium.card_pipeline import CardPipeline
from personal_mnemonic_medium.exporters.anki.package_generator import (
AnkiPackageGenerator,
)
from personal_mnemonic_medium.exporters.anki.sync import sync_deck
from personal_mnemonic_medium.note_factories.markdown import MarkdownNoteFactory
from personal_mnemonic_medium.note_factories.markdown import (
MarkdownNoteFactory,
)
from personal_mnemonic_medium.prompt_extractors.cloze_extractor import (
ClozePromptExtractor,
)
from personal_mnemonic_medium.prompt_extractors.qa_extractor import QAPromptExtractor
from personal_mnemonic_medium.prompt_extractors.qa_extractor import (
QAPromptExtractor,
)
from wasabi import Printer

msg = Printer(timestamp=True)


# helper for creating anki connect requests
def request(action: Any, **params: Any) -> Dict[str, Any]:
def request(action: Any, **params: Any) -> dict[str, Any]:
return {"action": action, "params": params, "version": 6}


Expand All @@ -30,12 +34,16 @@ def main(
host_output_dir: Path,
watch: Annotated[
bool,
typer.Option(help="Keep running, updating Anki deck every 15 seconds"),
typer.Option(
help="Keep running, updating Anki deck every 15 seconds"
),
],
):
"""Run the thing."""
if not input_dir.exists():
raise FileNotFoundError(f"Input directory {input_dir} does not exist")
raise FileNotFoundError(
f"Input directory {input_dir} does not exist"
)

if not host_output_dir.exists():
msg.info(f"Creating output directory {host_output_dir}")
Expand All @@ -59,17 +67,17 @@ def main(
ClozePromptExtractor(),
],
card_exporter=AnkiPackageGenerator(), # Step 3, get the cards from the prompts
).run(
input_path=input_dir,
)

decks = defaultdict(list)
).run(input_path=input_dir)

for card in cards:
decks[card.deckname] += [card]
grouped_cards = (
Seq(cards).group_by(lambda card: card.deckname).to_iter()
)

for deck in decks:
deck_bundle = AnkiPackageGenerator().cards_to_deck_bundle(cards=decks[deck])
for group in grouped_cards:
cards = group.group_contents.to_list()
deck_bundle = AnkiPackageGenerator().cards_to_deck_bundle(
cards=cards
)
sync_deck(
deck_bundle=deck_bundle,
sync_dir_path=host_output_dir,
Expand All @@ -79,10 +87,16 @@ def main(

if watch:
sleep_seconds = 60
msg.good(f"Sync complete, sleeping for {sleep_seconds} seconds")
msg.good(
f"Sync complete, sleeping for {sleep_seconds} seconds"
)
sleep(sleep_seconds)
main(input_dir=input_dir, watch=watch, host_output_dir=host_output_dir)
main(
input_dir=input_dir,
watch=watch,
host_output_dir=host_output_dir,
)



if __name__ == "__main__":
typer.run(main)
Loading
Loading