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

DRAFT - DO NOT MERGE Convert python 3 - DO NOT MERGE #140

Open
wants to merge 181 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
435b537
Python3 conversion - setup.py, json config load, and cPickle
Nov 14, 2020
d872138
Python3 conversion - setup.py, json config load, cPickle, and print_f…
danstoner Dec 15, 2020
350962d
Merge branch 'convert_python_3' of github.com:iDigBio/idb-backend int…
danstoner Dec 15, 2020
92853ee
replace func_code with __code__
danstoner Dec 15, 2020
cb00c6f
fix imports for email module
danstoner Dec 15, 2020
a57c876
Python3 conversion - setup.py, json config load, cPickle, and print_f…
danstoner Dec 15, 2020
dbfd755
replace func_code with __code__
danstoner Dec 15, 2020
90525b7
fix imports for email module
danstoner Dec 15, 2020
194cdf8
use raw strings so regex escape sequence is valid
danstoner Jan 12, 2021
f172ec8
update gevent to 1.3.0
danstoner Jan 12, 2021
57d811a
Merge branch 'convert_python_3' of github.com:iDigBio/idb-backend int…
danstoner Jan 12, 2021
7ce689b
use raw string so regex escape sequence is valid
danstoner Jan 13, 2021
b67f42d
fix syntax error
danstoner Jan 13, 2021
c26a66c
StandardError exception name was removed in python3
danstoner Jan 13, 2021
500f85d
python3 compatible imports, modules, methods
danstoner Jan 13, 2021
c330940
python3 no longer has a basestring type
danstoner Jan 13, 2021
78e655d
basestring, unicode no longer exist in python3
danstoner Jan 13, 2021
9a9f22f
replace cStringIO
danstoner Jan 13, 2021
6921a69
add a FIXME and replace itertools with standard lib
danstoner Jan 13, 2021
cebfd42
convert boto md5 bytes to string for comparison
danstoner Jan 13, 2021
d4a117c
replace cStringIO
danstoner Jan 13, 2021
32ab835
Exception no longer has a "message" in python3
danstoner Jan 13, 2021
c792a80
StandardError exception name was removed in python3
danstoner Jan 14, 2021
2afe845
imap replaced with map, all strings in python3 are the same type
danstoner Jan 14, 2021
ebc37ce
Exception no longer has a "message" in python3
danstoner Jan 14, 2021
95f9abb
put comment back because not fixed yet
danstoner Jan 14, 2021
7004eff
"reload" moved to importlib in python3
danstoner Jan 14, 2021
d7e0304
main3? Only fixing the print statements for now
danstoner Jan 14, 2021
1ff7ed2
json.dump requires the file-like object to be string-writable
danstoner Jan 14, 2021
90a7561
all strings are the same type in python3
danstoner Jan 14, 2021
f666127
no longer write strings in binary mode
danstoner Jan 14, 2021
e149540
Stop trying to get indexed item out of unordered dict
danstoner Jan 14, 2021
b7595d5
convert boto md5 bytes to string for comparison
danstoner Jan 14, 2021
ecad8bd
itertools izip_longest was replaced with zip_longest in python3
danstoner Jan 14, 2021
f876577
update README with python 3 instructions
danstoner Jan 17, 2021
dc4d24a
izip_longest renamed to zip_longest in python3
danstoner Jan 18, 2021
b1a51b1
convert bytes to string for comparison
danstoner Jan 18, 2021
794272a
gevent.wsgi has been renamed to gevent.pywsgi
danstoner Jan 19, 2021
c8d51d4
fixup section on Testing Dependencies
danstoner Jan 19, 2021
44c9724
bump major version of idb-backend for Python 3 migration
danstoner Jan 19, 2021
43721f2
setup.py changes for Python 3, update Flask
danstoner Jan 19, 2021
47f3c82
only need path from os here
danstoner Jan 19, 2021
2e172ef
test_data_api_downloads python3 compatibility
danstoner Jan 19, 2021
20762f2
tell redis_client to decode responses
danstoner Feb 2, 2021
b0604f4
Let the library open and read bytes of XML from file
danstoner Feb 3, 2021
fb44f4b
iterables fixes
danstoner Feb 3, 2021
7950a2f
iteritems() renamed to items() in python3
danstoner Feb 3, 2021
9d1dc69
b64encode needs a bytes-like object
danstoner Feb 3, 2021
cd36ebe
move testing doc in main README to the existing tests/README
danstoner Feb 4, 2021
56c053f
update developer environment virtualenv setup instructions for py3
danstoner Feb 4, 2021
d0898eb
update Dockerfile with python3 to fix build pipeline for this branch
danstoner Feb 4, 2021
012e81a
update travis build to use python3
danstoner Feb 4, 2021
b95b822
remove trailing whitespace
danstoner Feb 5, 2021
6a5752f
Fix test_continuous subprocess count
danstoner Feb 6, 2021
22ab8a1
Merge branch 'convert_python_3' of github.com:iDigBio/idb-backend int…
danstoner Feb 10, 2021
8d7fb55
add notes for running ES locally for test suite
danstoner Feb 23, 2021
fe2cef4
lists must be in the same order for assertEqual to be true
danstoner Mar 27, 2021
177563b
python3 uses pickle not cPickle
danstoner Mar 28, 2021
834ef2a
werkzeug ProxyFix moved to different library
danstoner Mar 28, 2021
75de07a
remove unused variable (according to linter)
danstoner Mar 28, 2021
09b2c85
remove commented out print debug lines
danstoner Mar 28, 2021
789417b
failing to get the file from storage should be an ERROR
danstoner Mar 29, 2021
03d7fc4
make error message a little more generic
danstoner Mar 29, 2021
426f85b
avoid the redirect (#136)
danstoner Mar 25, 2021
0d96a9c
remove old and temporary comments (#137)
danstoner Mar 25, 2021
f756511
download xml schema before trying to parse it (#138)
danstoner Mar 25, 2021
8477803
update derivatives blacklist with additional bad media (#141)
danstoner Mar 28, 2021
c884a8b
Derivatives multiprocessing procs fix, tweak timer (#143)
danstoner Mar 29, 2021
fa89d03
remove extraneous cStringIO import
danstoner Mar 29, 2021
f79d0bb
add code coverage config file for py3
danstoner Mar 29, 2021
3b9db45
use proper pyproj Transformer pattern
danstoner Mar 30, 2021
5d0927e
use BytesIO to construct a file-like object properly
danstoner Mar 30, 2021
0d18002
Revert "use proper pyproj Transformer pattern"
danstoner Mar 30, 2021
7f31f84
add how to view code coverage to tests README
danstoner Mar 30, 2021
9db2054
use print function from __future__
danstoner Mar 30, 2021
00bded6
add sample code coverage report run in python3
danstoner Mar 30, 2021
f2e2eb7
print is a function in py3
danstoner Mar 30, 2021
d718d1e
Merge branch 'convert_python_3' of github.com:iDigBio/idb-backend int…
danstoner Apr 2, 2021
7f68bd4
remove un-used readline function
danstoner Apr 2, 2021
e00e93d
add stub tests for dwca.py
danstoner Apr 2, 2021
875bd68
move lookups into functions to make testable
danstoner Apr 2, 2021
03538ef
put back linesTerminatedBy and make testable
danstoner Apr 2, 2021
c340bff
Correcting minor typos.
nrejac Apr 2, 2021
6c1f3b7
move lookups into functions to make dwca testable (#149)
danstoner Apr 2, 2021
b07ca8f
add tests for getting unescaped "By" symbols (#150)
danstoner Apr 5, 2021
1d92c5b
un-escape the "By" fields using python3-compatible method
danstoner Apr 5, 2021
2286c6a
provide iterator methods so we can wrap unicodecsv
danstoner Apr 6, 2021
a90f2d2
use supported iterator pattern
danstoner Apr 6, 2021
9d3e185
use print function
danstoner Apr 6, 2021
641d4bc
in python3 dict.keys() replaces dict.viewkeys()
danstoner Apr 6, 2021
3a9dbb0
Rename variable for clarity.
nrejac Apr 6, 2021
b748a78
fix linter issue (should not be spaces between decorator and function…
danstoner Apr 6, 2021
3faade3
replace three identical functions with one
danstoner Apr 6, 2021
5fa653d
Merge branch 'convert_python_3' of github.com:iDigBio/idb-backend int…
danstoner Apr 6, 2021
d33f3f4
Revert "replace three identical functions with one"
danstoner Apr 6, 2021
41895ee
add help for "idb datatables" (#155)
danstoner Apr 9, 2021
69cc15e
comment and whitespace cleanup (linting)
danstoner Apr 9, 2021
4b2412e
allow library to open file by passing the filename
danstoner Apr 9, 2021
1396098
urlparse library renamed to urllib.parse in python3
danstoner Apr 11, 2021
e1352af
whitespace and garbage comment cleanup
danstoner Apr 11, 2021
744e54b
declare string for regex as raw string to allow backslash
danstoner Apr 11, 2021
5ece3db
make comment clearer to read
danstoner Apr 11, 2021
ce129c8
remove TODO we do not really need to do
danstoner Apr 11, 2021
a6d1c67
use raw string for regex with backslash escapes
danstoner Apr 11, 2021
392255a
add more virtualenv dirnames to gitignore
danstoner Apr 11, 2021
a3866de
fix W0612 unused-variable linting
danstoner Apr 11, 2021
1125735
Revert "fix W0612 unused-variable linting"
danstoner Apr 11, 2021
f405a84
add four more etags to derivatives blacklist (#165)
danstoner Apr 12, 2021
0184486
Minor spelling correction.
nrejac Apr 19, 2021
c2b4b43
Address issue #123, now development mode provides information when st…
nrejac Apr 19, 2021
6823578
Merge pull request #168 from iDigBio/add_console_output_for_data_api
nrejac Apr 20, 2021
9219d2f
Adding comment to conversions code to show where flag is set.
nrejac May 6, 2021
3e74562
Adding comment to conversions code to show where flag is set.
nrejac May 6, 2021
7c0ccc7
Adding comment to conversions code to show where flag is set.
nrejac May 6, 2021
c3da5d6
Add docstring for idb.helpers.conversion.checkBounds
nrejac May 6, 2021
710c98e
Add unit test for idb.helpers.conversions.checkBounds.
nrejac May 6, 2021
94d8211
fix use of dict.keys() which has different behavior in py3
danstoner Jun 18, 2021
3ed14f6
Fixing W1651 deprecated-itertools-function: itertools.imap is replace…
nrejac Jun 25, 2021
6907eec
Addressing W1620: Calling a dict.iter*() method (dict-iter-method), r…
nrejac Jun 25, 2021
1240fbf
Addressing W1633: round built-in referenced (round-builtin). The roun…
nrejac Jun 25, 2021
2acb2d5
Change ignore statement since we're using pylint, not flake or other …
nrejac Jun 25, 2021
f945f7c
Revert "Change ignore statement since we're using pylint, not flake o…
nrejac Jun 25, 2021
4053998
Revert "Addressing W1633: round built-in referenced (round-builtin). …
nrejac Jun 25, 2021
4a4f8e9
add note about ssh port forwarding to access Elasticsearch
danstoner Aug 4, 2021
029b585
update README with howto get idb binaries in path
danstoner Aug 17, 2021
c55aabf
add note - try to run ES in docker
danstoner Nov 24, 2021
f87db0d
remove link to vertnet since we no longer have access
danstoner Dec 17, 2021
ca9ca13
add more media error statuses
danstoner Feb 13, 2022
4d9d5c7
change redmine link in Ingestion report to new Phase 3 subsection (#202)
danstoner Jan 20, 2022
253e9da
reduce derivatives processing count to save memory (#201)
danstoner Jan 14, 2022
c278820
add new term namespaces (#199)
danstoner Jan 10, 2022
86df49b
ALA new namespaces (#198)
danstoner Jan 10, 2022
139a1f5
support https symbiota terms urls in meta.xml (#196)
danstoner Nov 16, 2021
e86a6f9
log errors during bulk indexing (#195)
danstoner Nov 13, 2021
fb1bcaa
remove lame comment
danstoner Nov 13, 2021
4708e23
Adjust settings for better bulk indexing (#190)
danstoner Oct 15, 2021
62fd968
WIP accommodate changes to DwC standard - basisOfRecord (#188)
danstoner Sep 19, 2021
eec97ca
add more etags to blacklist (#186)
danstoner Aug 10, 2021
a7a7974
[skip travis-ci] re-enable the push of stats into elastic by default
roncanepa Jun 22, 2021
db959a5
change recordset stats aggregation job to use custom config file and …
roncanepa Jun 22, 2021
8201d57
add "chrono:ChronometricAge" to list of un-indexable objects (#175)
danstoner May 23, 2021
e5963de
truncate problematic objects containing dots in fieldnames (#173)
danstoner May 7, 2021
01e3e68
add new ExtendedMeasurementOrFact extension (#167)
danstoner Apr 20, 2021
27961f6
add help for "idb datatables" (#155)
danstoner Apr 9, 2021
aebcf24
fixup doc sentence
danstoner Feb 27, 2022
e7591f9
cherry pickin from python2 main
danstoner Feb 27, 2022
f9f3c9c
add "mappings" command to idb index to only put mappings (#211)
danstoner Mar 10, 2022
e98a3ce
cleanup tab in setup.py
danstoner Mar 23, 2022
484f67d
suggest INFO for celery logging level
danstoner Mar 23, 2022
58c8121
add comment about IPT guids and regex warning
danstoner Mar 24, 2022
bdb113d
add linter warning
danstoner Mar 24, 2022
b542740
add pylint notes
danstoner Mar 24, 2022
8b191d7
fix pytest and pip package builds, pin versions
danstoner Feb 7, 2023
19b9cc9
remove commented out section
danstoner Feb 8, 2023
3aea9fe
dq flags now only get assigned to `records`
danstoner Feb 8, 2023
18bcd02
non-records types *do* get dqs and flags fields
danstoner Feb 10, 2023
57977b6
use postgres version 11 when testing with docker
danstoner Feb 10, 2023
fac0b6b
pin very specific version of fiona for compatibility with older click
danstoner Mar 1, 2023
43c5ab0
bump python3 version
danstoner Mar 1, 2023
d3994af
bump python3 to 3.8.10 in Dockerfile
danstoner Mar 1, 2023
7ea81bd
clarify comment
danstoner Mar 28, 2023
f901b0a
update local postgres test db version to 14
danstoner Mar 28, 2023
4242d2f
use newer Pillow to remove deprecation warning
danstoner Mar 28, 2023
4983957
attempt to fix Travis build issue
danstoner Mar 28, 2023
4408cbd
eliminate "greenlet has the wrong size" error during docker build
danstoner Mar 28, 2023
c695c34
update pip in Dockerfile build
danstoner Mar 28, 2023
3898838
bump gevent to fix pgpool hang
danstoner Mar 28, 2023
baa50f6
add travis_wait to prevent pipeline timeouts
danstoner Mar 28, 2023
0097eef
bump version to try to fix pgpool hang in Travis
danstoner Mar 28, 2023
bc7d84b
change gevent and greenlet version pins
danstoner Mar 28, 2023
4b87bd8
bump postgres version in travis pipeline
danstoner Mar 28, 2023
94fd589
use addon packages, port, and pguser as recommended in docs
danstoner Mar 28, 2023
27c1e40
change to newer dist
danstoner Mar 28, 2023
f60397c
try to install pg from official repos
danstoner Mar 28, 2023
cff94cb
try pg 11 instead
danstoner Mar 28, 2023
64d9a07
try pg 12 instead
danstoner Mar 29, 2023
85f592e
try jammy to get access to pg 14, move envs
danstoner Mar 29, 2023
55207f6
back to focal and pg 12
danstoner Mar 29, 2023
af2b3ea
add output to see where jobs are aborting
danstoner Mar 29, 2023
c2e36c3
reduce output to see if can avoid travis terminations
danstoner Mar 29, 2023
ec6cacf
remove travis_wait and use "travis" for pg connection
danstoner Mar 29, 2023
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
18 changes: 18 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This config file is used by coverage.py (and supposedly pytest-cov, although it does not seem to).

# The protip for generating a coverage report on idb-backend is to
# change into the top level of idb-backend and then run:
#
# $ coverage run -m pytest
#
# which will use this config file to access the sources listed below.
#
# To view the coverage report, run:
#
# $ coverage report

[run]
source =
./idb
./idigbio_ingestion
./idigbio_workers
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ venv/
ENV/
.venv/
.virtualenv/
.venv*/

# Spyder project settings
.spyderproject
Expand Down
21 changes: 14 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
sudo: required
dist: xenial
dist: focal
language: python
python: 2.7
python: 3.8.10
services:
- docker
- postgresql
addons:
postgresql: "9.5"
postgresql: "12"
apt:
packages:
- postgresql-12
- postgresql-client-12

git:
depth: 1

install:
- docker build -t $BUILDING .
- psql -U postgres -c 'create database test_idigbio;'
- psql -U postgres -c "DROP SCHEMA public CASCADE;" test_idigbio
- echo "docker build complete!"
- psql -U travis -c 'create database test_idigbio;'
- psql -U travis -c "DROP SCHEMA public CASCADE;" test_idigbio
- docker run -d --net host --name minio-test -e "MINIO_ACCESS_KEY=${ACCESS_KEY}" -e "MINIO_SECRET_KEY=${SECRET_KEY=}" minio/minio:RELEASE.2017-07-24T18-27-35Z server /export

script:
Expand All @@ -22,7 +27,7 @@ script:
-e "IDB_STORAGE_SECRET_KEY=${SECRET_KEY}"
-e "IDB_STORAGE_HOST=localhost:9000"
$BUILDING
pytest -p no:cacheprovider --pguser=postgres --pgpass="" tests/idb
pytest -p no:cacheprovider --pguser=travis --pgpass="" tests/idb

after_success:
# upload new docker images
Expand All @@ -42,6 +47,8 @@ env:
- BUILDING=$DOCKER_IMAGE:$TRAVIS_COMMIT
- ACCESS_KEY="testAccessKey"
- SECRET_KEY="testSecretKey"
- PGPORT=5433
- PGUSER=travis
notifications:
slack:
secure: "GVJcqmhKww+74MaAKiSPIf2oPxEFp0PoYHzdzL0xw5xd62OiJkrcdzOsiZ5DQxLlgU+MgWrxcxJmunMXOUvR7gt1V1WjuvYsmJ6+bC4/AU81Qr0z5BDANZRX7O8yA/WLvPyE5hsJQWAyBL0NFvkKbxzw/qKlaaoh+uUXI2FLA+LMq6kuW1BYyQuFsoX/14842ppRETrxK5uVAft7c+Egh68Tet5xO5lry3bBFZ0F75Jg5nuzgAgq3OcOe8Luo8FuekX75tBjT0hBNSM+Kn9LOPx25O6tRfivCJn1quOPNSNhet8zbeYecnSevW49VLtWi34fLX6rIsPcvGZg1Z5q1MjvxqDtuIEnhLBeR/8+hK+dLu6MP0YGcG4jBELEH13WlkmJJcH1X+DmRLK1tkgwWhJlW1RJ/QHPoqsMKMNFxS4aDenFGiYXSvv7skX8pr+i2QW1j55V6AU55OCvhsrgyHwFXlA+1ItU5geCVvmLscg8RXF7HuTrZrN/UxLjDVPAjY4rHS2ccZx1g3vo+K0OWafKk6yOi9J7rfwT+OGCMGv3Q57i1ShDIHvmfzfJmsjhtRCvKowwUrw2/Udean/ncdcRLvTTv0Xn+ioxnWAyvWo7UMdXj7YeHvp4bT9pY2eSjfHjB6Fe7S3vWC5zzLc0BDYouxkysv+j0EvP1vx84t4="
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM python:2.7
RUN apt-get update && apt-get install -y --no-install-recommends \
FROM python:3.8.10
# python:3.6 and later are based on "Debian GNU/Linux"
RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends \
gfortran \
libatlas-base-dev \
ffmpeg \
Expand All @@ -12,9 +13,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# fonts-dejavu-core \
# libxml2 \
# libxslt1-dev \
&& rm -rf /var/lib/apt/lists/*
> /dev/null && rm -rf /var/lib/apt/lists/*

COPY . /opt/idb-backend/
WORKDIR /opt/idb-backend/
RUN pip --no-cache-dir install -e .[test]
# RUN python3 -m virtualenv venv
RUN pip install -q --upgrade pip
RUN pip -q --no-cache-dir install -e .[test]
USER www-data
138 changes: 40 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ iDigBio server and backend code for data ingestion and data API.

### System Dependencies

Currently this project only works in python2.7 and is not compatible with Python 3.

The following library packages will need to be installed to run the api:

In Ubuntu 16.04:

apt-get install python2.7-dev libblas-dev liblapack-dev \
libatlas-base-dev gfortran libgdal-dev libpq-dev libgeos-c1v5 \
libsystemd-dev
#### Python 3 instructions:

In Ubuntu 18.04:

apt install python-dev libblas-dev liblapack-dev \
apt install python3-dev python3-all-dev libblas-dev liblapack-dev \
libatlas-base-dev gfortran libgdal-dev libpq-dev libgeos-c1v5 \
libsystemd-dev

For Ingestion and Development, the following are also needed:

In Ubuntu 16.04, 18.04:
In 18.04:

apt install libxml2 libxslt1-dev ffmpeg fonts-dejavu-core libfreetype6-dev python-systemd

apt-get install libxml2 libxslt1-dev ffmpeg fonts-dejavu-core libfreetype6-dev python-systemd
#### Python 2.7 instructions:

This version of idb-backend will not work under Python 2.


### Package installation
Expand Down Expand Up @@ -70,6 +66,16 @@ no need to set the `PYTHONPATH`.
In any invocation an `idigbio.json` must be present in either `$PWD`,
`$HOME`, or `/etc/idigbio`.

For convenience we can create links to the virtual environment entrypoints in `/usr/local/bin/` so we do not need to activate the virtual environment explicitly or use the full path.

```
$ sudo ln -s /home/idigbio-ingestion/idb-backend/venv/bin/idb /usr/local/bin/idb
$ ls -la /usr/local/bin/idb
lrwxrwxrwx 1 root root 48 Aug 16 20:23 /usr/local/bin/idb -> /home/idigbio-ingestion/idb-backend/venv/bin/idb
$ sudo ln -s /home/idigbio-ingestion/idb-backend/venv/bin/idigbio-ingestion /usr/local/bin/idigbio-ingestion
$ ls -la /usr/local/bin/idigbio-ingestion
lrwxrwxrwx 1 root root 62 Aug 16 20:24 /usr/local/bin/idigbio-ingestion -> /home/idigbio-ingestion/idb-backend/venv/bin/idigbio-ingestion
```
### Data API

This serves the `api.idigbio.org` interface
Expand All @@ -82,7 +88,7 @@ This package can also be run as a [celery worker]; this is used by the
data api that launches some tasks (most notably download building) via
celery to a background worker.

celery worker --app=idigbio_workers -l WARNING
celery worker --app=idigbio_workers -l INFO

[celery worker]: http://docs.celeryproject.org/en/latest/userguide/workers.html

Expand All @@ -91,111 +97,47 @@ celery to a background worker.
You probably want to run in a virtual environment. You may wish to disable the pip cache
to verify package builds are working properly.


### Python 3

```bash
$ virtualenv -p python2.7 .venv

$ python --version
Python 2.7.17

$ python3 -m virtualenv -p python3 .venv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/venvtest/.venv/bin/python3
Also creating executable in /tmp/venvtest/.venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.

$ source .venv/bin/activate

$ python --version
Python 2.7.17
Python 3.6.9

$ pip --no-cache-dir install -e .

$ pip --no-cache-dir install -r requirements.txt
```

It is possible in the future that this project will be runnable using "Open in container" features of Microsoft Visual Studio Code (aka vscode or just `code`).
### Python 2 (obsolete)

### Testing Dependencies
This project is no longer compatible with Python 2.

Some idb-backend tests depend on external resources, such as a database or Elasticsearch.

A local postgresql DB named `test_idigbio` with user/pass `test` / `test` must exist for many of the tests to run. Note: The data in the DB will be destroyed during the testing.
### Develop in Container

Database tests will be SKIPPED if the database is not available.
It is possible in the future that this project will be runnable using "Open in container" features of Microsoft Visual Studio Code (aka vscode or just `code`).

Tests that depend on Elasticsearch will FAIL if the computer running the tests cannot reach the Elasticsearch cluster (fail very slowly in fact), or if there is some other failure.

### Running tests
### Running the Test Suite

The test suite can be run by executing `py.test` (or `pytest`).

However due to the dependencies mentioned above, you may wish to run the database in docker each time. The sleep is needed to allow postgres time to start accepting connections.

docker run --rm --name postgres_test_idigbio --network host \
-e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test_idigbio \
-d postgres:9.5 && \
sleep 5; \
py.test ; \
docker stop postgres_test_idigbio


To exclude a single set of tests that are failing (or Seg Faulting!), add the `--deselect` option to the pytest command:
See the [README.md in the `tests` subdirectory](tests/README.md) for more information.

py.test --deselect=tests/idigbio_ingestion/mediaing/test_derivatives.py
There are a number of important dependencies noted there.

To find out why tests are being Skipped, add the `-rxs` options.

A "what the heck is going on with the tests and skip the one that is Seg Faulting" example command:

docker run --rm --name postgres_test_idigbio --network host \
-e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test_idigbio \
-d postgres:9.5 && \
sleep 5; \
py.test -rxs --deselect=tests/idigbio_ingestion/mediaing/test_derivatives.py ; \
docker stop postgres_test_idigbio

### Create a local postgres DB

The recommended approach is to run postgres via docker (see above).

If you have a full installation of postgres running locally, the db can be manually created with:

createuser -l -e test -P
createdb -l 'en_US.UTF-8' -E UTF8 -O test -e test_idigbio;

# The schema obj is still owned by the user of the above
# statement, not the owner 'test'. Drop it so it will be recreated
# by the script appropriately
psql -c "DROP SCHEMA public CASCADE;" test_idigbio


### Schema

The live production db schema is copied into `tests/data/schema.sql` by periodically running this command:

pg_dump --host c18node8.acis.ufl.edu --username idigbio \
--format plain --schema-only --schema=public \
--clean --if-exists \
--no-owner --no-privileges --no-tablespaces --no-unlogged-table-data \
--file tests/data/schema.sql \
idb_api_prod

Except not yet because there are lots of differences between the existing file and one created by running that command (due to fixes for https://wiki.postgresql.org/wiki/A_Guide_to_CVE-2018-1058:_Protect_Your_Search_Path).


### Data

A trimmed down set of data has been manually curated to support the test suite. It is provided in `tests/data/testdata.sql`

The full dump / original was created with something like:

pg_dump --port 5432 --host c18node8.acis.ufl.edu --username idigbio \
--format plain --data-only --encoding UTF8 \
--inserts --column-inserts --no-privileges --no-tablespaces \
--verbose --no-unlogged-table-data \
--exclude-table-data=ceph_server_files \
--file tests/data/testdata.sql idb_api_prod

Such a dump is huge and un-usable and un-editable by normal means. It is not clear how the dump was transformed / curated into its current state.

If running the dump again, consider adding multiple `--exclude-table-data=TABLE` for some of the bigger tables that are not materially relevant to test suite such as:

```plaintext
annotations
data
corrections
ceph_server_files
```

We likely need to find a new way to refresh the test dataset.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# deprecated for both naming and the call. see: idb-recordset-stats--aggregator.*

[Unit]
Description="Runs `idb api-stats`"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# deprecated for both naming and the call. see: idb-recordset-stats--aggregator.*

[Unit]
Description="Daily timer for idb api-stats"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# deprecated for both naming and the call. see: idb-interaction-telemetry-aggregator.*

[Unit]
Description="Runs `idb collect-stats`"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# deprecated for both naming and the call. see: idb-interaction-telemetry-aggregator.*

[Unit]
Description="daily timer for idb collect-stats"

Expand Down
12 changes: 12 additions & 0 deletions etc/systemd/system/idb-recordset-stats-aggregator.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://redmine.idigbio.org/projects/infrastructure/wiki/Portal_and_api_stats_overview

[Unit]
Description="Runs `idb api-stats` (recordset stats aggregator) via non-root user and virtualenv"

[Service]
Type=oneshot
User=stats
Environment=LANG=en_US.UTF-8

# the virtualenv is "baked in" and does not need to be activated first
ExecStart=/home/stats/.virtualenvs/idb-backend/bin/python /home/stats/.virtualenvs/idb-backend/bin/idb --journal -vv --config /etc/idigbio/idigbio-recordset-stats-aggregator-overrides.json api-stats
4 changes: 2 additions & 2 deletions etc/systemd/system/idigbio-ingestion-derivatives.timer
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Description="Timer for idigbio-ingestion derivatives"

[Timer]
OnBootSec=13min
OnUnitInactiveSec=10min
RandomizedDelaySec=4m
OnUnitInactiveSec=1min
RandomizedDelaySec=15

[Install]
WantedBy=timers.target
3 changes: 2 additions & 1 deletion idb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__ = "3.0.7"
# This sets the version for the generated idb-backend PyPi package also.
__version__ = "4.0.0"
Loading