Skip to content

Commit

Permalink
Switch to absolute imports for Python3 compatability
Browse files Browse the repository at this point in the history
Part of google#412

Started by:
futurize -nw -f libfuturize.fixes.fix_absolute_import  .
And followed up by fixing a few local problems.
  • Loading branch information
jarondl committed Jan 28, 2019
1 parent 14ee635 commit 03374f0
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 96 deletions.
11 changes: 6 additions & 5 deletions extensions/googletransit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from agency import *
from fareattribute import *
from route import *
from setup_extension import *
from stop import *
from __future__ import absolute_import
from .agency import *
from .fareattribute import *
from .route import *
from .setup_extension import *
from .stop import *
4 changes: 3 additions & 1 deletion extensions/googletransit/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import extension_util
from __future__ import absolute_import

from . import extension_util
import transitfeed

class Agency(transitfeed.Agency):
Expand Down
3 changes: 2 additions & 1 deletion extensions/googletransit/extension_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pybcp47 import Bcp47LanguageParser
from __future__ import absolute_import
from .pybcp47 import Bcp47LanguageParser
from transitfeed import problems as problems_class
from transitfeed import util

Expand Down
3 changes: 2 additions & 1 deletion extensions/googletransit/pybcp47/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from bcp47languageparser import *
from __future__ import absolute_import
from .bcp47languageparser import *
3 changes: 2 additions & 1 deletion extensions/googletransit/pybcp47/testpybcp47.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

# Unit tests for the bcp47languageparser module.

from __future__ import absolute_import
import codecs
import os
import unittest

from bcp47languageparser import Bcp47LanguageParser
from .bcp47languageparser import Bcp47LanguageParser

class PyBcp47TestCase(unittest.TestCase):
bcp47parser = Bcp47LanguageParser()
Expand Down
9 changes: 5 additions & 4 deletions extensions/googletransit/setup_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import transitfeed

import agency
import fareattribute
import route
import stop
from . import agency
from . import fareattribute
from . import route
from . import stop

def GetGtfsFactory(factory = None):
if not factory:
Expand Down
43 changes: 22 additions & 21 deletions transitfeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,34 @@
TimeToSecondsSinceMidnight(): Convert HH:MM:SS into seconds since midnight.
FormatSecondsSinceMidnight(s): Formats number of seconds past midnight into a string
"""
from __future__ import absolute_import

# util needs to be imported before problems because otherwise the loading order
# of this module is Agency -> Problems -> Util -> Trip and trip tries to
# use problems.default_problem_reporter as a default argument (which fails
# because problems.py isn't fully loaded yet). Loading util first solves this as
# problems.py gets fully loaded right away.
# TODO: Solve this problem cleanly
from util import *
from agency import *
from fareattribute import *
from farerule import *
from frequency import *
from gtfsfactory import *
from gtfsfactoryuser import *
from gtfsobjectbase import *
from loader import *
from problems import *
from route import *
from schedule import *
from serviceperiod import *
from shape import *
from shapelib import *
from shapeloader import *
from shapepoint import *
from stop import *
from stoptime import *
from transfer import *
from trip import *
from .util import *
from .agency import *
from .fareattribute import *
from .farerule import *
from .frequency import *
from .gtfsfactory import *
from .gtfsfactoryuser import *
from .gtfsobjectbase import *
from .loader import *
from .problems import *
from .route import *
from .schedule import *
from .serviceperiod import *
from .shape import *
from .shapelib import *
from .shapeloader import *
from .shapepoint import *
from .stop import *
from .stoptime import *
from .transfer import *
from .trip import *

from transitfeed.version import __version__
7 changes: 4 additions & 3 deletions transitfeed/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from gtfsobjectbase import GtfsObjectBase
from problems import default_problem_reporter
import util
from __future__ import absolute_import
from .gtfsobjectbase import GtfsObjectBase
from .problems import default_problem_reporter
from . import util

class Agency(GtfsObjectBase):
"""Represents an agency in a schedule.
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/fareattribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from gtfsobjectbase import GtfsObjectBase
from problems import default_problem_reporter
import util
from __future__ import absolute_import
from .gtfsobjectbase import GtfsObjectBase
from .problems import default_problem_reporter
from . import util

class FareAttribute(GtfsObjectBase):
"""Represents a fare type."""
Expand Down
5 changes: 3 additions & 2 deletions transitfeed/farerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from problems import default_problem_reporter
from gtfsobjectbase import GtfsObjectBase
from __future__ import absolute_import
from .problems import default_problem_reporter
from .gtfsobjectbase import GtfsObjectBase

class FareRule(GtfsObjectBase):
"""This class represents a rule that determines which itineraries a
Expand Down
5 changes: 3 additions & 2 deletions transitfeed/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from gtfsobjectbase import GtfsObjectBase
import util
from __future__ import absolute_import
from .gtfsobjectbase import GtfsObjectBase
from . import util

class Frequency(GtfsObjectBase):
"""This class represents a period of a trip during which the vehicle travels
Expand Down
33 changes: 17 additions & 16 deletions transitfeed/gtfsfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from agency import Agency
from fareattribute import FareAttribute
from farerule import FareRule
from feedinfo import FeedInfo
from frequency import Frequency
from loader import Loader
import problems
from route import Route
from schedule import Schedule
from serviceperiod import ServicePeriod
from shape import Shape
from shapepoint import ShapePoint
from stop import Stop
from stoptime import StopTime
from transfer import Transfer
from trip import Trip
from __future__ import absolute_import
from .agency import Agency
from .fareattribute import FareAttribute
from .farerule import FareRule
from .feedinfo import FeedInfo
from .frequency import Frequency
from .loader import Loader
from . import problems
from .route import Route
from .schedule import Schedule
from .serviceperiod import ServicePeriod
from .shape import Shape
from .shapepoint import ShapePoint
from .stop import Stop
from .stoptime import StopTime
from .transfer import Transfer
from .trip import Trip

class GtfsFactory(object):
"""A factory for the default GTFS objects"""
Expand Down
3 changes: 2 additions & 1 deletion transitfeed/gtfsfactoryuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
class GtfsFactoryUser(object):
"""Base class for objects that must store a GtfsFactory in order to
be able to instantiate Gtfs classes.
Expand All @@ -38,7 +39,7 @@ def GetGtfsFactory(self):
# This is why the import is here and not at the top level.
# When this runs, gtfsfactory should have already been loaded
# by other modules, avoiding the circular imports.
import gtfsfactory
from . import gtfsfactory
self._gtfs_factory = gtfsfactory.GetGtfsFactory()
return self._gtfs_factory

Expand Down
3 changes: 2 additions & 1 deletion transitfeed/gtfsobjectbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from gtfsfactoryuser import GtfsFactoryUser
from __future__ import absolute_import
from .gtfsfactoryuser import GtfsFactoryUser

class GtfsObjectBase(GtfsFactoryUser):
"""Object with arbitrary attributes which may be added to a schedule.
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import codecs
import cStringIO as StringIO
import csv
import os
import re
import zipfile

import gtfsfactory as gtfsfactory_module
import problems
import util
from . import gtfsfactory as gtfsfactory_module
from . import problems
from . import util

class Loader:
def __init__(self,
Expand Down
3 changes: 2 additions & 1 deletion transitfeed/problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
# limitations under the License.

from __future__ import print_function
from __future__ import absolute_import
import logging
import time

import util
from . import util

# Problem types:
# Error: A data issue not allowed by the GTFS spec.
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from gtfsobjectbase import GtfsObjectBase
import problems as problems_module
import util
from __future__ import absolute_import
from .gtfsobjectbase import GtfsObjectBase
from . import problems as problems_module
from . import util

class Route(GtfsObjectBase):
"""Represents a single route."""
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import bisect
import cStringIO as StringIO
import datetime
Expand All @@ -39,10 +40,10 @@
import weakref
import zipfile

import gtfsfactory
import problems as problems_module
from . import gtfsfactory
from . import problems as problems_module
from transitfeed.util import defaultdict
import util
from . import util

class Schedule(object):
"""Represents a Schedule, a collection of stops, routes, trips and
Expand Down
5 changes: 3 additions & 2 deletions transitfeed/serviceperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import datetime
import re
import time

import problems as problems_module
import util
from . import problems as problems_module
from . import util

class ServicePeriod(object):
"""Represents a service, which identifies a set of dates when one or more
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import bisect

from gtfsfactoryuser import GtfsFactoryUser
import problems as problems_module
import util
from .gtfsfactoryuser import GtfsFactoryUser
from . import problems as problems_module
from . import util

class Shape(GtfsFactoryUser):
"""This class represents a geographic shape that corresponds to the route
Expand Down
3 changes: 2 additions & 1 deletion transitfeed/shapeloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from loader import Loader
from __future__ import absolute_import
from .loader import Loader

class ShapeLoader(Loader):
"""A subclass of Loader that only loads the shapes from a GTFS file."""
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/shapepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import bisect
from gtfsobjectbase import GtfsObjectBase
import problems as problems_module
import util
from .gtfsobjectbase import GtfsObjectBase
from . import problems as problems_module
from . import util
import sys

class ShapePoint(GtfsObjectBase):
Expand Down
7 changes: 4 additions & 3 deletions transitfeed/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import warnings

from gtfsobjectbase import GtfsObjectBase
import problems as problems_module
import util
from .gtfsobjectbase import GtfsObjectBase
from . import problems as problems_module
from . import util

class Stop(GtfsObjectBase):
"""Represents a single stop. A stop must have a latitude, longitude and name.
Expand Down
Loading

0 comments on commit 03374f0

Please sign in to comment.