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

Bump min Papis version #55

Merged
merged 5 commits into from
Nov 16, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
fail-fast: False

steps:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ mypy: ## Run (strict) mypy checks
.PHONY: mypy

pytest: ## Run pytest test and doctests
python -m pytest -rswx --cov=papis_zotero -v -s tests
python -m pytest -rswx -v -s tests
.PHONY: pytest

ci-install: ## Run pip and install dependencies on CI
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade pip hatchling wheel
python -m pip install -e '.[develop]'
.PHONY: ci-install
6 changes: 3 additions & 3 deletions papis_zotero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
logger = papis.logging.get_logger(__name__)


@click.group("zotero") # type: ignore[arg-type]
@click.group("zotero")
@click.help_option("-h", "--help")
def main() -> None:
"""Zotero interface for papis."""


@main.command("serve") # type: ignore[arg-type]
@main.command("serve")
@click.help_option("-h", "--help")
@click.option("--port",
help="Port to listen to",
Expand Down Expand Up @@ -56,7 +56,7 @@ def serve(address: str, port: int, set_list: List[Tuple[str, str]],) -> None:
httpd.serve_forever()


@main.command("import") # type: ignore[arg-type]
@main.command("import")
@click.help_option("-h", "--help")
@click.option(
"-f",
Expand Down
38 changes: 19 additions & 19 deletions papis_zotero/bibtex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from typing import Optional
import re
from typing import Any, Dict, Optional

import papis.bibtex
import papis.commands.add
Expand All @@ -8,6 +9,8 @@

logger = papis.logging.get_logger(__name__)

RE_SEPARATOR = re.compile(r"\s*,\s*")


def add_from_bibtex(bib_file: str,
out_folder: Optional[str] = None,
Expand All @@ -18,28 +21,25 @@ def add_from_bibtex(bib_file: str,
entries = papis.bibtex.bibtex_to_dict(bib_file)
nentries = len(entries)
for i, entry in enumerate(entries):
# cleanup tags
if "date" in entry:
date = str(entry.pop("date")).split("-")
entry["year"] = int(date[0]) # type: ignore[assignment]
entry["month"] = int(date[1]) # type: ignore[assignment]
result: Dict[str, Any] = entry.copy()

if "keywords" in entry:
entry["tags"] = entry.pop("keywords")
# cleanup date
if "date" in result:
date = str(result.pop("date")).split("-")
result["year"] = int(date[0])
result["month"] = int(date[1])

if "author" not in entry:
if "tags" in entry:
entry["tags"] = "{} unknown-author".format(entry["tags"])
else:
entry["tags"] = "unknown-author"
# cleanup tags
if "keywords" in result:
result["tags"] = RE_SEPARATOR.split(result.pop("keywords"))

if "ref" in entry:
entry["ref"] = papis.bibtex.ref_cleanup(entry["ref"])
if "ref" in result:
result["ref"] = papis.bibtex.ref_cleanup(result["ref"])
else:
entry["ref"] = papis.bibtex.create_reference(entry)
result["ref"] = papis.bibtex.create_reference(result)

# get file
pdf_file = entry.pop("file", None)
pdf_file = result.pop("file", None)
if pdf_file is not None:
pdf_file = pdf_file.split(":")[1]
pdf_file = os.path.join(*pdf_file.split("/"))
Expand All @@ -53,8 +53,8 @@ def add_from_bibtex(bib_file: str,

# add to library
logger.info("[%4d/%-4d] Exporting item with ref '%s'.",
i, nentries, entry["ref"])
i, nentries, result["ref"])

papis.commands.add.run([pdf_file] if pdf_file is not None else [],
data=entry,
data=result,
link=link)
2 changes: 1 addition & 1 deletion papis_zotero/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}]),
_k("tags", [{
"key": "tags",
"action": lambda t: "; ".join(tag["tag"] for tag in t)
"action": lambda t: [tag["tag"] for tag in t]
}]),
_k("date", [
{"key": "year", "action": lambda d: int(d.split("-")[0])},
Expand Down
14 changes: 6 additions & 8 deletions papis_zotero/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

logger = papis.logging.get_logger(__name__)

# separator between multiple tags
# FIXME: this should be handled by papis
ZOTERO_TAG_DELIMITER = " "

# fuzzy date matching
ISO_DATE_RE = re.compile(r"(?P<year>\d{4})-?(?P<month>\d{2})?-?(?P<day>\d{2})?")

Expand Down Expand Up @@ -162,11 +158,11 @@ def get_files(connection: sqlite3.Connection, item_id: str, item_key: str,
"""


def get_tags(connection: sqlite3.Connection, item_id: str) -> Dict[str, str]:
def get_tags(connection: sqlite3.Connection, item_id: str) -> Dict[str, List[str]]:
cursor = connection.cursor()
cursor.execute(ZOTERO_QUERY_ITEM_TAGS, (item_id,))

tags = ZOTERO_TAG_DELIMITER.join(str(row[0]) for row in cursor)
tags = [str(row[0]) for row in cursor]
return {"tags": tags} if tags else {}


Expand Down Expand Up @@ -221,7 +217,8 @@ def get_collections(connection: sqlite3.Connection,
""".format(",".join(["?"] * len(papis_zotero.utils.ZOTERO_EXCLUDED_ITEM_TYPES)))


def add_from_sql(input_path: str, out_folder: Optional[str] = None,
def add_from_sql(input_path: str,
out_folder: Optional[str] = None,
link: bool = False) -> None:
"""
:param inpath: path to zotero SQLite database "zoter.sqlite" and
Expand Down Expand Up @@ -259,6 +256,7 @@ def add_from_sql(input_path: str, out_folder: Optional[str] = None,
if out_folder is not None:
papis.config.set_lib_from_name(out_folder)

folder_name = papis.config.getstring("add-folder-name")
for i, (item_id, item_type, item_key, date_added) in enumerate(cursor, start=1):
# convert fields
date_added = (
Expand All @@ -284,7 +282,7 @@ def add_from_sql(input_path: str, out_folder: Optional[str] = None,
i, items_count, item_key, out_folder)

papis.commands.add.run(paths=files, data=item, link=link,
folder_name=papis.config.getstring("add-folder-name")
folder_name=folder_name
)

logger.info("Finished exporting from '%s'.", input_path)
Expand Down
46 changes: 26 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=1.10.0"]
requires = [ "hatchling>=1.10" ]

[project]
name = "papis-zotero"
description = "Interact with Zotero using papis"
version = "0.1.2"
authors = [{ name = "Alejandro Gallo", email = "aamsgallo@gmail.com" }]
maintainers = [{ name = "Alejandro Gallo", email = "aamsgallo@gmail.com" }]
description = "Interact with Zotero using papis"
readme = "README.rst"
license = { text = "GPLv3" }
keywords = [ "bibtex", "biliography", "cli", "management", "papis", "zotero" ]
license = { text = "GPL-3.0-or-later" }
maintainers = [ { name = "Alejandro Gallo", email = "aamsgallo@gmail.com" } ]
authors = [ { name = "Alejandro Gallo", email = "aamsgallo@gmail.com" } ]
requires-python = ">=3.8"
classifiers = [
"Environment :: Console :: Curses",
"Environment :: Console",
"Environment :: Console :: Curses",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
Expand All @@ -29,43 +31,47 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Utilities",
]
keywords = ["bibtex", "biliography", "cli", "management", "papis", "zotero"]
dependencies = ["papis==0.13"]

[project.urls]
Repository = "https://github.com/papis/papis-zotero"
dependencies = [ "papis>=0.14,<0.15" ]

[project.optional-dependencies]
"develop" = [
develop = [
"flake8",
"flake8-bugbear",
"flake8-pyproject",
"flake8-quotes",
"Flake8-pyproject",
"mypy>=0.7",
"pep8-naming",
"pytest",
"pytest-cov",
"python-coveralls",
"types-PyYAML",
"types-tqdm",
"types-pyyaml",
]

[project.urls]
Repository = "https://github.com/papis/papis-zotero"

[project.entry-points."papis.command"]
"zotero" = "papis_zotero:main"
zotero = "papis_zotero:main"

[tool.flake8]
select = ["B", "D", "E", "F", "N", "Q", "W"]
extend-ignore = ["B019", "E123", "N818", "W503"]
select = [ "B", "D", "E", "F", "N", "Q", "W" ]
extend-ignore = [ "B019", "E123", "N818", "W503" ]
max-line-length = 88
inline-quotes = "double"
multiline-quotes = "double"

[tool.pytest.ini_options]
addopts = [
"--doctest-modules",
"--cov=papis_zotero",
]
norecursedirs = ".git doc build dist"
python_files = "*.py"
markers = ["config_setup: setup for tmp_config",
markers = [
"config_setup: setup for tmp_config",
"library_setup: setup for tmp_library",
]

Expand All @@ -74,4 +80,4 @@ strict = true
show_column_numbers = true
hide_error_codes = false
pretty = true
warn_unused_ignores = false
warn_unused_ignores = true
31 changes: 0 additions & 31 deletions tests/conftest.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/resources/bibtex/zotero-library.bib
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @article{schaeffer_efficient_2013
author = {Schaeffer, Nathanaël},
urldate = {2023-02-26},
date = {2013-03},
langid = {english},
langid = {english}
file = {Full Text:files/8/Schaeffer - 2013 - Efficient spherical harmonic transforms aimed at p.pdf:application/pdf},
}

Expand Down
5 changes: 3 additions & 2 deletions tests/resources/bibtex_out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ journaltitle: Journal of Computational Physics
langid: english
month: 7
pages: 17--38
ref: ReviewOfSummaSvard2014
tags: sbp
ref: svard_review_2014
tags:
- sbp
title: Review of summation-by-parts schemes for initial–boundary-value problems
type: article
url: https://linkinghub.elsevier.com/retrieve/pii/S002199911400151X
Expand Down
3 changes: 1 addition & 2 deletions tests/test_bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import papis.database
import papis.document
import papis_zotero.bibtex

from .testlib import TemporaryLibrary
from papis.testing import TemporaryLibrary


@pytest.mark.skipif(os.name == "nt", reason="encoding is incorrect on windows")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import papis.yaml
import papis.document
import papis_zotero.sql

from .testlib import TemporaryLibrary
from papis.testing import TemporaryLibrary


@pytest.mark.skipif(os.name == "nt", reason="encoding is incorrect on windows")
Expand Down
Loading
Loading