-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initiating work on strict typing, need sqlalchemy-stubs
attempting to use sqlalchemy stubs fleshed out mypy.ini - verified works with vscode; updated mypy improved support for mypy-sqlalchemy questionable_model_change fixed issues except python/mypy#4049 adding some mypy workarounds for mypy #4049 and #4291
- Loading branch information
Showing
1,112 changed files
with
28,711 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "sqlalchemy-stubs"] | ||
path = sqlalchemy-stubs | ||
url = https://github.com/JelleZijlstra/sqlalchemy-stubs.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,26 @@ | ||
"""Browse controllers.""" | ||
import re | ||
|
||
from typing import Dict, Optional, Tuple | ||
|
||
from flask import request | ||
from arxiv import status | ||
from typing import Tuple, Dict, Any, Optional | ||
from browse.services.document import metadata | ||
from browse.services.document.metadata import AbsNotFoundException,\ | ||
AbsVersionNotFoundException | ||
from browse.domain.identifier import IdentifierException | ||
from browse.services.database.models import get_institution | ||
from werkzeug.exceptions import InternalServerError | ||
from flask_api import status | ||
from browse.services.database import get_institution | ||
|
||
Response = Tuple[Dict[str, Any], int, Dict[str, Any]] | ||
|
||
InstitutionResp = Tuple[Dict[str, str], int] | ||
|
||
def get_abs_page(arxiv_id: str) -> Response: | ||
"""Get the data that constitutes an /abs page.""" | ||
response_data = {} # type: Dict[str, Any] | ||
|
||
try: | ||
abs_meta = metadata.get_abs(arxiv_id) | ||
response_data['abs_meta'] = abs_meta | ||
except AbsNotFoundException as e: | ||
return {'not_found': True, 'arxiv_id': arxiv_id}, \ | ||
status.HTTP_404_NOT_FOUND, {} | ||
except AbsVersionNotFoundException as e: | ||
arxiv_id_latest = re.sub(r'(v[\d]+)$', '', arxiv_id) | ||
return {'version_not_found': True, | ||
'arxiv_id': arxiv_id, | ||
'arxiv_id_latest': arxiv_id_latest},\ | ||
status.HTTP_404_NOT_FOUND, {} | ||
except IdentifierException as e: | ||
print(f'Got IdentifierException {e}') | ||
return {'arxiv_id': arxiv_id}, status.HTTP_404_NOT_FOUND, {} | ||
except IOError as e: | ||
# TODO: handle differently? | ||
raise InternalServerError( | ||
"There was a problem. If this problem " | ||
"persists, please contact [email protected]." | ||
) | ||
|
||
return response_data, status.HTTP_200_OK, {} | ||
|
||
|
||
def get_institution_from_request() -> Optional[str]: | ||
def get_institution_from_request() -> InstitutionResp: | ||
"""Get the institution name from the request context.""" | ||
institution_str = None | ||
try: | ||
institution_str = get_institution(request.remote_addr) | ||
institution_opt: Optional[str] = get_institution(request.remote_addr) | ||
response: InstitutionResp = ({ | ||
'institution': institution_opt | ||
}, status.HTTP_200_OK) if institution_opt is not None else ({ | ||
'explanation': 'Institution not found.' | ||
}, status.HTTP_400_BAD_REQUEST) | ||
return response | ||
|
||
except IOError: | ||
# TODO: log this | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
"""Application factory for browse service components.""" | ||
|
||
from flask import Flask | ||
from browse.services.database import models | ||
from browse import views | ||
from browse.services.database.models import dbx as db | ||
|
||
|
||
def create_web_app() -> Flask: | ||
def create_web_app(config_filename: str) -> Flask: | ||
"""Initialize an instance of the browse web application.""" | ||
from browse.views import blueprint | ||
|
||
app = Flask('browse', static_folder='static', template_folder='templates') | ||
app.config.from_pyfile('config.py') | ||
app: Flask = Flask('browse', static_folder='static', | ||
template_folder='templates') | ||
app.config.from_pyfile(config_filename) | ||
|
||
models.init_app(app) | ||
from browse.url_converter import ArXivConverter | ||
app.url_map.converters['arxiv'] = ArXivConverter | ||
|
||
# from browse.url_converter import ArXivConverter | ||
# app.url_map.converters['arxiv'] = ArXivConverter | ||
app.register_blueprint(views.blueprint) | ||
db.init_app(app) | ||
|
||
app.register_blueprint(blueprint) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,46 @@ | ||
"""Import db instance and define utility functions.""" | ||
|
||
import ipaddress | ||
from browse.services.database.models import db | ||
from browse.services.database.models import dbx | ||
from browse.services.database.models import MemberInstitution, \ | ||
MemberInstitutionIP | ||
from sqlalchemy.sql import func | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm.exc import NoResultFound | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
from typing import Optional | ||
|
||
# def get_institution(ip: str): | ||
# """Get institution label from IP address.""" | ||
# decimal_ip = int(ipaddress.ip_address(ip)) | ||
# try: | ||
# stmt = ( | ||
# db.session.query( | ||
# MemberInstitution.label, | ||
# func.sum(MemberInstitutionIP.exclude).label("exclusions") | ||
# ). | ||
# join(MemberInstitutionIP). | ||
# filter( | ||
# MemberInstitutionIP.start <= decimal_ip, | ||
# MemberInstitutionIP.end >= decimal_ip | ||
# ). | ||
# group_by(MemberInstitution.label). | ||
# subquery() | ||
# ) | ||
# | ||
# return ( | ||
# db.session.query(stmt.c.label). | ||
# filter(stmt.c.exclusions == 0).one().label | ||
# ) | ||
# except NoResultFound: | ||
# return None | ||
# except SQLAlchemyError as e: | ||
# raise IOError('Database error: %s' % e) from e | ||
# Temporary fix for https://github.com/python/mypy/issues/4049 : | ||
db: SQLAlchemy = dbx | ||
|
||
|
||
def get_institution(ip: str) -> Optional[str]: | ||
"""Get institution label from IP address.""" | ||
decimal_ip = int(ipaddress.ip_address(ip)) | ||
try: | ||
stmt = ( | ||
db.session.query( | ||
MemberInstitution.label, | ||
func.sum(MemberInstitutionIP.exclude).label("exclusions") | ||
). | ||
join(MemberInstitutionIP). | ||
filter( | ||
MemberInstitutionIP.start <= decimal_ip, | ||
MemberInstitutionIP.end >= decimal_ip | ||
). | ||
group_by(MemberInstitution.label). | ||
subquery() | ||
) | ||
|
||
institution: str = db.session.query(stmt.c.label) \ | ||
.filter(stmt.c.exclusions == 0).one().label | ||
|
||
return institution | ||
except NoResultFound: | ||
return None | ||
except SQLAlchemyError as e: | ||
raise IOError('Database error: %s' % e) from e | ||
|
||
|
||
__all__ = ["get_institution", "db"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sqlalchemy-stubs
added at
5e89b6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
------------------------------------------------------------------------------ | ||
\\ | ||
arXiv:acc-phys/9411001 | ||
From: Salman Habib <[email protected]> | ||
Date: Tue, 1 Nov 1994 18:57:48 GMT (199kb) | ||
|
||
Title: Symplectic Computation of Lyapunov Exponents | ||
Authors: Salman Habib and Robert D. Ryne | ||
Categories: acc-phys physics.acc-ph | ||
Comments: 12 pages, uuencoded PostScript (figures included) | ||
Report-no: LA-UR-94-3641 | ||
\\ | ||
A recently developed method for the calculation of Lyapunov exponents of | ||
dynamical systems is described. The method is applicable whenever the | ||
linearized dynamics is Hamiltonian. By utilizing the exponential representation | ||
of symplectic matrices, this approach avoids the renormalization and | ||
reorthogonalization procedures necessary in usual techniques. It is also easily | ||
extendible to damped systems. The method is illustrated by considering two | ||
examples of physical interest: a model system that describes the beam halo in | ||
charged particle beams and the driven van der Pol oscillator. | ||
\\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
------------------------------------------------------------------------------ | ||
\\ | ||
arXiv:acc-phys/9411002 | ||
From: Salman Habib <[email protected]> | ||
Date: Sat, 19 Nov 1994 21:03:56 GMT (12kb) | ||
|
||
Title: Order $\hbar$ Corrections to the Classical Dynamics of a Particle with | ||
Intrinsic Spin Moving in a Constant Magnetic Field | ||
Authors: Patrick L. Nash (University of Texas at San Antonio) | ||
Categories: acc-phys physics.acc-ph | ||
\\ | ||
$O(\hbar)$ effects that modify the classical orbit of a charged particle are | ||
described for the case of a classical spin-1/2 particle moving in a constant | ||
magnetic field, using a manifestly covariant formalism reported previously. It | ||
is found that the coupling between the momentum and spin gives rise to a shift | ||
in the cyclotron frequency, which is explicitly calculated. In addition the | ||
orbit is found to exhibit $O(\hbar)$ oscillations along the axis of the uniform | ||
static magnetic field whenever the gyromagnetic ratio $g$ of the particle is | ||
not 2. This oscillation is found to occur at a frequency $\propto$ $\frac{g}{2} | ||
- 1$, and is an observable source of electric dipole radiation. | ||
\\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
------------------------------------------------------------------------------ | ||
\\ | ||
arXiv:acc-phys/9411003 | ||
From: Peter V. Vorob'ev. <[email protected]> | ||
Date: Tue, 22 Nov 1994 12:45:16 GMT (69kb) | ||
|
||
Title: Candela Photo-Injector Experimental Results | ||
Authors: C. Travier, L. Boy, J.N. Cayla, B. Leblond, P. Georges, P. Thomas | ||
Categories: acc-phys physics.acc-ph | ||
Comments: 8 pages, 6 figures, LATEX | ||
Report-no: LAL/RT/94-15 | ||
\\ | ||
The CANDELA photo-injector is a two cell S-band photo-injector. The copper | ||
cathode is illuminated by a 500 fs Ti:sapphire laser. This paper presents | ||
energy spectrum measurements of the dark current and intense electron emission | ||
that occurs when the laser power density is very high. | ||
\\ |
Oops, something went wrong.