Skip to content

Commit

Permalink
Restructuring project to meet setup.py packaging standards
Browse files Browse the repository at this point in the history
  • Loading branch information
sripathikrishnan committed Oct 24, 2016
1 parent e78b375 commit 4bcb37a
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
venv
.project
.pydevproject
*.pyc
build/
dist/
jinja2sql.egg-info/
venv
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* 0.1.0
* Initial Release
5 changes: 5 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Please use
python setup.py install

To report errors, create a new issue on Github - https://github.com/hashedin/jinjasql/issues

22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License

Copyright (c) 2016 HashedIn Technologies Pvt. Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include CHANGES
include INSTALL
include LICENSE
include README.textile
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Generate SQL Queries using a Jinja2 Template. #

JinjaSql automatically tracks bind parameters, and returns an array
of all parameters that can be used to execute the query.

## Installing jinjasql ##

Pre-Requisites :

1. python 2.x and pip.
2. jinja2

To install from PyPI (recommended) :

pip install jinjasql

To install from source :

git clone https://github.com/hashedin/jinjasql
cd jinjasql
sudo python setup.py install

## Usage ##

from jinja2sql import JinjaSql

template = """
SELECT project, timesheet, hours
FROM timesheet
WHERE user_id = {{ user_id }}
{% if project_id %}
AND project_id = {{ project_id }}
{% endif %}
"""

data = {
"project_id": 123,
"user_id": u"sripathi"
}

j = JinjaSql()
query, bind_params = j.prepare_query(template, data)

expected_query = """
SELECT project, timesheet, hours
FROM timesheet
WHERE user_id = %s
AND project_id = %s
"""

self.assertEquals(bind_params, [u'sripathi', 123])
self.assertEquals(query.strip(), expected_query.strip())

# You can now use the query and bind parameters to execute the query
# For example, in django

from django.db import connection
with connection.cursor() as cursor:
cursor.execute(query, bind_params)
for row in cursor.fetchall():
# do something with the results
pass


## License

jinjasql is licensed under the MIT License. See [LICENSE](https://github.com/hashedin/jinjasql/blob/master/LICENSE)

## Maintained By

Sripathi Krishnan : @srithedabbler
6 changes: 6 additions & 0 deletions jinjasql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from jinjasql.core import JinjaSql

__version__ = '0.1.0'
VERSION = tuple(map(int, __version__.split('.')))

__all__ = ['JinjaSql']
File renamed without changes.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Jinja2==2.8
MarkupSafe==0.23
wsgiref==0.1.2
8 changes: 8 additions & 0 deletions run_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python

import unittest
from tests import all_tests

if __name__ == "__main__":
tests = all_tests()
results = unittest.TextTestRunner().run(tests)
42 changes: 42 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
import os
from rdbtools import __version__

long_description = '''
Generate SQL Queries using a Jinja2 Template.
JinjaSql automatically tracks bind parameters, and returns an array
of all parameters that can be used to execute the query.
'''

sdict = {
'name' : 'jinjasql',
'version' : __version__,
'description' : 'Generate SQL Queries and Corresponding Bind Parameters using a Jinja2 Template',
'long_description' : long_description,
'url': 'https://github.com/hashedin/jinjasql',
'download_url' : 'http://cloud.github.com/downloads/hashedin/jinjasql/jinjasql-%s.tar.gz' % __version__,
'author' : 'Sripathi Krishnan',
'author_email' : '[email protected]',
'maintainer' : 'Sripathi Krishnan',
'maintainer_email' : '[email protected]',
'keywords' : ['Jinja2', 'SQL', 'Python', 'Template'],
'license' : 'MIT',
'packages' : ['jinjasql'],
'test_suite' : 'tests.all_tests',
'classifiers' : [
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python'],
}

try:
from setuptools import setup
except ImportError:
from distutils.core import setup

setup(**sdict)

7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import unittest
from tests.test_jinjasql import JinjaSqlTest

def all_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(JinjaSqlTest))
return suite
3 changes: 1 addition & 2 deletions test_jinja2sql.py → tests/test_jinjasql.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ def test_macro(self):
self.assertEquals(query.strip(), query.strip())
self.assertEquals(bind_params, [123, u'sripathi'])


def test_html_escape(self):
"""Check that jinja doesn't escape HTML characters"""

source = """select 'x' from dual where X {{etc.lt | sqlsafe}} 1"""
j = JinjaSql()
query, bind_params = j.prepare_query(source, _DATA)
Expand Down

0 comments on commit 4bcb37a

Please sign in to comment.