#93 Various fixes related to Python3 and requirements
Closed 2 years ago by kparal. Opened 2 years ago by kparal.

file modified
+2 -4
@@ -1,11 +1,11 @@ 

  # This is required for running on EL6

  import __main__

  __main__.__requires__ = ['SQLAlchemy >= 0.7', 'Flask >= 0.9', 'jinja2 >= 2.6']

- import pkg_resources

  

  import sys

  import os

  from optparse import OptionParser

+ import secrets

  

  from blockerbugs import db, app

  from blockerbugs.models.milestone import Milestone
@@ -17,7 +17,6 @@ 

  from alembic.config import Config

  from alembic import command as al_command

  from alembic.migration import MigrationContext

- from webassets.script import CommandLineEnvironment

  

  

  def get_alembic_config():
@@ -106,7 +105,7 @@ 

          print("configuration file %s already exists, exiting" % config_filename)

          sys.exit(0)

  

-     secret_key = os.urandom(24).encode('string_escape')

+     secret_key = secrets.token_hex()

  

      config_file = open(config_filename, 'w')

      config_file.write('SECRET_KEY = \'%s\'\n' % secret_key)
@@ -225,4 +224,3 @@ 

      exit = main()

      if exit:

          sys.exit(exit)

- 

@@ -25,7 +25,6 @@ 

  from flask import flash, request, redirect, url_for

  from flask_admin.babel import gettext

  import flask_admin

- import wtforms

  from blockerbugs import app, db

  from blockerbugs.models.build import Build

  from blockerbugs.models.release import Release
@@ -143,5 +142,3 @@ 

  admin.add_view(ReleaseView(Release, db.session))

  admin.add_view(UserInfoView(UserInfo, db.session))

  admin.add_view(BuildView(Build, db.session))

- 

- 

@@ -26,8 +26,6 @@ 

  import wtforms

  from flask_admin import expose

  from flask_admin.babel import gettext

- from flask_admin.contrib.sqla.fields import QuerySelectMultipleField

- from flask_admin.form import Select2Widget

  

  from blockerbugs.controllers.admin.auth import FasAuthModelView

  from blockerbugs.models.build import Build

@@ -22,19 +22,15 @@ 

  #   Ilgiz Islamgulov <ilgizisl@gmail.com>

  #

  

- import datetime

- 

  from flask import Blueprint, request

- from iso8601 import parse_date

  

  from blockerbugs import db

  from blockerbugs.models.milestone import Milestone

  from blockerbugs.models.update import Update

  from blockerbugs.models.release import Release

  from blockerbugs.models.bug import Bug

- from . import validators

  from . import errors

- from .utils import get_or_404, json_loads, JsonResponse, check_api_rights

+ from .utils import get_or_404, JsonResponse

  

  api_v0 = Blueprint('api', __name__, url_prefix='/api/v0')

  

@@ -70,8 +70,8 @@ 

          """

          Validation function that does not check required flag.

          """

-         raise NotImplemented('To use this class inherit from it '

-                              'and define _check_data method')

+         raise NotImplementedError('To use this class inherit from it '

+             'and define _check_data method')

  

  

  class NumericValidator(BaseValidator):
@@ -179,7 +179,7 @@ 

  class DateTimeValidator(BaseValidator):

      def _check_data(self):

          try:

-             val = parse_date(self.raw_data)

+             parse_date(self.raw_data)

          except ParseError:

              raise ValidationError('%s must be datetime in ISO 8601 format' % (self.name))

  

@@ -24,7 +24,7 @@ 

  from flask_wtf import Form

  from wtforms import TextField, SelectField, BooleanField, IntegerField

  from wtforms import TextAreaField, PasswordField, ValidationError

- from wtforms.validators import Required, Optional, Email

+ from wtforms.validators import Required, Email

  

  

  def one_proposal(form, field):

@@ -427,9 +427,9 @@ 

          app.logger.debug('bugid: %i' % bugform.bugid.data)

          app.logger.debug('bz_user: %s' % user_info.bz_user)

          app.logger.debug('milestone: %i' % bugform.milestone.data)

-         app.logger.debug('blocker: %s' % unicode(bugform.blocker.data))

-         app.logger.debug('freeze_exception: %s' % unicode(bugform.freeze_exception.data))

-         app.logger.debug('justification: %s' % unicode(bugform.justification.data))

+         app.logger.debug('blocker: %s' % bugform.blocker.data)

+         app.logger.debug('freeze_exception: %s' % bugform.freeze_exception.data)

+         app.logger.debug('justification: %s' % bugform.justification.data)

  

          selected_milestone = Milestone.query.filter_by(id=bugform.milestone.data).first()

          bugid = bugform.bugid.data
@@ -437,7 +437,7 @@ 

          trackers = {'blocker': selected_milestone.blocker_tracker,

                      'fe': selected_milestone.fe_tracker}

  

-         app.logger.debug('selected trackers: %s' % unicode(trackers))

+         app.logger.debug('selected trackers: %s' % trackers)

  

          # The form does basic datatype validation but we need to check for valid

          # data
@@ -474,7 +474,7 @@ 

                  bugform.bugid.errors = [e.msg]

                  app.logger.info('bug proposal form errors: %s' % e.msg)

          else:

-             app.logger.info('bug proposal form errors: %s' % unicode(bugform.errors))

+             app.logger.info('bug proposal form errors: %s' % bugform.errors)

  

      # this assumes that the current milestone is the release against which the

      # blocker is being proposed. It isn't an ideal assumption but it should hold

@@ -22,8 +22,6 @@ 

  #

  # Liberally borrows from the sample app in Flask-FAS maintained by Ian Weller

  

- from functools import wraps

- 

  from flask import redirect, url_for, request, g, abort

  

  from blockerbugs import app, fas

file modified
+3 -1
@@ -24,6 +24,9 @@ 

  from blockerbugs import db

  import datetime

  

+ # unused imports, but required by dynamic relationships:

+ from blockerbugs.models.milestone import Milestone

+ 

  

  class Bug(db.Model):

      id = db.Column(db.Integer, primary_key=True)
@@ -115,4 +118,3 @@ 

          newbug = Bug(buginfo['bug_id'], '', '', '','', release, buginfo['active'], False, '')

          newbug.update(buginfo, tracker_type, release)

          return newbug

- 

@@ -22,8 +22,9 @@ 

  

  

  from blockerbugs import db

+ # unused imports, but required by dynamic relationships:

  from blockerbugs.models.criterion import Criterion

- 

+ from blockerbugs.models.release import Release

  

  class Milestone(db.Model):

      id = db.Column(db.Integer, primary_key=True)

file modified
+6 -1
@@ -23,6 +23,12 @@ 

  from blockerbugs import db

  from blockerbugs.models.bug import Bug

  

+ # unused imports, but required by dynamic relationships:

+ from blockerbugs.models.bug import Bug

+ from blockerbugs.models.release import Release

+ from blockerbugs.models.milestone import Milestone

+ 

+ 

  update_fixes = db.Table(

      'update_fixes',

      db.Column('bug_id', db.Integer, db.ForeignKey('bug.id')),
@@ -108,4 +114,3 @@ 

          newupdate = Update(updateinfo['title'], '', 0, '', [], release, None)

          newupdate.sync(updateinfo)

          return newupdate

- 

file modified
+1 -3
@@ -71,7 +71,7 @@ 

                      buginfo['needinfo'] = True

                      try:

                          needinfos.append(flag['requestee'])

-                     except KeyError as e:

+                     except KeyError:

                          pass

              buginfo['needinfo_requestee'] = ', '.join(needinfos)

  
@@ -194,5 +194,3 @@ 

              milestone.last_bug_sync = starttime

              self.db.session.add(milestone)

              self.db.session.commit()

- 

- 

file modified
+1 -1
@@ -92,7 +92,7 @@ 

  The ``SECRET_KEY`` is used to encrypt data in the HTTP session and must be

  regnerated. An easy way to do this is to use the output of the following command::

  

-   python -c "import os; print os.urandom(24).encode('string_escape')"

+   python -c 'import secrets; print(secrets.token_hex())'

  

  FAS and Login Related Settings

  ------------------------------

file modified
-1
@@ -11,7 +11,6 @@ 

  pytest>=2.3.5

  pytest-cov>=1.6

  python-bugzilla>=1.1.0

- wsgiref>=0.1.2

  kitchen>=1.1.1

  python-fedora>=0.5.5

  pycurl>=7.19.0

These are several commits, see the changes per commit.

@frantisekz Are we able to run on Python3 in production? These fixes assume running on Py3 (and I'm too lazy to create and test workarounds for Py2 - not to mention I might not be able to test Py2 anymore because most packages are now missing from Fedora).

4 new commits added

  • remove unneeded imports
  • fix errors under Python3
  • cli: fix secret key generation
  • requirements.txt: remove wsgiref
2 years ago

4 new commits added

  • remove unneeded imports
  • fix errors under Python3
  • cli: fix secret key generation
  • requirements.txt: remove wsgiref
2 years ago

4 new commits added

  • Imports improvements
  • fix errors under Python3
  • cli: fix secret key generation
  • requirements.txt: remove wsgiref
2 years ago

LGTM, we'll sort out deployment issues on production later.

OK, I'll merge this, and if we need some py2-compatible workarounds, I'll add them later.

Pull-Request has been closed by kparal

2 years ago