Giter Club home page Giter Club logo

pylons / pyramid-cookiecutter-alchemy Goto Github PK

View Code? Open in Web Editor NEW
40.0 11.0 23.0 105 KB

[DEPRECATED - Please use https://github.com/pylons/pyramid-cookiecutter-starter instead] A Cookiecutter (project template) for creating a Pyramid project using SQLite for persistent storage, SQLAlchemy for an ORM, Alembic for database migrations, URL dispatch for routing, and Jinja2 for templating.

Python 67.21% CSS 13.07% HTML 17.52% Mako 2.20%
cookiecutter-template pyramid sqlite sqlalchemy alembic jinja2 url-dispatch

pyramid-cookiecutter-alchemy's Introduction

pyramid-cookiecutter-alchemy

Deprecation notice

This cookiecutter has been deprecated in favor of the unified cookiecutter pyramid-cookiecutter-starter effective with the release of Pyramid 1.10. pyramid-cookiecutter-starter combines all features of pyramid-cookiecutter-alchemy and pyramid-cookiecutter-zodb. Please use pyramid-cookiecutter-starter instead of this one. This cookiecutter may not receive further updates.

latest Travis CI Status

A Cookiecutter (project template) for creating a Pyramid project using SQLite for persistent storage, SQLAlchemy for an ORM, Alembic for database migrations, URL dispatch for routing, and Jinja2 for templating.

Requirements

Versions

This cookiecutter has several branches to support new features in Pyramid or avoid incompatibilities.

  • latest aligns with the latest stable release of Pyramid, and is the default branch on GitHub.
  • master aligns with the master branch of Pyramid, and is where development takes place.
  • x.y-branch aligns with the x.y-branch branch of Pyramid.

Usage

  1. Generate a Pyramid project, following the prompts from the command.

    $ cookiecutter gh:Pylons/pyramid-cookiecutter-alchemy

    Optionally append a specific branch checkout to the command:

    $ cookiecutter gh:Pylons/pyramid-cookiecutter-alchemy --checkout master
  2. Finish configuring the project by creating a virtual environment and installing your new project. These steps are output as part of the cookiecutter command above and are slightly different for Windows.

    # Change directory into your newly created project.
    $ cd myproj
    # Create a virtual environment...
    $ python3 -m venv env
    # ...where we upgrade packaging tools...
    $ env/bin/pip install --upgrade pip setuptools
    # ...and into which we install our project and its testing requirements.
    $ env/bin/pip install -e ".[testing]"
  3. Initialize and upgrade the database using Alembic.

    # Generate your first revision.
    $ env/bin/alembic -c development.ini revision --autogenerate -m "init"
    # Upgrade to that revision.
    $ env/bin/alembic -c development.ini upgrade head
  4. Load default data into the database using a script.

    $ env/bin/initialize_tutorial_db development.ini
  5. Run your project's tests.

    $ env/bin/pytest
  6. Run your project.

    $ env/bin/pserve development.ini

pyramid-cookiecutter-alchemy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyramid-cookiecutter-alchemy's Issues

Would be great to add a functional test using SQLAlchemy.

Hi! Thanks for the work in this cookiecutter :)

I was following along but found an issue,

https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/testing.html

Says, in the bottom, that for functional tests we should use

class FunctionalTests(unittest.TestCase):
    def setUp(self):
        from myproject import main
        app = main({})
        from webtest import TestApp
        self.testapp = TestApp(app)

    def test_root(self):
        res = self.testapp.get('/', status=200)
        self.assertTrue(b'Pyramid' in res.body)

If we try to apply this on this cookiecutter we get an error from the main({}) part with a SQLAlchemy KeyError on url, following the unit test I was able to augment the cookie cutter with

class BaseFunctionalTest(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp(settings={
            'sqlalchemy.url': 'sqlite:///:memory:'
        })
        self.config.include('bookshare.models')
        settings = self.config.get_settings()

        from bookshare import main
        app = main(settings)

        from webtest import TestApp
        self.testapp = TestApp(app)

    def tearDown(self):
        testing.tearDown()
        transaction.abort()

However I still got the same error, after some google-ing and Stackoverflow I saw that it should be

app = main(global_config={}, **settings)

Of course that I could've checked better the docstring of the functions and so on but still, for newcomers, not that obvious :)

Thanks!

uWSGI Entry Point

Would you be so kind as to provide a working uWSGI entry point for this cookiecutter?

There already exist tutorials on setting up uWSGI to serve REALLY BASIC pyramid applications. But their methods don't work with this cookiecutter, because there is not just one single python file that has an "application" defined.

How to Recreate Issue

Say I create a new application named "umbrella":

python3 -m cookiecutter gh:Pylons/pyramid-cookiecutter-alchemy

After following the instructions output from the cookiecutter, running pserve works fine:

env/bin/pserve production.ini  # this works fine!

But say now I want to run it from uWSGI like this:

uwsgi --chmod-socket=020 --enable-threads --plugin=python3 -s /tmp/umbrella.sock --manage-script-name --mount /=wsgi:application

Based on the "--mount /=wsgi:application" part of the invocation, uWSGI expects to have an entry point (python file) by the name of "wsgi.py" that defines a variable named "application". Would you be so kind as to provide such a wsgi.py file that will work?

My best effort is the following:

# wsgi.py
from umbrella import main
import pyramid


global_config = {'__file__': '/home/ubuntu/umbrella/production.ini',
                 'here': '/home/ubuntu/umbrella'}

settings = {'pyramid.reload_templates': 'false',
            'pyramid.debug_authorization': 'false',
            'pyramid.debug_notfound': 'false',
            'pyramid.debug_routematch': 'false', i
            'pyramid.default_locale_name': 'en',
            'sqlalchemy.url': 'sqlite:////home/ubuntu/umbrella/umbrella.sqlite',
            'retry.attempts': '3'}

application = main(global_config, settings=settings)

if __name__ == '__main__':
    # uWSGI won't call this section, but it gives us a way to test the code above
    # using env/bin/python wsgi.py
    from waitress import serve
    serve(application, host='0.0.0.0', port=6542)

But whether it's invoked via the uwsgi incantation shows above or via a simple env/bin/python wsgi.py, it gives the same error:

$ env/bin/python wsgi.py
Traceback (most recent call last):
  File "wsgi.py", line 15, in <module>
    application = main(global_config, settings=settings)
  File "/home/ubuntu/umbrella/umbrella/__init__.py", line 12, in main
    config.include('.models')
  File "/home/ubuntu/umbrella/env/lib/python3.6/site-packages/pyramid/config/__init__.py", line 839, in include
    c(configurator)
  File "/home/ubuntu/umbrella/umbrella/models/__init__.py", line 69, in includeme
    session_factory = get_session_factory(get_engine(settings))
  File "/home/ubuntu/umbrella/umbrella/models/__init__.py", line 17, in get_engine
    return engine_from_config(settings, prefix)
  File "/home/ubuntu/umbrella/env/lib/python3.6/site-packages/sqlalchemy/engine/__init__.py", line 464, in engine_from_config
    url = options.pop('url')
KeyError: 'url'

Not saying this is necessarily a bug with the cookiecutter, but hoping you can offer
some advice anyway.

alembic migrations: need to have the [alembic] section in all ini files

I am a bit doubtful about the need to have the [alembic] section in all ini files. If I am not mistaken, the [alembic]script_location must be same in all config files for migrations to work. Then I think putting it into the config file is sort of confusing and can cause mistakes. What about adding something like this into alembic's env.py?

if not config.get_main_option("script_location"): config.set_main_option("script_location", "{{ cookiecutter.repo_name }}/alembic")

Thus, the settings in the ini files would continue working but they would be optional.

If we agree on this, I will prepare a pull request...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.