Skip to content
Draft
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
43 changes: 6 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
.DS_Store
node_modules
/dist
migrations

# Python specific
__pycache__/
*.py[cod]

# Sequence Files
temp/
temp/*
/temp/*
b000027.txt

# local env files
.env.local
*.env.*.local
*.env

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*~
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.venv


*.log
.env
.pytest_cache
.ruff_cache
__pycache__
venv
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
247 changes: 50 additions & 197 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,201 +1,54 @@
# Numberscope - backscope
Numberscope - backscope
=======================

Copyright 2020-2022 Regents of the University of Colorado.

This project is licensed under the
[MIT License](https://opensource.org/licenses/MIT). See the text of the MIT
License in LICENSE.md.

## What is backscope?

backscope is [Numberscope's](https://numberscope.colorado.edu) back end. It is
responsible for getting sequences and other data from the [On-Line Encyclopedia
of Integer Sequences](https://oeis.org).

## Set up backscope

All of these instructions assume you have already cloned the backscope
repository from `https://github.com/numberscope/backscope` and are in
the top-level directory of your clone (the directory that contains this
`README.md` file).

### Install Python

You need a version of Python at least equal to 3.5. (If you don't have
Python, install the latest stable version.) By installing a version of
Python greater than or equal to 3.5, you should get the package
installer for Python (`pip`) and a working `venv` module for creating a
virtual environment.

To check to see your Python version, issue the following command:

```shell
python --version
```

The output should be something like "Python 3.10.8". If you see a message about
not being able to find Python, or you don't see any output, you need to
troubleshoot your Python installation.

Depending on how you installed Python, the executable might be named `python3`.
In that case, issue the following command:

```shell
python3 --version
```

In all the remaining commands, substitute either `python` or `python3` for
`[PYEXEC]` depending on which of the above worked.

To check to see if you have a working `venv` module, issue the following
command:

```shell
[PYEXEC] -m venv -h
```

You should see help for the `venv` module.

Note that since you will (likely) be compiling the cypari Python package, you
will (likely) need a _full_ Python3 installation, including the
"development header files." To check if these files are installed, you can
execute the following (very long) command:

```shell
[PYEXEC] -c "from distutils import sysconfig as s; from os.path import isfile; print(isfile(s.get_config_vars()['INCLUDEPY']+'/Python.h') and 'OK')"
```

If this command displays anything other than `OK` (such as `False` or an error
message) then your distribution is lacking these header files. You likely
will need to install the "Python development" package for your operating
system (the details of doing so are beyond the scope of these instructions).

### Other prerequisites

For a successfull installation of backscope, you will (likely) need a
_full_ Pari/GP installation already present on your computer, including the
documentation files. To test if the installation is present, try
executing:

```shell
gphelp -detex factorial
```

You should see a description of Pari/GP's factorial function. If not, you
may need to install Pari/GP and/or additional packages related to it,
depending on your operating system.

### Create a virtual environment and install dependencies

1. Create your virtual environment and activate it:

```bash
[PYEXEC] -m venv .venv # create a new virtual env called .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install --force cypari2
```

All remaining instructions assume that you have this virtual environment
activated. So if, for example, you stop and log out and come back later
and pick up the process, make sure to re-activate the virtual environment
by re-issuing the `source .venv/bin/activate` command in the top-level
directory of your backscope clone. Note also that once the virtual
environment is activated, the `python` command will invoke the proper
version of `python`, so you no longer need to worry about whether you
need to call `python3` or `python`. Hence, the remaining instructions
all just use `python`.

2. Install and configure PostgreSQL and create an empty database:

Specific instructions for PostgreSQL installation are unfortunately beyond
the current scope of this README, as they depend greatly on the particulars
of your operating system. You need to end up with a running
Postgres server on your machine that will accept localhost connections.

Specifically, once you are set up, it should be possible to use the command
`psql` to connect to a Postgres shell where you can create a database for
backscope. You should be able to use the `-U` flag to specify a user who
has the correct permissions to access the Postgres shell and create a database.

```bash
psql -U <username for psql>
<username>=# CREATE DATABASE <database name>;
CREATE DATABASE
<username>=# \q
```

3. Set up your environment and initialize the database:

This project uses python-dotenv. In order to detect your database
username / password, you must create a file called `.env` in the root
of your directory containing:
```
export APP_ENVIRONMENT="development"
export DATABASE_URI="postgresql://localhost/<database name>"
export SECRET_KEY="Uneccessary for development"
export POSTGRES_USER="<username for psql>"
export POSTGRES_DB="<database name>"
export POSTGRES_PASSWORD="<password for psql>"
```
You can see other configuration options inside
[the config file](./flaskr/config.py).

4. Configure the database:

```bash
python manage.py db init # initializes tables inside database
```

The previous command will issue a message about editing
`alembic.ini`, which is safe to ignore. The default works fine.

```bash
python manage.py db migrate # migrate data models
python manage.py db upgrade # upgrade changes to database
psql -U <username for psql> -d <database name>
db=# \d
Schema | Name | Type | Owner
--------+-----------------+----------+--------------------
public | alembic_version | table | <username for psql>
public | sequences | table | <username for psql>
public | user | table | <username for psql>
public | user_id_seq | sequence | <username for psql>
db=# \q
```

## Run backscope

Option 1:
```bash
python manage.py runserver
```

Option 2:
```bash
export FLASK_APP=flaskr
flask run
```

This should print a series of messages. One of these
messages should be the URL the server is running on, typically
`http://127.0.0.1:5000/`. To test that the server is working correctly,
try visiting `<URL>/api/get_oeis_values/A000030/50` (substitute in the server
URL for `<URL>`). This should display the first digits of the numbers from
0 through 49.

## More information

### General

- [API Endpoints](./doc/api_endpoints.md)
- [Directory Descriptions](./doc/directory_descriptions.md)
- [Resetting the Database](./doc/resetting-the-database.md)

### Administering the production backscope instance

- [Update Backscope](./doc/update-backscope.md)
- [Server Administration](./doc/server-administration.md)
- [Database Administration](./doc/database-administration.md)
- [server Directory README](./server/README.md)

[MIT License](https://opensource.org/licenses/MIT). See the text of the
MIT License in LICENSE.md.

What is backscope?
------------------

backscope is [Numberscope's](https://numberscope.colorado.edu) back end.
It is responsible for getting sequences and other data from the
[On-Line Encyclopedia of Integer Sequences](https://oeis.org).

Quick start
-----------

1. Clone this repo.
2. Install prerequisites: Git, Python 3, Python 3 dev package,
Python 3 package for creating virtual environments, full installation
of pari-gp (including all metadata files — you might need to install
a package like "libpari-dev"), GNU multi-precision arithmetic dev
package, a C compiler, and C build tools.
+ For detailed instructions on installing backscope on Ubuntu, see
[this doc](doc/install-ubuntu.md).
3. Create a virtual environment: `python -m venv venv`.
4. Activate the virtual environment: `source venv/bin/activate`.
5. Install deps: `pip install -r requirements.txt`.
6. Install and configure PostgreSQL and create an empty database.
+ For detailed instructions on installing and configuring PostgreSQL,
see [ths doc](doc/install-postgres.md).
7. Run backscope: `flask run`
+ For detailed instructions on running backscope, see
[this doc](doc/running-backscope.md).

More info
---------

If you plan on developing backscope, you might find one of these useful:

- [How to format, lint, and test your code](doc/format-lint-test.md)
- [How to install a pre-commit hook](doc/pre-commit-hook.md)
- [How to do database migrations](doc/db-migrations.md)
- [How to reset your database](doc/db-reset.md)
- [Understanding our requirements files](doc/requirements.md)

If you are a maintainer, you might find one of these useful:

- [How to update frontscope on the CU server](doc/server-update-frontscope.md)
- [How to update backscope on the CU server](doc/server-update-backscope.md)
- [How to administer our server](doc/server-admin.md)
- [How to administer our database](doc/db-admin.md)
52 changes: 52 additions & 0 deletions api.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
MY_FOO = None
HTTPSConnectionPool(host='oeis.orga000040', port=443): Max retries exceeded with url: /b000040.txt (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7ff91b15c730>: Failed to resolve 'oeis.orga000040' ([Errno -2] Name or service not known)"))
HTTPSConnectionPool(host='oeis.orga000041', port=443): Max retries exceeded with url: /b000041.txt (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7ff91b15ca90>: Failed to resolve 'oeis.orga000041' ([Errno -2] Name or service not known)"))
HTTPSConnectionPool(host='oeis.orga000041', port=443): Max retries exceeded with url: /b000041.txt (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7ff91b15d630>: Failed to resolve 'oeis.orga000041' ([Errno -2] Name or service not known)"))
attempting to connect to db
connected to db
attempting to connect to db
connected to db
MY_FOO = foo
HTTPSConnectionPool(host='oeis.orga000040', port=443): Max retries exceeded with url: /b000040.txt (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7efdf0dc86a0>: Failed to resolve 'oeis.orga000040' ([Errno -2] Name or service not known)"))
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
'NoneType' object has no attribute 'append'
attempting to connect to db
connected to db
attempting to connect to db
connected to db
metadata fetching for A000001 in progress
metadata fetching for A000001 in progress
metadata fetching for A000001 in progress
metadata fetching for A000001 in progress
attempting to connect to db
connected to db
attempting to connect to db
connected to db
metadata fetching for A000001 in progress
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
attempting to connect to db
connected to db
Loading