Skip to content

Commit

Permalink
feat: Add apkg import option (#18)
Browse files Browse the repository at this point in the history
* Move test data for local_import into folder

* Add apkg import option

* Install dev-requirements in gha

* Update python version to 3.9

* Run mypy without arguments in gha

* Add zstandard_wheels to repo

* Remove support for new apkg format

* Undo change to __init__ file

* Add comment

* chore: reorganize requirements

* chore: add build script, edit readme

* chore: comment out not wokring test

* chore: remove todo comments

* chore: update checks GHA

* chore: fix build script

* chore: Add note about running tests to readme

* perf: Dont create zipfile for every file in zip

* ref: Refactor tests

* Check for media file conflicts in background
  • Loading branch information
RisingOrange authored Jul 21, 2023
1 parent 7a1a5b8 commit 2c8b6da
Show file tree
Hide file tree
Showing 20 changed files with 479 additions and 212 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Install Python libraries
run: python -m pip install aqt mypy pyqt5-stubs types-requests types-simplejson pycryptodome
run: python -m pip install -r dev-requirements.txt

- name: Run the build script
run: python scripts/build.py

- name: Run mypy
run: python -m mypy ./src
run: python -m mypy
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
It may not be possible to delete the add-on during runtime.
In that case, you will need to open the addon directory by clicking 'View Files',
close Anki, and manually delete the addon directory.

# Development

Run the following code to install all required packages
## Installing packages needed for development
```bash
pip install -r dev-requirements.txt
```

## Building the add-on
```bash
python scripts/build.py
```

## Type checking
You need to build the add-on first:
```bash
pip install --no-deps --target=./src/media_import/libs -r requirements.txt
python scripts/build.py
```

Run the following code to get a list of packages to add to requirements.txt
Then you can run mypy:
```bash
mypy
```

## Tests
You need to build the add-on first:
```bash
pip install --target=./temp/libs <package_name>
pip freeze --path=./temp/libs > temp_reqs.txt
python scripts/build.py
```

Then you can run pytest:
```bash
python -m pytest tests
```
13 changes: 12 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-r requirements.txt

git+https://github.com/andrewsanchez/[email protected]
anki==2.1.56
aqt==2.1.56

pyqt5==5.15.5
pyqt5-qt5==5.15.2
pyqtwebengine==5.15.5
pyqtwebengine-qt5==5.15.2
pyaes==1.6.1
types-requests==2.31.0.1

git+https://github.com/ankipalace/pytest-anki.git
mypy==0.971
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[mypy]
files = src/media_import, tests
no_strict_optional = True
disallow_untyped_defs = True
exclude = (?:src/media_import/libs/)
36 changes: 36 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path

import _aqt
import anki
import subprocess


def vendor_requirements():
"""Install requirements into the src/media_import/libs directory."""
subprocess.run(
[
"python",
"-m",
"pip",
"install",
"--no-deps",
"--target=./src/media_import/libs",
"--upgrade",
"-r",
"requirements.txt",
],
check=True,
)

def create_init_file(module):
module_path = Path(module.__path__[0])
init_file_path = module_path / "__init__.py"
init_file_path.touch(exist_ok=True)


if __name__ == "__main__":
vendor_requirements()

# This makes mypy type checking work on Anki versions >= 2.1.55
create_init_file(anki)
create_init_file(_aqt)
7 changes: 5 additions & 2 deletions src/media_import/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from aqt.utils import openFolder, restoreGeom, saveGeom

from .importing import ImportResult
from .tabs import GDriveTab, ImportTab, LocalTab, MegaTab
from .tabs import ApkgTab, GDriveTab, ImportTab, LocalTab, MegaTab


class ImportResultDialog(QMessageBox):
Expand Down Expand Up @@ -34,6 +34,7 @@ def __init__(self) -> None:
QDialog.__init__(self, mw, Qt.WindowType.Tool)
self.setWindowTitle("Import Media")
self.setMinimumWidth(500)
self.setMinimumHeight(230)
self.setup()
self.setup_buttons()
restoreGeom(self, f"addon-mediaimport-import")
Expand All @@ -50,7 +51,9 @@ def setup(self) -> None:
main_layout.addSpacing(10)

self.local_tab = LocalTab(self)
main_tab.addTab(self.local_tab, "Local Files")
main_tab.addTab(self.local_tab, "Local Folder")
self.apkg_tab = ApkgTab(self)
main_tab.addTab(self.apkg_tab, "Anki Deck Package (*.apkg)")
self.gdrive_tab = GDriveTab(self)
main_tab.addTab(self.gdrive_tab, "Google Drive")
self.mega_tab = MegaTab(self)
Expand Down
Loading

0 comments on commit 2c8b6da

Please sign in to comment.