From 1e266b87499d692337d62ab5097be45748a33d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20Iensen?= Date: Thu, 19 Oct 2017 18:45:36 +0200 Subject: [PATCH] Modularize osm2gtfs and add the setup file (#79) As a preparation for writing automated tests, in this commit, we are creating a root module called osm2gtfs. Having a root module will make it easier to import classes in the test files. We added a new setup file in the root folder so we can install osm2gtfs with pip, since we are now defining the project dependencies there we removed the requirements file. Also, after installing this project with pip you can run the script by calling osm2gtfs in your terminal. Relates to #75 --- .gitignore | 1 + .travis.yml | 4 +-- README.md | 21 +++++++++------- __init__.py => osm2gtfs/__init__.py | 0 {core => osm2gtfs/core}/__init__.py | 0 {core => osm2gtfs/core}/cache.py | 0 {core => osm2gtfs/core}/configuration.py | 0 {core => osm2gtfs/core}/creator_factory.py | 25 +++++++++++-------- {core => osm2gtfs/core}/osm_connector.py | 6 ++--- {core => osm2gtfs/core}/osm_routes.py | 0 {core => osm2gtfs/core}/osm_stops.py | 0 {creators => osm2gtfs/creators}/__init__.py | 0 .../creators}/accra/__init__.py | 0 .../creators}/accra/accra.json | 0 .../creators}/accra/routes_creator_accra.py | 2 +- .../creators}/accra/stops_creator_accra.py | 2 +- .../creators}/accra/trips_creator_accra.py | 2 +- .../creators}/agency_creator.py | 0 .../creators}/feed_info_creator.py | 0 .../creators}/fenix/__init__.py | 0 .../creators}/fenix/fenix.json | 0 .../creators}/fenix/routes_creator_fenix.py | 2 +- .../creators}/fenix/trips_creator_fenix.py | 4 +-- .../creators}/incofer/__init__.py | 0 .../creators}/incofer/incofer.json | 0 .../incofer/routes_creator_incofer.py | 2 +- .../incofer/trips_creator_incofer.py | 2 +- .../creators}/routes_creator.py | 0 .../creators}/stops_creator.py | 4 +-- .../creators}/trips_creator.py | 0 osm2gtfs.py => osm2gtfs/osm2gtfs.py | 0 requirements.txt | 2 -- setup.py | 12 +++++++++ 33 files changed, 55 insertions(+), 36 deletions(-) rename __init__.py => osm2gtfs/__init__.py (100%) rename {core => osm2gtfs/core}/__init__.py (100%) rename {core => osm2gtfs/core}/cache.py (100%) rename {core => osm2gtfs/core}/configuration.py (100%) rename {core => osm2gtfs/core}/creator_factory.py (77%) rename {core => osm2gtfs/core}/osm_connector.py (99%) rename {core => osm2gtfs/core}/osm_routes.py (100%) rename {core => osm2gtfs/core}/osm_stops.py (100%) rename {creators => osm2gtfs/creators}/__init__.py (100%) rename {creators => osm2gtfs/creators}/accra/__init__.py (100%) rename {creators => osm2gtfs/creators}/accra/accra.json (100%) rename {creators => osm2gtfs/creators}/accra/routes_creator_accra.py (80%) rename {creators => osm2gtfs/creators}/accra/stops_creator_accra.py (97%) rename {creators => osm2gtfs/creators}/accra/trips_creator_accra.py (98%) rename {creators => osm2gtfs/creators}/agency_creator.py (100%) rename {creators => osm2gtfs/creators}/feed_info_creator.py (100%) rename {creators => osm2gtfs/creators}/fenix/__init__.py (100%) rename {creators => osm2gtfs/creators}/fenix/fenix.json (100%) rename {creators => osm2gtfs/creators}/fenix/routes_creator_fenix.py (81%) rename {creators => osm2gtfs/creators}/fenix/trips_creator_fenix.py (99%) rename {creators => osm2gtfs/creators}/incofer/__init__.py (100%) rename {creators => osm2gtfs/creators}/incofer/incofer.json (100%) rename {creators => osm2gtfs/creators}/incofer/routes_creator_incofer.py (95%) rename {creators => osm2gtfs/creators}/incofer/trips_creator_incofer.py (99%) rename {creators => osm2gtfs/creators}/routes_creator.py (100%) rename {creators => osm2gtfs/creators}/stops_creator.py (96%) rename {creators => osm2gtfs/creators}/trips_creator.py (100%) rename osm2gtfs.py => osm2gtfs/osm2gtfs.py (100%) delete mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index dbe6595c..1fe661a3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ src # Android Studio files .idea/* !.idea/codeStyleSettings.xml +*.egg-info diff --git a/.travis.yml b/.travis.yml index 45519d2f..154a50a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,13 @@ python: - "2.7" install: - - pip install -r requirements.txt + - pip install -e . jobs: include: - stage: pep8 before_script: pip install pep8 - script: pep8 --show-pep8 --max-line-length=100 --exclude=data . + script: pep8 --show-pep8 --max-line-length=100 osm2gtfs - stage: pylint before_script: pip install pylint diff --git a/README.md b/README.md index 49aa337f..8239fb62 100644 --- a/README.md +++ b/README.md @@ -25,24 +25,27 @@ OpenStreetMap. And by extending the creator classes in code, different approaches for time information handling can be easily implemented. You can help with pull requests to improve this script. -Use +Install ------------ - python osm2gtfs.py -c - -Example: +Install by running - $ python osm2gtfs.py -c creators/fenix/fenix.json + pip install -e . Requirements ------------ +Automatically installed by the previous step: +* https://github.com/DinoTools/python-overpy +* https://github.com/google/transitfeed -Install dependencies by running +Use +------------ - pip install -r requirements.txt + osm2gtfs -c -* https://github.com/DinoTools/python-overpy -* https://github.com/google/transitfeed +Example: + + $ osm2gtfs -c osm2gtfs/creators/fenix/fenix.json License ------- diff --git a/__init__.py b/osm2gtfs/__init__.py similarity index 100% rename from __init__.py rename to osm2gtfs/__init__.py diff --git a/core/__init__.py b/osm2gtfs/core/__init__.py similarity index 100% rename from core/__init__.py rename to osm2gtfs/core/__init__.py diff --git a/core/cache.py b/osm2gtfs/core/cache.py similarity index 100% rename from core/cache.py rename to osm2gtfs/core/cache.py diff --git a/core/configuration.py b/osm2gtfs/core/configuration.py similarity index 100% rename from core/configuration.py rename to osm2gtfs/core/configuration.py diff --git a/core/creator_factory.py b/osm2gtfs/core/creator_factory.py similarity index 77% rename from core/creator_factory.py rename to osm2gtfs/core/creator_factory.py index aadf0a91..0f64e795 100644 --- a/core/creator_factory.py +++ b/osm2gtfs/core/creator_factory.py @@ -1,11 +1,11 @@ # coding=utf-8 import importlib -from creators.agency_creator import AgencyCreator -from creators.feed_info_creator import FeedInfoCreator -from creators.routes_creator import RoutesCreator -from creators.stops_creator import StopsCreator -from creators.trips_creator import TripsCreator +from osm2gtfs.creators.agency_creator import AgencyCreator +from osm2gtfs.creators.feed_info_creator import FeedInfoCreator +from osm2gtfs.creators.routes_creator import RoutesCreator +from osm2gtfs.creators.stops_creator import StopsCreator +from osm2gtfs.creators.trips_creator import TripsCreator class CreatorFactory(object): @@ -29,7 +29,8 @@ def get_agency_creator(self): selector = self.selector try: module = importlib.import_module( - "creators." + selector + ".agency_creator_" + selector) + ".creators." + selector + ".agency_creator_" + selector, + package="osm2gtfs") agency_creator_override = getattr( module, "AgencyCreator" + selector.capitalize()) print "Agency creator: " + selector.capitalize() @@ -42,7 +43,8 @@ def get_feed_info_creator(self): selector = self.selector try: module = importlib.import_module( - "creators." + selector + ".feed_info_creator_" + selector) + ".creators." + selector + ".feed_info_creator_" + selector, + package="osm2gtfs") feed_info_creator_override = getattr( module, "FeedInfoCreator" + selector.capitalize()) print "Feed info creator: " + selector.capitalize() @@ -55,7 +57,8 @@ def get_routes_creator(self): selector = self.selector try: module = importlib.import_module( - "creators." + selector + ".routes_creator_" + selector) + ".creators." + selector + ".routes_creator_" + selector, + package="osm2gtfs") routes_creator_override = getattr( module, "RoutesCreator" + selector.capitalize()) print "Routes creator: " + selector.capitalize() @@ -68,7 +71,8 @@ def get_stops_creator(self): selector = self.selector try: module = importlib.import_module( - "creators." + selector + ".stops_creator_" + selector) + ".creators." + selector + ".stops_creator_" + selector, + package="osm2gtfs") stops_creator_override = getattr( module, "StopsCreator" + selector.capitalize()) print "Stops creator: " + selector.capitalize() @@ -81,7 +85,8 @@ def get_trips_creator(self): selector = self.selector try: module = importlib.import_module( - "creators." + selector + ".trips_creator_" + selector) + ".creators." + selector + ".trips_creator_" + selector, + package="osm2gtfs") trips_creator_override = getattr( module, "TripsCreator" + selector.capitalize()) print "Trips creator: " + selector.capitalize() diff --git a/core/osm_connector.py b/osm2gtfs/core/osm_connector.py similarity index 99% rename from core/osm_connector.py rename to osm2gtfs/core/osm_connector.py index 9d172172..1fe81d75 100644 --- a/core/osm_connector.py +++ b/osm2gtfs/core/osm_connector.py @@ -4,9 +4,9 @@ import overpy from collections import OrderedDict from transitfeed import util -from core.cache import Cache -from core.osm_routes import Route, RouteMaster -from core.osm_stops import Stop, StopArea +from osm2gtfs.core.cache import Cache +from osm2gtfs.core.osm_routes import Route, RouteMaster +from osm2gtfs.core.osm_stops import Stop, StopArea class OsmConnector(object): diff --git a/core/osm_routes.py b/osm2gtfs/core/osm_routes.py similarity index 100% rename from core/osm_routes.py rename to osm2gtfs/core/osm_routes.py diff --git a/core/osm_stops.py b/osm2gtfs/core/osm_stops.py similarity index 100% rename from core/osm_stops.py rename to osm2gtfs/core/osm_stops.py diff --git a/creators/__init__.py b/osm2gtfs/creators/__init__.py similarity index 100% rename from creators/__init__.py rename to osm2gtfs/creators/__init__.py diff --git a/creators/accra/__init__.py b/osm2gtfs/creators/accra/__init__.py similarity index 100% rename from creators/accra/__init__.py rename to osm2gtfs/creators/accra/__init__.py diff --git a/creators/accra/accra.json b/osm2gtfs/creators/accra/accra.json similarity index 100% rename from creators/accra/accra.json rename to osm2gtfs/creators/accra/accra.json diff --git a/creators/accra/routes_creator_accra.py b/osm2gtfs/creators/accra/routes_creator_accra.py similarity index 80% rename from creators/accra/routes_creator_accra.py rename to osm2gtfs/creators/accra/routes_creator_accra.py index 14d6e2b8..fc2dea14 100644 --- a/creators/accra/routes_creator_accra.py +++ b/osm2gtfs/creators/accra/routes_creator_accra.py @@ -1,6 +1,6 @@ # coding=utf-8 -from creators.routes_creator import RoutesCreator +from osm2gtfs.creators.routes_creator import RoutesCreator class RoutesCreatorAccra(RoutesCreator): diff --git a/creators/accra/stops_creator_accra.py b/osm2gtfs/creators/accra/stops_creator_accra.py similarity index 97% rename from creators/accra/stops_creator_accra.py rename to osm2gtfs/creators/accra/stops_creator_accra.py index 5a399a16..6a7509f2 100644 --- a/creators/accra/stops_creator_accra.py +++ b/osm2gtfs/creators/accra/stops_creator_accra.py @@ -1,7 +1,7 @@ # coding=utf-8 -from creators.stops_creator import StopsCreator +from osm2gtfs.creators.stops_creator import StopsCreator import math diff --git a/creators/accra/trips_creator_accra.py b/osm2gtfs/creators/accra/trips_creator_accra.py similarity index 98% rename from creators/accra/trips_creator_accra.py rename to osm2gtfs/creators/accra/trips_creator_accra.py index 729dca70..99a5b254 100644 --- a/creators/accra/trips_creator_accra.py +++ b/osm2gtfs/creators/accra/trips_creator_accra.py @@ -2,7 +2,7 @@ from datetime import timedelta, datetime -from creators.trips_creator import TripsCreator +from osm2gtfs.creators.trips_creator import TripsCreator class TripsCreatorAccra(TripsCreator): diff --git a/creators/agency_creator.py b/osm2gtfs/creators/agency_creator.py similarity index 100% rename from creators/agency_creator.py rename to osm2gtfs/creators/agency_creator.py diff --git a/creators/feed_info_creator.py b/osm2gtfs/creators/feed_info_creator.py similarity index 100% rename from creators/feed_info_creator.py rename to osm2gtfs/creators/feed_info_creator.py diff --git a/creators/fenix/__init__.py b/osm2gtfs/creators/fenix/__init__.py similarity index 100% rename from creators/fenix/__init__.py rename to osm2gtfs/creators/fenix/__init__.py diff --git a/creators/fenix/fenix.json b/osm2gtfs/creators/fenix/fenix.json similarity index 100% rename from creators/fenix/fenix.json rename to osm2gtfs/creators/fenix/fenix.json diff --git a/creators/fenix/routes_creator_fenix.py b/osm2gtfs/creators/fenix/routes_creator_fenix.py similarity index 81% rename from creators/fenix/routes_creator_fenix.py rename to osm2gtfs/creators/fenix/routes_creator_fenix.py index 759f847f..87335d72 100644 --- a/creators/fenix/routes_creator_fenix.py +++ b/osm2gtfs/creators/fenix/routes_creator_fenix.py @@ -1,6 +1,6 @@ # coding=utf-8 -from creators.routes_creator import RoutesCreator +from osm2gtfs.creators.routes_creator import RoutesCreator class RoutesCreatorFenix(RoutesCreator): diff --git a/creators/fenix/trips_creator_fenix.py b/osm2gtfs/creators/fenix/trips_creator_fenix.py similarity index 99% rename from creators/fenix/trips_creator_fenix.py rename to osm2gtfs/creators/fenix/trips_creator_fenix.py index c950c46f..14ee0684 100644 --- a/creators/fenix/trips_creator_fenix.py +++ b/osm2gtfs/creators/fenix/trips_creator_fenix.py @@ -5,8 +5,8 @@ import re import transitfeed from datetime import timedelta, datetime -from creators.trips_creator import TripsCreator -from core.osm_routes import Route, RouteMaster +from osm2gtfs.creators.trips_creator import TripsCreator +from osm2gtfs.core.osm_routes import Route, RouteMaster DEBUG_ROUTE = "" BLACKLIST = [ diff --git a/creators/incofer/__init__.py b/osm2gtfs/creators/incofer/__init__.py similarity index 100% rename from creators/incofer/__init__.py rename to osm2gtfs/creators/incofer/__init__.py diff --git a/creators/incofer/incofer.json b/osm2gtfs/creators/incofer/incofer.json similarity index 100% rename from creators/incofer/incofer.json rename to osm2gtfs/creators/incofer/incofer.json diff --git a/creators/incofer/routes_creator_incofer.py b/osm2gtfs/creators/incofer/routes_creator_incofer.py similarity index 95% rename from creators/incofer/routes_creator_incofer.py rename to osm2gtfs/creators/incofer/routes_creator_incofer.py index e6e96cab..08590fb6 100644 --- a/creators/incofer/routes_creator_incofer.py +++ b/osm2gtfs/creators/incofer/routes_creator_incofer.py @@ -1,6 +1,6 @@ # coding=utf-8 -from creators.routes_creator import RoutesCreator +from osm2gtfs.creators.routes_creator import RoutesCreator class RoutesCreatorIncofer(RoutesCreator): diff --git a/creators/incofer/trips_creator_incofer.py b/osm2gtfs/creators/incofer/trips_creator_incofer.py similarity index 99% rename from creators/incofer/trips_creator_incofer.py rename to osm2gtfs/creators/incofer/trips_creator_incofer.py index 654f4184..acd011a8 100644 --- a/creators/incofer/trips_creator_incofer.py +++ b/osm2gtfs/creators/incofer/trips_creator_incofer.py @@ -5,7 +5,7 @@ import transitfeed -from creators.trips_creator import TripsCreator +from osm2gtfs.creators.trips_creator import TripsCreator class TripsCreatorIncofer(TripsCreator): diff --git a/creators/routes_creator.py b/osm2gtfs/creators/routes_creator.py similarity index 100% rename from creators/routes_creator.py rename to osm2gtfs/creators/routes_creator.py diff --git a/creators/stops_creator.py b/osm2gtfs/creators/stops_creator.py similarity index 96% rename from creators/stops_creator.py rename to osm2gtfs/creators/stops_creator.py index 13c2cbaa..b113b6ae 100644 --- a/creators/stops_creator.py +++ b/osm2gtfs/creators/stops_creator.py @@ -2,8 +2,8 @@ import transitfeed -from core.osm_routes import Route, RouteMaster -from core.osm_stops import Stop, StopArea +from osm2gtfs.core.osm_routes import Route, RouteMaster +from osm2gtfs.core.osm_stops import Stop, StopArea class StopsCreator(object): diff --git a/creators/trips_creator.py b/osm2gtfs/creators/trips_creator.py similarity index 100% rename from creators/trips_creator.py rename to osm2gtfs/creators/trips_creator.py diff --git a/osm2gtfs.py b/osm2gtfs/osm2gtfs.py similarity index 100% rename from osm2gtfs.py rename to osm2gtfs/osm2gtfs.py diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 2ef72bb6..00000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -overpy>=0.4 -transitfeed diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..32b65264 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_packages + +setup( + name='osm2gtfs', + install_requires=['overpy>=0.4', 'transitfeed'], + packages=find_packages(), + include_package_data=True, + entry_points=''' + [console_scripts] + osm2gtfs = osm2gtfs.osm2gtfs:main + ''' +)