From 9da7e6cc0d4e45fd7abf1d2536ed59be76215fb6 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 27 Oct 2023 20:25:06 +0200 Subject: [PATCH] ci: use nimble-python --- .cookiecutter.json | 5 +- .cruft.json | 9 +- .devcontainer/devcontainer.json | 68 ++++++++------- .github/workflows/dependabot_automerge.yml | 30 ------- .github/workflows/{validate.yml => tests.yml} | 25 +++--- .vscode/launch.json | 19 ---- .vscode/settings.json | 17 ++-- makefile | 55 +++++++----- pyproject.toml | 86 +++++++------------ readme.md | 64 ++++++++++++-- 10 files changed, 192 insertions(+), 186 deletions(-) delete mode 100644 .github/workflows/dependabot_automerge.yml rename .github/workflows/{validate.yml => tests.yml} (60%) delete mode 100644 .vscode/launch.json diff --git a/.cookiecutter.json b/.cookiecutter.json index e80c2a10..202857ac 100644 --- a/.cookiecutter.json +++ b/.cookiecutter.json @@ -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", diff --git a/.cruft.json b/.cruft.json index 3f72bab4..3bcf6242 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { - "template": "https://github.com/MartinBernstorff/swift-python-cookiecutter", - "commit": "525b1f682621953d7ef9deb6ad6cf7359ebd43c8", + "template": "https://github.com/MartinBernstorff/nimble-python-cookiecutter", + "commit": "d65d50c7215714a4e6df85be23c5cd9066db9cc0", "checkout": null, "context": { "cookiecutter": { @@ -8,15 +8,16 @@ "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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 841db021..f049add4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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: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" } \ No newline at end of file diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml deleted file mode 100644 index 22d2ecd7..00000000 --- a/.github/workflows/dependabot_automerge.yml +++ /dev/null @@ -1,30 +0,0 @@ -# GitHub action to automerge dependabot PRs. Only merges if tests passes the -# branch protections in the repository settings. -# You can set branch protections in the repository under Settings > Branches > Add rule -name: automerge-bot-prs - -on: pull_request - -permissions: - contents: write - pull-requests: write - -jobs: - dependabot-automerge: - runs-on: ubuntu-latest - # if actor is dependabot or pre-commit-ci[bot] then run - if: ${{ github.actor == 'dependabot[bot]' }} - - steps: - # Checkout action is required for token to persist - - name: Enable auto-merge for Dependabot PRs - run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR - env: - PR_URL: ${{github.event.pull_request.html_url}} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Auto approve dependabot PRs - if: ${{ github.actor == 'dependabot[bot]' }} - uses: hmarr/auto-approve-action@v3.1.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/validate.yml b/.github/workflows/tests.yml similarity index 60% rename from .github/workflows/validate.yml rename to .github/workflows/tests.yml index 8064d438..ac2134b3 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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/ci@v0.3 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 \ No newline at end of file + make validate diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index b7594878..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Run main on Life Lessons", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "args": [ - "/input/", - "Life.apkg" - ], - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 190db2e1..2483f957 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } \ No newline at end of file diff --git a/makefile b/makefile index a547efa1..cf64fdf7 100644 --- a/makefile +++ b/makefile @@ -1,28 +1,43 @@ -lint: - @echo Running black - black . +SRC_PATH = personal_mnemonic_medium - @echo Running ruff +install-dev: + pip install -r dev-requirements.txt + +install-deps: + pip install -r requirements.txt + +install: + make install-deps + make install-dev + pip install -e . + +test: ## Run tests + pytest $(SRC_PATH) + +lint: ## Format code ruff check . --fix + ruff format . -test: - @echo ––– Testing ––– - pytest -n auto -rfE --failed-first --disable-warnings -q +type-check: ## Type-check code + pyright $(SRC_PATH) -type-check: - @echo ––– Running static type checks ––– - pyright . +validate: ## Run all checks + make lint + make type-check + make test -install: - pip install --upgrade -e .[dev,tests] +sync-pr: + git push --set-upstream origin HEAD + git push -validate: - @echo ––– Ensuring dependencies are up to date. This will take a few moments --- - @make install > /dev/null - @make lint && make type-check && make test +create-pr: + gh pr create -w || true -pr: - gh pr create -w +merge-pr: + gh pr merge --auto --merge --delete-branch + +pr: ## Run relevant tests before PR + make sync-pr + make create-pr make validate - git push - gh pr merge --auto --merge \ No newline at end of file + make merge-pr \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 66fb2f30..df59ba7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,23 +1,22 @@ -# v1 -# v2 [build-system] requires = ["setuptools>=61.0.0", "wheel", "setuptools_scm"] build-backend = "setuptools.build_meta" [project] name = "personal-mnemonic-medium" -version = "0.2.0" -authors = [ - { name = "Martin Bernstorff", email = "martinbernstorfff@gmail.com" }, -] +version = "0.0.0" +authors = [{ name = "Martin Bernstorff", email = "martinbernstorff@gmail.com" }] description = "Personal Mnemonic Medium" -classifiers = [ - "Operating System :: POSIX :: Linux", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Programming Language :: Python :: 3.10", -] -requires-python = ">=3.10" +classifiers = ["Programming Language :: Python :: 3.11"] +requires-python = ">=3.11" +[project.license] +file = "LICENSE" +name = "MIT" + +[project.readme] +file = "README.md" +content-type = "text/markdown" + dependencies = [ "misaka==2.1.1", "genanki==0.13.0", @@ -48,10 +47,8 @@ repository = "https://github.com/MartinBernstorff/personal-mnemonic-medium" documentation = "https://MartinBernstorff.github.io/personal-mnemonic-medium/" [tool.pyright] -exclude = [".*venv*", ".tox", "*.apkg"] +exclude = [".*venv*", ".tox"] pythonPlatform = "Darwin" -typeCheckingMode = "basic" - [tool.ruff] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. @@ -83,7 +80,23 @@ select = [ "SIM", "W", ] -ignore = ["ANN101", "ANN401", "E402", "E501", "F401", "F841", "UP006", "RET504"] +ignore = [ + "ANN101", + "ANN401", + "E402", + "E501", + "F401", + "F841", + "RET504", + "COM812", + "COM819", + "Q000", + "Q001", + "Q002", + "Q003", + "W191", +] +ignore-init-module-imports = true # Allow autofix for all enabled rules (when `--fix`) is provided. unfixable = ["ERA"] # Exclude a variety of commonly ignored directories. @@ -112,7 +125,7 @@ exclude = [ ] # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -target-version = "py39" +target-version = "py311" [tool.ruff.flake8-annotations] mypy-init-return = true @@ -125,42 +138,5 @@ known-third-party = ["wandb"] # Unlike Flake8, default to a complexity level of 10. max-complexity = 10 -[tool.semantic_release] -branch = "main" -version_variable = ["pyproject.toml:version"] -upload_to_pypi = false -upload_to_release = false -build_command = "python -m pip install build; python -m build" - [tool.setuptools] include-package-data = true - - -[tool.tox] -legacy_tox_ini = """ -[tox] -envlist = py{39} - -[testenv] -description: run unit tests -extras = tests -use_develop = true -commands = - pytest -n auto {posargs:test} - -[testenv:type] -description: run type checks -extras = tests, dev -basepython = py39 # Setting these explicitly avoid recreating env if your shell is set to a different version -use_develop = true -commands = - pyright . - -[testenv:docs] -description: build docs -extras = docs -basepython = py39 # Setting these explicitly avoid recreating env if your shell is set to a different version -use_develop = true -commands = - sphinx-build -b html docs docs/_build/html -""" diff --git a/readme.md b/readme.md index 85108c0a..3eb868d9 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,18 @@ # Personal Mnemonic Medium -[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/MartinBernstorff/personal-mnemonic-medium/) + +[![PyPI](https://img.shields.io/pypi/v/personal-mnemonic-medium.svg)][pypi status] +[![Python Version](https://img.shields.io/pypi/pyversions/personal-mnemonic-medium)][pypi status] +[![documentation](https://github.com/MartinBernstorff/personal-mnemonic-medium/actions/workflows/documentation.yml/badge.svg)][documentation] +[![Tests](https://github.com/MartinBernstorff/personal-mnemonic-medium/actions/workflows/tests.yml/badge.svg)][tests] +[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black] + +[pypi status]: https://pypi.org/project/personal-mnemonic-medium/ +[documentation]: https://MartinBernstorff.github.io/personal-mnemonic-medium/ +[tests]: https://github.com/MartinBernstorff/personal-mnemonic-medium/actions?workflow=Tests +[black]: https://github.com/psf/black + + + Extracting spaced repetition prompts (flashcards) from documents. @@ -11,7 +24,10 @@ A [Zettelkasten](https://medium.com/@martinbernstorf/why-you-need-an-idea-manage This thinking is largely inspired by Andy Matuschak's [Personal Mnemonic Medium](https://notes.andymatuschak.org/The_mnemonic_medium_can_be_extended_to_one%E2%80%99s_personal_notes), and the code is based on the unmaintained [Ankdown](https://github.com/benwr/ankdown). -FYI-style open source, maintenance is not guaranteed. + + +## Installation + ## Pipeline The left path describes the abstract pipeline, the right path the current instantiation in this repo. @@ -33,10 +49,44 @@ graph TD Prompts -- AnkiPackageGenerator --> Cards ``` -## Contributing -To get a full +### Setting up a dev environment +1. Install [Orbstack](https://orbstack.dev/) or Docker Desktop. Make sure to complete the full install process before continuing. +2. If not installed, install VSCode +3. Press this [link](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Aarhus-Psychiatry-Research/psycop-common) +4. Complete the setup process + +## Usage + +TODO: Add minimal usage example + +To see more examples, see the [documentation]. + +# 📖 Documentation + +| Documentation | | +| --------------------- | -------------------------------------------------------- | +| 🔧 **[Installation]** | Installation instructions on how to install this package | +| 📖 **[Documentation]** | A minimal and developing documentation | +| 👩‍💻 **[Tutorials]** | Tutorials for using this package | +| 🎛️ **[API Reference]** | API reference for this package | +| 📚 **[FAQ]** | Frequently asked questions | + + +# 💬 Where to ask questions + +| Type | | +| ------------------------------ | ---------------------- | +| 📚 **FAQ** | [FAQ] | +| 🚨 **Bug Reports** | [GitHub Issue Tracker] | +| 🎁 **Feature Requests & Ideas** | [GitHub Issue Tracker] | +| 👩‍💻 **Usage Questions** | [GitHub Discussions] | +| 🗯 **General Discussion** | [GitHub Discussions] | -## Running through docker -To build and run the container, see `docker_cmd.sh`. +[Documentation]: https://MartinBernstorff.github.io/personal-mnemonic-medium/index.html +[Installation]: https://MartinBernstorff.github.io/personal-mnemonic-medium/installation.html +[Tutorials]: https://MartinBernstorff.github.io/personal-mnemonic-medium/tutorials.html +[API Reference]: https://MartinBernstorff.github.io/personal-mnemonic-medium/references.html +[FAQ]: https://MartinBernstorff.github.io/personal-mnemonic-medium/faq.html +[github issue tracker]: https://github.com/MartinBernstorff/personal-mnemonic-medium/issues +[github discussions]: https://github.com/MartinBernstorff/personal-mnemonic-medium/discussions -