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

papis-html: fixup and modernize code #60

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
# 17:00 on Friday (UTC)
- cron: "00 17 * * 5"

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
fail-fast: False

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install
run: make ci-install

- name: Run tests, mypy and linting
run: make ci-test
shell: bash
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PYTHON=python

all: help

help: ## Show this help
@echo -e "Specify a command. The choices are:\n"
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-18s\033[m %s\n", $$1, $$2}'
@echo ""
.PHONY: help

ci-install:
make -C papis-html ci-install
.PHONY: ci-install

ci-test:
make -C papis-html ci-lint
.PHONY: ci-test
30 changes: 30 additions & 0 deletions papis-html/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PYTHON=python

all: help

help: ## Show this help
@echo -e "Specify a command. The choices are:\n"
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-18s\033[m %s\n", $$1, $$2}'
@echo ""
.PHONY: help

ci-install:
$(PYTHON) -m pip install --upgrade pip setuptools wheel
$(PYTHON) -m pip install -e .[develop]
.PHONY: ci-install

ci-lint:
python -m flake8 papis_html
python -m mypy --show-error-codes papis_html
.PHONY: ci-lint

tags: ## Generate ctags for main codebase
ctags -f tags \
--recurse=yes \
--tag-relative=yes \
--fields=+l \
--kinds-python=-i \
--language-force=python \
papis
.PHONY: tags

27 changes: 12 additions & 15 deletions papis-html/README.rst
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
.. image:: https://badge.fury.io/py/papis-html.svg
:target: https://badge.fury.io/py/papis-html

Papis-HTML
papis-html
==========

::

Usage: papis-html [OPTIONS] [QUERY]

Create a simple searchable offline html site with your references
For instance, doing

Options:
-h, --help Show this message and exit.
--out TEXT Output directory
.. code:: sh

For instance, doing
papis html einstein -o einstein-papers

::
will get you a directory ``einstein-papers`` with a website inside. This website
uses local files, so may not work directly when opened in a modern browser
(due to XSS precautions). You can start a simple web server in the generated
directory with

papis html einstein -o einstein-papers
.. code:: sh

will get you a directory ``einstein-papers`` with a website inside.
python -m http.server -d einstein-papers -b 127.0.0.1 8000
firefox 127.0.0.1:8000

You can find an example in
`here <https://papis.github.io/papis-html/einstein/>`_.
You can find an example `here <https://papis.github.io/papis-html/einstein/>`__.

Acknowledgements
================
Expand Down
54 changes: 25 additions & 29 deletions papis-html/papis_html/__init__.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import shutil

import click

import papis.cli
import papis.api
import papis.logging
from papis.commands.export import run as export
import os
import shutil
import logging

logger = logging.getLogger('papis-html')
logging.basicConfig(level=logging.INFO)
logger = papis.logging.get_logger("papis_html")

template_folder = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'data'
"data"
)


@click.command()
@papis.cli.query_option()
@click.help_option('-h', '--help')
@papis.cli.query_argument()
@click.help_option("-h", "--help")
@click.option(
'-o', '--out',
help='Output directory',
default='bibliography'
"-o", "--out",
help="Output directory",
default="html"
)
def main(query, out):
def main(query: str, out: str) -> None:
"""
Create a simple searchable offline html site with your references
Create a simple searchable offline HTML site with your documents
"""
if os.path.exists(out):
logger.error("Output directory '%s' already exists.", out)

logger.info('Searching in database..'.format(out))
logger.info("Searching in database.")
docs = papis.api.get_documents_in_lib(
library=papis.api.get_lib_name(),
search=query
)

logger.info('Saving in folder {}'.format(out))
bibtex_text = export(docs, to_format='bibtex')
bibtex_text = export(docs, to_format="bibtex")

logger.info('template files in {}'.format(template_folder))
shutil.copytree(
template_folder,
out
)
shutil.copytree(template_folder, out)
logger.info("Template files copied from '%s'.", template_folder)
logger.info("Saving in folder '%s'.", out)

bibtex_outfile = os.path.join(out, 'library.bib')
logger.info('Creating bib file in {}'.format(bibtex_outfile))
with open(bibtex_outfile, 'w+') as fd:
bibtex_outfile = os.path.join(out, "papis-html-library.bib")
with open(bibtex_outfile, "w+") as fd:
fd.write(bibtex_text)

logger.info('Done!')

if __name__ == "__main__":
main()
logger.info("Created BibTex file: '%s'.", bibtex_outfile)
12 changes: 7 additions & 5 deletions papis-html/papis_html/data/css/bootstrap.min.css

Large diffs are not rendered by default.

Loading