Skip to content

Commit

Permalink
remove some unneeded warnings filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
brondsem authored and Carlos Cruz committed Sep 9, 2024
1 parent 4b59755 commit 20006c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
9 changes: 1 addition & 8 deletions Allura/allura/command/reclone_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ def command(self):

def _setup(self):
'''Perform basic setup, suppressing superfluous warnings.'''
with warnings.catch_warnings():
try:
from sqlalchemy import exc
except ImportError:
pass
else:
warnings.simplefilter("ignore", category=exc.SAWarning)
self.basic_setup()
self.basic_setup()

def _load_objects(self):
'''Load objects to be operated on.'''
Expand Down
55 changes: 24 additions & 31 deletions Allura/allura/command/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,33 @@ class ScriptCommand(base.Command):
help='Drop to a debugger on error')

def command(self):
with warnings.catch_warnings():
try:
from sqlalchemy import exc
except ImportError:
pass
else:
warnings.simplefilter("ignore", category=exc.SAWarning)
self.basic_setup()
request = webob.Request.blank('--script--', environ={
'paste.registry': self.registry})
tg.request_local.context.request = request
if self.options.pdb:
base.log.info('Installing exception hook')
sys.excepthook = utils.postmortem_hook
filename = self.args[1]
with open(filename) as fp:
ns = dict(__name__='__main__')
sys.argv = self.args[1:]
code = compile(fp.read(), filename, 'exec')
self.basic_setup()
request = webob.Request.blank('--script--', environ={
'paste.registry': self.registry})
tg.request_local.context.request = request
if self.options.pdb:
base.log.info('Installing exception hook')
sys.excepthook = utils.postmortem_hook
filename = self.args[1]
with open(filename) as fp:
ns = dict(__name__='__main__')
sys.argv = self.args[1:]
code = compile(fp.read(), filename, 'exec')

if self.options.profile:
profile_output_file = self.options.profile_output or '%s.profile' % os.path.basename(filename)
if not os.access(os.path.dirname(profile_output_file), os.W_OK):
raise OSError(f'no write permission to dir for {profile_output_file}. '
f'Specify a different path with --profile-output')
# https://stackoverflow.com/a/48622889
pr = cProfile.Profile()
pr.enable()
if self.options.profile:
profile_output_file = self.options.profile_output or '%s.profile' % os.path.basename(filename)
if not os.access(os.path.dirname(profile_output_file), os.W_OK):
raise OSError(f'no write permission to dir for {profile_output_file}. '
f'Specify a different path with --profile-output')
# https://stackoverflow.com/a/48622889
pr = cProfile.Profile()
pr.enable()

exec(code, ns) # noqa: S102
exec(code, ns) # noqa: S102

if self.options.profile:
pr.disable()
pr.dump_stats(profile_output_file)
if self.options.profile:
pr.disable()
pr.dump_stats(profile_output_file)


class SetToolAccessCommand(base.Command):
Expand Down
4 changes: 1 addition & 3 deletions Allura/allura/controllers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
from tg import request, response
from webob import exc as wexc
from paste.deploy.converters import asbool
with warnings.catch_warnings(): # ignore py2 CryptographyDeprecationWarning
warnings.filterwarnings('ignore')
from cryptography.hazmat.primitives.twofactor import InvalidToken
from cryptography.hazmat.primitives.twofactor import InvalidToken
from beaker.session import _session_id

import allura.tasks.repo_tasks
Expand Down
10 changes: 4 additions & 6 deletions Allura/allura/lib/multifactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
from tg import config
from tg import app_globals as g
from paste.deploy.converters import asint
with warnings.catch_warnings(): # ignore py2 CryptographyDeprecationWarning
warnings.filterwarnings('ignore')
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.twofactor import InvalidToken
from cryptography.hazmat.primitives.twofactor.totp import TOTP
from cryptography.hazmat.primitives.hashes import SHA1
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.twofactor import InvalidToken
from cryptography.hazmat.primitives.twofactor.totp import TOTP
from cryptography.hazmat.primitives.hashes import SHA1
import qrcode
from ming.odm import session

Expand Down

0 comments on commit 20006c4

Please sign in to comment.