summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/README.md41
-rw-r--r--python/TODO6
-rwxr-xr-xpython/codegen_python_client.sh5
-rw-r--r--python/fatcat/templates/base.html1
-rw-r--r--python/fatcat/templates/release_view.html2
-rw-r--r--python/fatcat_client/api/default_api.py20
-rw-r--r--python/tests/grobid_metadata_importer.py8
7 files changed, 62 insertions, 21 deletions
diff --git a/python/README.md b/python/README.md
index 1369051a..9ba6b990 100644
--- a/python/README.md
+++ b/python/README.md
@@ -1,18 +1,47 @@
-## Python Web Interface and API Client Library
+## Python Web Interface
-Use `pipenv` (which you can install with `pip`).
+This project uses `pipenv` to manage dependencies, and assumes Python 3.5
+(which pipenv may install if you are running a different local version). You
+can can install `pipenv` with `pip`. You may want to set the
+`PIPENV_VENV_IN_PROJECT` environment variable on your development machine (see
+pipenv docs for details).
+To just run the web interface (which will try to connect to a back-end API
+server on the same machine by default), use:
+
+ # will listen on http://localhost:9810 by default
pipenv run fatcat_webface.py
-Run tests:
+## Python Client Library
+
+An auto-generated python client library for the fatcat API lives under
+`./fatcat_client`. It includes entity model objects and functions to call all
+API endpoints; see `./README_codegen.md` for details.
+
+To re-generate swagger-codegen python client library (requires docker installed
+locally):
+
+ ./codegen_python_client.sh
+
+## Running Tests
+
+Many (though not all) python tests depend on access to a local running API
+server (the `fatcatd` rust daemon, code in `../rust/`), which itself depends on
+a local PostgreSQL database server. Tests will fail if this endpoint isn't
+found. See the README there to get that set up first. The CI integration tests
+build and start this daemon automatically.
+
+To run the python tests (with `fatcatd` running locally on port 9411):
pipenv install --dev
pipenv run pytest
- # for coverage:
+To calculate code coverage (of python code):
+
pipenv run pytest --cov --cov-report html
-Regeneate swagger-codegen python client library (requires docker):
+To run 'lint' on the code base (note that this is pretty noisy and isn't
+enforced by CI yet):
- ./codegen_python_client.sh
+ pipenv run pylint --disable bad-continuation,arguments-differ,unidiomatic-typecheck fatcat
diff --git a/python/TODO b/python/TODO
index 54b63dd3..7a6eb10f 100644
--- a/python/TODO
+++ b/python/TODO
@@ -1,4 +1,10 @@
+Idea for new module structure: refactor 'fatcat_client' into 'fatcat' and have
+that be the general purpose API client. create a new 'fatcat_services' for web
+interface, importers, workers, etc, which depends on the other module.
+potentially, move library module into subdirectory or another top-level folder
+("python-fatcat"? "python-library"?).
+
- use dict counter type (in python collections) instead of currently janky counters
- schema.org metadata for releases
diff --git a/python/codegen_python_client.sh b/python/codegen_python_client.sh
index 4cd30c44..3344c214 100755
--- a/python/codegen_python_client.sh
+++ b/python/codegen_python_client.sh
@@ -6,7 +6,7 @@ set -o pipefail
OUTPUT=`pwd`/codegen-out
mkdir -p $OUTPUT
# Strip tags, so entire API is under a single class
-cat ../fatcat-openapi2.yml | grep -v "TAGLINE$" > $OUTPUT/api.yml
+cat ../fatcat-openapi2.yml | grep -v "TAGLINE$" | sed 's/\[https\]/\[http\]/g' > $OUTPUT/api.yml
docker run \
-v $OUTPUT:/tmp/swagger/ \
@@ -23,4 +23,5 @@ mkdir -p tests/codegen_tests
cp -r $OUTPUT/fatcat_client/* fatcat_client
cp -r $OUTPUT/test/* tests/codegen_tests
cp $OUTPUT/README.md README_codegen.md
-#rm -rf $OUTPUT
+# safer than 'rm -rf $OUTPUT'
+mv $OUTPUT /tmp
diff --git a/python/fatcat/templates/base.html b/python/fatcat/templates/base.html
index 670d854f..856a6e03 100644
--- a/python/fatcat/templates/base.html
+++ b/python/fatcat/templates/base.html
@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width">
<title>{% block title %}fatcat!{% endblock %}</title>
+ <meta name="referrer" content="origin-when-cross-origin">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.3.2/dist/semantic.min.css">
<script
diff --git a/python/fatcat/templates/release_view.html b/python/fatcat/templates/release_view.html
index 3c05653b..39dcf8fd 100644
--- a/python/fatcat/templates/release_view.html
+++ b/python/fatcat/templates/release_view.html
@@ -22,7 +22,7 @@
<div class="one wide column"></div>
<div class="ten wide column" style="font-size: 16px;">
-{% if release.release_date != None %}<p><b>Date (published):</b> {{ release.release_date[:10] }}{% endif %}
+{% if release.release_date != None %}<p><b>Date (published):</b> {{ release.release_date }}{% endif %}
{% if release.pmid != None %}
<br><b>PubMed:</b> <a href="https://www.ncbi.nlm.nih.gov/pubmed/{{ release.pmid }}">&nbsp;<code>{{ release.pmid }}</code></a>
{% endif %}
diff --git a/python/fatcat_client/api/default_api.py b/python/fatcat_client/api/default_api.py
index a5971279..d3ce3cee 100644
--- a/python/fatcat_client/api/default_api.py
+++ b/python/fatcat_client/api/default_api.py
@@ -1970,7 +1970,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For containers, none accepted (yet).
:return: ContainerEntity
If the method is called asynchronously,
returns the request thread.
@@ -1992,7 +1992,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For containers, none accepted (yet).
:return: ContainerEntity
If the method is called asynchronously,
returns the request thread.
@@ -2172,7 +2172,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For creators, none accepted (yet).
:return: CreatorEntity
If the method is called asynchronously,
returns the request thread.
@@ -2194,7 +2194,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For creators, none accepted (yet).
:return: CreatorEntity
If the method is called asynchronously,
returns the request thread.
@@ -2770,7 +2770,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For files, none accepted (yet).
:return: FileEntity
If the method is called asynchronously,
returns the request thread.
@@ -2792,7 +2792,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For files, none accepted (yet).
:return: FileEntity
If the method is called asynchronously,
returns the request thread.
@@ -2972,7 +2972,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For releases, 'files' and 'container' are valid.
:return: ReleaseEntity
If the method is called asynchronously,
returns the request thread.
@@ -2994,7 +2994,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For releases, 'files' and 'container' are valid.
:return: ReleaseEntity
If the method is called asynchronously,
returns the request thread.
@@ -3364,7 +3364,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For works, none accepted (yet).
:return: WorkEntity
If the method is called asynchronously,
returns the request thread.
@@ -3386,7 +3386,7 @@ class DefaultApi(object):
:param async bool
:param str id: (required)
- :param str expand: List of sub-entities to expand in response. For now, only 'all' accepted.
+ :param str expand: List of sub-entities to expand in response. For works, none accepted (yet).
:return: WorkEntity
If the method is called asynchronously,
returns the request thread.
diff --git a/python/tests/grobid_metadata_importer.py b/python/tests/grobid_metadata_importer.py
index 7bbabb39..2c8565aa 100644
--- a/python/tests/grobid_metadata_importer.py
+++ b/python/tests/grobid_metadata_importer.py
@@ -1,5 +1,7 @@
+import os
import json
+import base64
import pytest
from fatcat.grobid_metadata_importer import FatcatGrobidMetadataImporter
@@ -34,10 +36,12 @@ def test_file_metadata_parse(grobid_metadata_importer):
with open('tests/files/example_grobid_metadata_lines.tsv', 'r') as f:
f.readline()
raw = f.readline().split('\t')
+ # randomize sha1 so tests are repeatable
+ random_sha1 = "sha1:{}".format(base64.b32encode(os.urandom(20)).decode('utf-8').upper())
fe = grobid_metadata_importer.parse_file_metadata(
- raw[0], json.loads(raw[1]), raw[2], int(raw[3]))
+ random_sha1, json.loads(raw[1]), raw[2], int(raw[3]))
assert fe
- assert fe.sha1 == "d4a841744719518bf8bdd5d91576ccedc55efbb5" # "sha1:2SUEC5CHDFIYX6F52XMRK5WM5XCV565V"
+ #assert fe.sha1 == "d4a841744719518bf8bdd5d91576ccedc55efbb5" # "sha1:2SUEC5CHDFIYX6F52XMRK5WM5XCV565V"
assert fe.md5 == None
assert fe.mimetype == "application/pdf"
assert fe.size == 142710