From fd712e4e5a6940a4947959000dd52ce09f4764ff Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Fri, 23 Mar 2018 11:00:00 +0100 Subject: [PATCH] initial import of pyramid project --- .coveragerc | 3 + .gitignore | 2 +- CHANGES.txt | 4 + MANIFEST.in | 2 + README.txt | 36 ++++++++ development.ini | 71 ++++++++++++++ ordr/__init__.py | 12 +++ ordr/models/__init__.py | 77 ++++++++++++++++ ordr/models/meta.py | 16 ++++ ordr/models/mymodel.py | 18 ++++ ordr/routes.py | 3 + ordr/scripts/__init__.py | 1 + ordr/scripts/initializedb.py | 45 +++++++++ ordr/static/pyramid-16x16.png | Bin 0 -> 1319 bytes ordr/static/pyramid.png | Bin 0 -> 12901 bytes ordr/static/theme.css | 154 +++++++++++++++++++++++++++++++ ordr/templates/404.jinja2 | 8 ++ ordr/templates/layout.jinja2 | 64 +++++++++++++ ordr/templates/mytemplate.jinja2 | 8 ++ ordr/tests.py | 65 +++++++++++++ ordr/views/__init__.py | 0 ordr/views/default.py | 33 +++++++ ordr/views/notfound.py | 7 ++ production.ini | 65 +++++++++++++ pytest.ini | 3 + setup.py | 60 ++++++++++++ 26 files changed, 756 insertions(+), 1 deletion(-) create mode 100644 .coveragerc create mode 100644 CHANGES.txt create mode 100644 MANIFEST.in create mode 100644 README.txt create mode 100644 development.ini create mode 100644 ordr/__init__.py create mode 100644 ordr/models/__init__.py create mode 100644 ordr/models/meta.py create mode 100644 ordr/models/mymodel.py create mode 100644 ordr/routes.py create mode 100644 ordr/scripts/__init__.py create mode 100644 ordr/scripts/initializedb.py create mode 100644 ordr/static/pyramid-16x16.png create mode 100644 ordr/static/pyramid.png create mode 100644 ordr/static/theme.css create mode 100644 ordr/templates/404.jinja2 create mode 100644 ordr/templates/layout.jinja2 create mode 100644 ordr/templates/mytemplate.jinja2 create mode 100644 ordr/tests.py create mode 100644 ordr/views/__init__.py create mode 100644 ordr/views/default.py create mode 100644 ordr/views/notfound.py create mode 100644 production.ini create mode 100644 pytest.ini create mode 100644 setup.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..9244cd0 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +source = ordr +omit = ordr/test* diff --git a/.gitignore b/.gitignore index a3ff839..bfd1ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,4 @@ target/ # pyenv python configuration file .python-version -venv-ordr2 +.venv diff --git a/CHANGES.txt b/CHANGES.txt new file mode 100644 index 0000000..14b902f --- /dev/null +++ b/CHANGES.txt @@ -0,0 +1,4 @@ +0.0 +--- + +- Initial version. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..4323f7f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include *.txt *.ini *.cfg *.rst +recursive-include ordr *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2 diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..1758611 --- /dev/null +++ b/README.txt @@ -0,0 +1,36 @@ +Ordr +==== + +This is a complete redo of the Ordr project. + + +Getting Started +--------------- + +- Change directory into your newly created project. + + cd ordr + +- Create a Python virtual environment. + + python3 -m venv env + +- Upgrade packaging tools. + + env/bin/pip install --upgrade pip setuptools + +- Install the project in editable mode with its testing requirements. + + env/bin/pip install -e ".[testing]" + +- Configure the database. + + env/bin/initialize_ordr_db development.ini + +- Run your project's tests. + + env/bin/pytest + +- Run your project. + + env/bin/pserve development.ini diff --git a/development.ini b/development.ini new file mode 100644 index 0000000..98cdf4f --- /dev/null +++ b/development.ini @@ -0,0 +1,71 @@ +### +# app configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + +[app:main] +use = egg:ordr + +pyramid.reload_templates = true +pyramid.debug_authorization = false +pyramid.debug_notfound = false +pyramid.debug_routematch = false +pyramid.default_locale_name = en +pyramid.includes = + pyramid_debugtoolbar + +sqlalchemy.url = sqlite:///%(here)s/ordr.sqlite + +retry.attempts = 3 + +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + +[server:main] +use = egg:waitress#main +listen = localhost:6543 + +### +# logging configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### + +[loggers] +keys = root, ordr, sqlalchemy + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = INFO +handlers = console + +[logger_ordr] +level = DEBUG +handlers = +qualname = ordr + +[logger_sqlalchemy] +level = INFO +handlers = +qualname = sqlalchemy.engine +# "level = INFO" logs SQL queries. +# "level = DEBUG" logs SQL queries and results. +# "level = WARN" logs neither. (Recommended for production systems.) + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s diff --git a/ordr/__init__.py b/ordr/__init__.py new file mode 100644 index 0000000..4dab448 --- /dev/null +++ b/ordr/__init__.py @@ -0,0 +1,12 @@ +from pyramid.config import Configurator + + +def main(global_config, **settings): + """ This function returns a Pyramid WSGI application. + """ + config = Configurator(settings=settings) + config.include('pyramid_jinja2') + config.include('.models') + config.include('.routes') + config.scan() + return config.make_wsgi_app() diff --git a/ordr/models/__init__.py b/ordr/models/__init__.py new file mode 100644 index 0000000..4b5351e --- /dev/null +++ b/ordr/models/__init__.py @@ -0,0 +1,77 @@ +from sqlalchemy import engine_from_config +from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import configure_mappers +import zope.sqlalchemy + +# import or define all models here to ensure they are attached to the +# Base.metadata prior to any initialization routines +from .mymodel import MyModel # flake8: noqa + +# run configure_mappers after defining all of the models to ensure +# all relationships can be setup +configure_mappers() + + +def get_engine(settings, prefix='sqlalchemy.'): + return engine_from_config(settings, prefix) + + +def get_session_factory(engine): + factory = sessionmaker() + factory.configure(bind=engine) + return factory + + +def get_tm_session(session_factory, transaction_manager): + """ + Get a ``sqlalchemy.orm.Session`` instance backed by a transaction. + + This function will hook the session to the transaction manager which + will take care of committing any changes. + + - When using pyramid_tm it will automatically be committed or aborted + depending on whether an exception is raised. + + - When using scripts you should wrap the session in a manager yourself. + For example:: + + import transaction + + engine = get_engine(settings) + session_factory = get_session_factory(engine) + with transaction.manager: + dbsession = get_tm_session(session_factory, transaction.manager) + + """ + dbsession = session_factory() + zope.sqlalchemy.register( + dbsession, transaction_manager=transaction_manager) + return dbsession + + +def includeme(config): + """ + Initialize the model for a Pyramid app. + + Activate this setup using ``config.include('ordr.models')``. + + """ + settings = config.get_settings() + settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' + + # use pyramid_tm to hook the transaction lifecycle to the request + config.include('pyramid_tm') + + # use pyramid_retry to retry a request when transient exceptions occur + config.include('pyramid_retry') + + session_factory = get_session_factory(get_engine(settings)) + config.registry['dbsession_factory'] = session_factory + + # make request.dbsession available for use in Pyramid + config.add_request_method( + # r.tm is the transaction manager used by pyramid_tm + lambda r: get_tm_session(session_factory, r.tm), + 'dbsession', + reify=True + ) diff --git a/ordr/models/meta.py b/ordr/models/meta.py new file mode 100644 index 0000000..02285b3 --- /dev/null +++ b/ordr/models/meta.py @@ -0,0 +1,16 @@ +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.schema import MetaData + +# Recommended naming convention used by Alembic, as various different database +# providers will autogenerate vastly different names making migrations more +# difficult. See: http://alembic.zzzcomputing.com/en/latest/naming.html +NAMING_CONVENTION = { + "ix": "ix_%(column_0_label)s", + "uq": "uq_%(table_name)s_%(column_0_name)s", + "ck": "ck_%(table_name)s_%(constraint_name)s", + "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", + "pk": "pk_%(table_name)s" +} + +metadata = MetaData(naming_convention=NAMING_CONVENTION) +Base = declarative_base(metadata=metadata) diff --git a/ordr/models/mymodel.py b/ordr/models/mymodel.py new file mode 100644 index 0000000..d65a01a --- /dev/null +++ b/ordr/models/mymodel.py @@ -0,0 +1,18 @@ +from sqlalchemy import ( + Column, + Index, + Integer, + Text, +) + +from .meta import Base + + +class MyModel(Base): + __tablename__ = 'models' + id = Column(Integer, primary_key=True) + name = Column(Text) + value = Column(Integer) + + +Index('my_index', MyModel.name, unique=True, mysql_length=255) diff --git a/ordr/routes.py b/ordr/routes.py new file mode 100644 index 0000000..25504ad --- /dev/null +++ b/ordr/routes.py @@ -0,0 +1,3 @@ +def includeme(config): + config.add_static_view('static', 'static', cache_max_age=3600) + config.add_route('home', '/') diff --git a/ordr/scripts/__init__.py b/ordr/scripts/__init__.py new file mode 100644 index 0000000..5bb534f --- /dev/null +++ b/ordr/scripts/__init__.py @@ -0,0 +1 @@ +# package diff --git a/ordr/scripts/initializedb.py b/ordr/scripts/initializedb.py new file mode 100644 index 0000000..7307ecc --- /dev/null +++ b/ordr/scripts/initializedb.py @@ -0,0 +1,45 @@ +import os +import sys +import transaction + +from pyramid.paster import ( + get_appsettings, + setup_logging, + ) + +from pyramid.scripts.common import parse_vars + +from ..models.meta import Base +from ..models import ( + get_engine, + get_session_factory, + get_tm_session, + ) +from ..models import MyModel + + +def usage(argv): + cmd = os.path.basename(argv[0]) + print('usage: %s [var=value]\n' + '(example: "%s development.ini")' % (cmd, cmd)) + sys.exit(1) + + +def main(argv=sys.argv): + if len(argv) < 2: + usage(argv) + config_uri = argv[1] + options = parse_vars(argv[2:]) + setup_logging(config_uri) + settings = get_appsettings(config_uri, options=options) + + engine = get_engine(settings) + Base.metadata.create_all(engine) + + session_factory = get_session_factory(engine) + + with transaction.manager: + dbsession = get_tm_session(session_factory, transaction.manager) + + model = MyModel(name='one', value=1) + dbsession.add(model) diff --git a/ordr/static/pyramid-16x16.png b/ordr/static/pyramid-16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..979203112e76ba4cfdb8cd6f108f4275e987d99a GIT binary patch literal 1319 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?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Df5N>jAUh#W*oc<&Bi7 zHo%dei>%VPt3hk6MxNi_Es7TtGMdasl<|~f(O$o~A?FarcW*)Fe*vwclnHDZ?}+SP zgYR&kn8RYb9O9><=RQuodIuwAN)ulS;SGy)PX}i^~1UYf0k$b`JnqicQgxToaq?rolg6VA7$>(o?TbE z6jEI3BBqxbUgL{6t@896dly!z7dXPugQXkT$}T@PWqm_3(f}$Agk`G%;50L{=*mi| zTE(qgB%svciozkc)B +

Pyramid Alchemy scaffold

+

404 Page Not Found

+ +{% endblock content %} diff --git a/ordr/templates/layout.jinja2 b/ordr/templates/layout.jinja2 new file mode 100644 index 0000000..27b0e9f --- /dev/null +++ b/ordr/templates/layout.jinja2 @@ -0,0 +1,64 @@ + + + + + + + + + + + Cookiecutter Alchemy project for the Pyramid Web Framework + + + + + + + + + + + + + +
+
+
+
+ +
+
+ {% block content %} +

No content

+ {% endblock content %} +
+
+ +
+ +
+
+
+ + + + + + + + diff --git a/ordr/templates/mytemplate.jinja2 b/ordr/templates/mytemplate.jinja2 new file mode 100644 index 0000000..45b7d0d --- /dev/null +++ b/ordr/templates/mytemplate.jinja2 @@ -0,0 +1,8 @@ +{% extends "layout.jinja2" %} + +{% block content %} +
+

Pyramid Alchemy project

+

Welcome to Ordr, a Pyramid application generated by
Cookiecutter.

+
+{% endblock content %} diff --git a/ordr/tests.py b/ordr/tests.py new file mode 100644 index 0000000..8e8c4b0 --- /dev/null +++ b/ordr/tests.py @@ -0,0 +1,65 @@ +import unittest +import transaction + +from pyramid import testing + + +def dummy_request(dbsession): + return testing.DummyRequest(dbsession=dbsession) + + +class BaseTest(unittest.TestCase): + def setUp(self): + self.config = testing.setUp(settings={ + 'sqlalchemy.url': 'sqlite:///:memory:' + }) + self.config.include('.models') + settings = self.config.get_settings() + + from .models import ( + get_engine, + get_session_factory, + get_tm_session, + ) + + self.engine = get_engine(settings) + session_factory = get_session_factory(self.engine) + + self.session = get_tm_session(session_factory, transaction.manager) + + def init_database(self): + from .models.meta import Base + Base.metadata.create_all(self.engine) + + def tearDown(self): + from .models.meta import Base + + testing.tearDown() + transaction.abort() + Base.metadata.drop_all(self.engine) + + +class TestMyViewSuccessCondition(BaseTest): + + def setUp(self): + super(TestMyViewSuccessCondition, self).setUp() + self.init_database() + + from .models import MyModel + + model = MyModel(name='one', value=55) + self.session.add(model) + + def test_passing_view(self): + from .views.default import my_view + info = my_view(dummy_request(self.session)) + self.assertEqual(info['one'].name, 'one') + self.assertEqual(info['project'], 'Ordr') + + +class TestMyViewFailureCondition(BaseTest): + + def test_failing_view(self): + from .views.default import my_view + info = my_view(dummy_request(self.session)) + self.assertEqual(info.status_int, 500) diff --git a/ordr/views/__init__.py b/ordr/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ordr/views/default.py b/ordr/views/default.py new file mode 100644 index 0000000..4835ed3 --- /dev/null +++ b/ordr/views/default.py @@ -0,0 +1,33 @@ +from pyramid.response import Response +from pyramid.view import view_config + +from sqlalchemy.exc import DBAPIError + +from ..models import MyModel + + +@view_config(route_name='home', renderer='../templates/mytemplate.jinja2') +def my_view(request): + try: + query = request.dbsession.query(MyModel) + one = query.filter(MyModel.name == 'one').first() + except DBAPIError: + return Response(db_err_msg, content_type='text/plain', status=500) + return {'one': one, 'project': 'Ordr'} + + +db_err_msg = """\ +Pyramid is having a problem using your SQL database. The problem +might be caused by one of the following things: + +1. You may need to run the "initialize_ordr_db" script + to initialize your database tables. Check your virtual + environment's "bin" directory for this script and try to run it. + +2. Your database server may not be running. Check that the + database server referred to by the "sqlalchemy.url" setting in + your "development.ini" file is running. + +After you fix the problem, please restart the Pyramid application to +try it again. +""" diff --git a/ordr/views/notfound.py b/ordr/views/notfound.py new file mode 100644 index 0000000..69d6e28 --- /dev/null +++ b/ordr/views/notfound.py @@ -0,0 +1,7 @@ +from pyramid.view import notfound_view_config + + +@notfound_view_config(renderer='../templates/404.jinja2') +def notfound_view(request): + request.response.status = 404 + return {} diff --git a/production.ini b/production.ini new file mode 100644 index 0000000..92aa483 --- /dev/null +++ b/production.ini @@ -0,0 +1,65 @@ +### +# app configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + +[app:main] +use = egg:ordr + +pyramid.reload_templates = false +pyramid.debug_authorization = false +pyramid.debug_notfound = false +pyramid.debug_routematch = false +pyramid.default_locale_name = en + +sqlalchemy.url = sqlite:///%(here)s/ordr.sqlite + +retry.attempts = 3 + +### +# wsgi server configuration +### + +[server:main] +use = egg:waitress#main +listen = *:6543 + +### +# logging configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### + +[loggers] +keys = root, ordr, sqlalchemy + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console + +[logger_ordr] +level = WARN +handlers = +qualname = ordr + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine +# "level = INFO" logs SQL queries. +# "level = DEBUG" logs SQL queries and results. +# "level = WARN" logs neither. (Recommended for production systems.) + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..7286498 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = ordr +python_files = *.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0cd63a3 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +import os + +from setuptools import setup, find_packages + +here = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(here, 'README.txt')) as f: + README = f.read() +with open(os.path.join(here, 'CHANGES.txt')) as f: + CHANGES = f.read() + +requires = [ + 'plaster_pastedeploy', + 'pyramid >= 1.9a', + 'pyramid_debugtoolbar', + 'pyramid_jinja2', + 'pyramid_retry', + 'pyramid_tm', + 'SQLAlchemy', + 'transaction', + 'zope.sqlalchemy', + 'waitress', +] + +tests_require = [ + 'WebTest >= 1.3.1', # py3 compat + 'pytest', + 'pytest-cov', +] + +setup( + name='ordr', + version='0.0', + description='Ordr', + long_description=README + '\n\n' + CHANGES, + classifiers=[ + 'Programming Language :: Python', + 'Framework :: Pyramid', + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Internet :: WWW/HTTP :: WSGI :: Application', + ], + author='', + author_email='', + url='', + keywords='web pyramid pylons', + packages=find_packages(), + include_package_data=True, + zip_safe=False, + extras_require={ + 'testing': tests_require, + }, + install_requires=requires, + entry_points={ + 'paste.app_factory': [ + 'main = ordr:main', + ], + 'console_scripts': [ + 'initialize_ordr_db = ordr.scripts.initializedb:main', + ], + }, +)