From 03991e584d70494d735f6efe12654cb8bd06f448 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 17:36:15 -0400 Subject: [PATCH 01/15] Add Django app with fantasy models and migrations --- .gitignore | 20 ++++++ MANIFEST.in | 3 + django/fantasy/__init__.py | 0 django/fantasy/migrations/0001_initial.py | 75 +++++++++++++++++++++++ django/fantasy/migrations/__init__.py | 0 django/fantasy/models.py | 51 +++++++++++++++ setup.py | 35 +++++++++++ 7 files changed, 184 insertions(+) create mode 100644 MANIFEST.in create mode 100644 django/fantasy/__init__.py create mode 100644 django/fantasy/migrations/0001_initial.py create mode 100644 django/fantasy/migrations/__init__.py create mode 100644 django/fantasy/models.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 1db64ac..d00b2a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,22 @@ node_modules .log +*.pyc + +# Python Distribution / packaging +.Python +env/ +.env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e4455d3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include LICENSE +include README.md +include data.json \ No newline at end of file diff --git a/django/fantasy/__init__.py b/django/fantasy/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django/fantasy/migrations/0001_initial.py b/django/fantasy/migrations/0001_initial.py new file mode 100644 index 0000000..a5a4e5e --- /dev/null +++ b/django/fantasy/migrations/0001_initial.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField(max_length=80)), + ('date_of_birth', models.DateField()), + ('date_of_death', models.DateField(null=True)), + ], + ), + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.CharField(max_length=80)), + ('date_published', models.DateField()), + ('author', models.ForeignKey(to='fantasy.Author')), + ], + ), + migrations.CreateModel( + name='Chapter', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.CharField(max_length=80)), + ('ordering', models.PositiveIntegerField()), + ('book', models.ForeignKey(to='fantasy.Book')), + ], + ), + migrations.CreateModel( + name='Photo', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.CharField(max_length=80)), + ('uri', models.URLField()), + ('imageable_id', models.PositiveIntegerField()), + ('imageable_type', models.ForeignKey(to='contenttypes.ContentType')), + ], + ), + migrations.CreateModel( + name='Series', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.CharField(max_length=80)), + ], + ), + migrations.CreateModel( + name='Store', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField(max_length=80)), + ('books', models.ManyToManyField(to='fantasy.Book')), + ], + ), + migrations.AddField( + model_name='book', + name='series', + field=models.ForeignKey(to='fantasy.Series', null=True), + ), + migrations.AlterUniqueTogether( + name='chapter', + unique_together=set([('book', 'ordering')]), + ), + ] diff --git a/django/fantasy/migrations/__init__.py b/django/fantasy/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django/fantasy/models.py b/django/fantasy/models.py new file mode 100644 index 0000000..9c8c0e0 --- /dev/null +++ b/django/fantasy/models.py @@ -0,0 +1,51 @@ + +from django.db import models +from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation +from django.contrib.contenttypes.models import ContentType + + +class Author(models.Model): + name = models.CharField(max_length=80) + date_of_birth = models.DateField() + date_of_death = models.DateField(null=True) + + +class Series(models.Model): + title = models.CharField(max_length=80) + photo = GenericRelation( + 'fantasy.Photo', + content_type_field='imageable_type', + object_id_field='imageable_id', + ) + + +class Book(models.Model): + series = models.ForeignKey('fantasy.Series', null=True) + author = models.ForeignKey('fantasy.Author') + title = models.CharField(max_length=80) + date_published = models.DateField() + + +class Chapter(models.Model): + title = models.CharField(max_length=80) + book = models.ForeignKey('fantasy.Book') + ordering = models.PositiveIntegerField() + + class Meta: + unique_together = ( + ('book', 'ordering'), + ) + + +class Store(models.Model): + name = models.CharField(max_length=80) + books = models.ManyToManyField('fantasy.Book') + + +class Photo(models.Model): + title = models.CharField(max_length=80) + uri = models.URLField() + + imageable_type = models.ForeignKey(ContentType) + imageable_id = models.PositiveIntegerField() + imageable_object = GenericForeignKey('imageable_type', 'imageable_id') diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a2b3765 --- /dev/null +++ b/setup.py @@ -0,0 +1,35 @@ +import os +from setuptools import setup, find_packages + + +README = open(os.path.join(os.path.dirname(__file__), 'django/README.md')).read() + +# allow setup.py to be run from any path +os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) + + +setup( + name='fantasy-database', + version='2.0.0', + license='BSD License', + + description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.', + long_description=README, + url='https://github.com/tkellen/fantasy-database', + author='Tyler Kellen', + package_dir={'': 'django'}, + packages=find_packages(), + + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Environment :: Web Environment', + 'Framework :: Django', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], +) From a562f391fa27ddf312e50b7e8ee622b6ed8b8cb6 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 17:38:12 -0400 Subject: [PATCH 02/15] Add Django fixture generation on setup --- django/fantasy/fixtures/fantasy-database.json | 1 + django/utils.py | 74 +++++++++++++++++++ setup.py | 40 ++++++++++ 3 files changed, 115 insertions(+) create mode 100644 django/fantasy/fixtures/fantasy-database.json create mode 100644 django/utils.py diff --git a/django/fantasy/fixtures/fantasy-database.json b/django/fantasy/fixtures/fantasy-database.json new file mode 100644 index 0000000..bef5c65 --- /dev/null +++ b/django/fantasy/fixtures/fantasy-database.json @@ -0,0 +1 @@ +// This will be replaced on setup \ No newline at end of file diff --git a/django/utils.py b/django/utils.py new file mode 100644 index 0000000..1ea0fb5 --- /dev/null +++ b/django/utils.py @@ -0,0 +1,74 @@ + + +def translate_fixture(data): + """ + Translate the contents of the `data.json` file into a django compatible fixture. + """ + results = [] + + for author in data['authors']: + results.append({ + 'pk': author['id'], 'model': 'fantasy.author', + 'fields': { + 'name': author['name'], + 'date_of_birth': author['date_of_birth'], + 'date_of_death': author['date_of_death'], + } + }) + + for series in data['series']: + results.append({ + 'pk': series['id'], 'model': 'fantasy.series', + 'fields': { + 'title': series['title'], + } + }) + + for book in data['books']: + results.append({ + 'pk': book['id'], 'model': 'fantasy.book', + 'fields': { + 'series': book['series_id'], + 'author': book['author_id'], + 'title': book['title'], + 'date_published': book['date_published'], + } + }) + + for chapter in data['chapters']: + results.append({ + 'pk': chapter['id'], 'model': 'fantasy.chapter', + 'fields': { + 'title': chapter['title'], + 'book': chapter['book_id'], + 'ordering': chapter['ordering'], + } + }) + + for store in data['stores']: + results.append({ + 'pk': store['id'], 'model': 'fantasy.store', + 'fields': { + 'name': store['name'], + 'books': [sb['book_id'] for sb in data['books_stores'] if sb['store_id'] == store['id']], + } + }) + + for photo in data['photos']: + types_map = { + 'authors': ('fantasy', 'author'), + 'books': ('fantasy', 'book'), + 'series': ('fantasy', 'series'), + } + + results.append({ + 'pk': photo['id'], 'model': 'fantasy.photo', + 'fields': { + 'imageable_id': photo['imageable_id'], + 'imageable_type': types_map[photo['imageable_type']], + 'title': photo['title'], + 'uri': photo['uri'], + } + }) + + return results diff --git a/setup.py b/setup.py index a2b3765..2425fdc 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,9 @@ import os +import sys +import json from setuptools import setup, find_packages +from setuptools.command.develop import develop +from setuptools.command.install import install README = open(os.path.join(os.path.dirname(__file__), 'django/README.md')).read() @@ -7,6 +11,37 @@ # allow setup.py to be run from any path os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) +# append the django directory to our path so we can import utils +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(BASE_DIR, 'django')) + + +def build_fixture(): + from utils import translate_fixture + + contents = None + with open(os.path.join(BASE_DIR, 'data.json')) as f: + contents = json.loads(f.read()) + + contents = translate_fixture(contents) + + with open(os.path.join(BASE_DIR, 'django/fantasy/fixtures/fantasy-database.json'), 'w') as f: + f.write(json.dumps(contents)) + + +class Develop(develop): + + def run(self): + develop.run(self) + build_fixture() + + +class Install(install): + + def run(self): + install.run(self) + build_fixture() + setup( name='fantasy-database', @@ -20,6 +55,11 @@ package_dir={'': 'django'}, packages=find_packages(), + cmdclass={ + 'develop': Develop, + 'install': Install, + }, + classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Web Environment', From 56467f1c32ff253bce5ce8f5d4c469e9be120830 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 20:14:32 -0400 Subject: [PATCH 03/15] Add test environment with setuptools integration --- django/tests/__init__.py | 0 django/tests/runner.py | 28 ++++++++++++++++++++++++++++ django/tests/settings.py | 23 +++++++++++++++++++++++ django/tests/test_fixture.py | 14 ++++++++++++++ django/tests/urls.py | 4 ++++ setup.py | 29 +++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 django/tests/__init__.py create mode 100644 django/tests/runner.py create mode 100644 django/tests/settings.py create mode 100644 django/tests/test_fixture.py create mode 100644 django/tests/urls.py diff --git a/django/tests/__init__.py b/django/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django/tests/runner.py b/django/tests/runner.py new file mode 100644 index 0000000..e570259 --- /dev/null +++ b/django/tests/runner.py @@ -0,0 +1,28 @@ +import os +import sys +import glob + + +base = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) + +# add test eggs to path +eggs = os.path.join(base, ".eggs/*.egg") +sys.path += glob.glob(eggs) + +# also add parent directory to path (to find tests) +pkg_base = os.path.join(base, 'django') +sys.path.append(pkg_base) + +os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' + + +def main(argv): + from django.core.management import execute_from_command_line + execute_from_command_line(argv) + + +if __name__ == '__main__': + args = sys.argv + args.insert(1, 'test') + + main(args) diff --git a/django/tests/settings.py b/django/tests/settings.py new file mode 100644 index 0000000..19ee684 --- /dev/null +++ b/django/tests/settings.py @@ -0,0 +1,23 @@ + +SECRET_KEY = 'not-so-secret' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } +} + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'fantasy', + 'tests', +) + + +ROOT_URLCONF = 'tests.urls' diff --git a/django/tests/test_fixture.py b/django/tests/test_fixture.py new file mode 100644 index 0000000..b323bcf --- /dev/null +++ b/django/tests/test_fixture.py @@ -0,0 +1,14 @@ + +from django.test import TestCase +from fantasy import models + + +class FixtureTest(TestCase): + fixtures = ['fantasy-database.json'] + + def test_data(self): + authors = models.Author.objects.values_list('name', flat=True) + + self.assertEqual(len(authors), 2) + self.assertEqual(authors[0], 'J. R. R. Tolkien') + self.assertEqual(authors[1], 'J. K. Rowling') diff --git a/django/tests/urls.py b/django/tests/urls.py new file mode 100644 index 0000000..f5a2617 --- /dev/null +++ b/django/tests/urls.py @@ -0,0 +1,4 @@ +""" +Blank URLConf just to keep the test suite happy +""" +urlpatterns = [] diff --git a/setup.py b/setup.py index 2425fdc..7e3395a 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ from setuptools import setup, find_packages from setuptools.command.develop import develop from setuptools.command.install import install +from setuptools.command.test import test README = open(os.path.join(os.path.dirname(__file__), 'django/README.md')).read() @@ -43,6 +44,31 @@ def run(self): build_fixture() +class Test(test): + user_options = [ + ('test-labels=', 'l', "Test labels to pass to runner.py test"), + ('djtest-args=', 'a', "Arguments to pass to runner.py test"), + ] + + def initialize_options(self): + test.initialize_options(self) + self.test_labels = 'tests' + self.djtest_args = '' + + def finalize_options(self): + test.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + from tests.runner import main + build_fixture() + + test_labels = self.test_labels.split() + djtest_args = self.djtest_args.split() + main(['runner.py', 'test'] + test_labels + djtest_args) + + setup( name='fantasy-database', version='2.0.0', @@ -55,9 +81,12 @@ def run(self): package_dir={'': 'django'}, packages=find_packages(), + tests_require=['django>=1.7'], + cmdclass={ 'develop': Develop, 'install': Install, + 'test': Test, }, classifiers=[ From 8948921b8af0f7e876292147697bb31380839abc Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 20:26:43 -0400 Subject: [PATCH 04/15] Add Django readme and fix setuptools license class --- README.md | 3 +++ django/README.md | 35 +++++++++++++++++++++++++++++++++++ setup.py | 4 ++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 django/README.md diff --git a/README.md b/README.md index 57819c4..1d58d43 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,6 @@ If you are a node user, running `npm install && npm start` will rebuild the SQLi Make this repository a dependency of your project and automate the process of copying `fantasy.db` into your testing harness. Because this repository is meant to be used by multiple programming languages, there are no affordances for auto-migrating your database (PRs welcome!). Use [schema.sql](https://github.com/endpoints/fantasy-database/blob/master/schema.sql) as a reference for building migrations, and [data.json](https://github.com/endpoints/fantasy-database/blob/master/data.json) for seeding if you'd like to test in something other than SQLite. + +#### Usage notes +- [Django](https://github.com/endpoints/fantasy-database/blob/master/django/README.md) diff --git a/django/README.md b/django/README.md new file mode 100644 index 0000000..0dd5771 --- /dev/null +++ b/django/README.md @@ -0,0 +1,35 @@ + +# fantasy-database + +> A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc. + +This test app for Django provides models, migrations, and fixtures that implement the fantasy-database. It's +recommended that app installation be limited to testing only. + +Example usage: + +In your `settings.py` module: + +```python + +# Testing +TESTING = len(sys.argv) > 1 and sys.argv[1] in ('test', 'testserver') + +if TESTING: + INSTALLED_APPS += ( + 'fantasy', + ) + +... +``` + +In a test module: +```python + +from django.test import TestCase + +class FantasyTests(TestCase): + fixtures = ['fantasy-database.json'] + ... + +``` diff --git a/setup.py b/setup.py index 7e3395a..8a4ce4b 100644 --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ def run_tests(self): setup( name='fantasy-database', version='2.0.0', - license='BSD License', + license='MIT', description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.', long_description=README, @@ -94,7 +94,7 @@ def run_tests(self): 'Environment :: Web Environment', 'Framework :: Django', 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', + 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', From 837f63e6e6ee3e47afb983f6b2f73a59c2df9ae1 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 20:39:04 -0400 Subject: [PATCH 05/15] Add timestamp fields --- django/fantasy/migrations/0001_initial.py | 27 +++++++++++++++++++++++ django/fantasy/models.py | 20 ++++++++++++----- django/utils.py | 14 ++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/django/fantasy/migrations/0001_initial.py b/django/fantasy/migrations/0001_initial.py index a5a4e5e..e9b6381 100644 --- a/django/fantasy/migrations/0001_initial.py +++ b/django/fantasy/migrations/0001_initial.py @@ -15,24 +15,36 @@ class Migration(migrations.Migration): name='Author', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=80)), ('date_of_birth', models.DateField()), ('date_of_death', models.DateField(null=True)), ], + options={ + 'abstract': False, + }, ), migrations.CreateModel( name='Book', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('title', models.CharField(max_length=80)), ('date_published', models.DateField()), ('author', models.ForeignKey(to='fantasy.Author')), ], + options={ + 'abstract': False, + }, ), migrations.CreateModel( name='Chapter', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('title', models.CharField(max_length=80)), ('ordering', models.PositiveIntegerField()), ('book', models.ForeignKey(to='fantasy.Book')), @@ -42,26 +54,41 @@ class Migration(migrations.Migration): name='Photo', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('title', models.CharField(max_length=80)), ('uri', models.URLField()), ('imageable_id', models.PositiveIntegerField()), ('imageable_type', models.ForeignKey(to='contenttypes.ContentType')), ], + options={ + 'abstract': False, + }, ), migrations.CreateModel( name='Series', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('title', models.CharField(max_length=80)), ], + options={ + 'abstract': False, + }, ), migrations.CreateModel( name='Store', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=80)), ('books', models.ManyToManyField(to='fantasy.Book')), ], + options={ + 'abstract': False, + }, ), migrations.AddField( model_name='book', diff --git a/django/fantasy/models.py b/django/fantasy/models.py index 9c8c0e0..7f5dedb 100644 --- a/django/fantasy/models.py +++ b/django/fantasy/models.py @@ -4,13 +4,21 @@ from django.contrib.contenttypes.models import ContentType -class Author(models.Model): +class TimestampedModel(models.Model): + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + class Meta: + abstract = True + + +class Author(TimestampedModel): name = models.CharField(max_length=80) date_of_birth = models.DateField() date_of_death = models.DateField(null=True) -class Series(models.Model): +class Series(TimestampedModel): title = models.CharField(max_length=80) photo = GenericRelation( 'fantasy.Photo', @@ -19,14 +27,14 @@ class Series(models.Model): ) -class Book(models.Model): +class Book(TimestampedModel): series = models.ForeignKey('fantasy.Series', null=True) author = models.ForeignKey('fantasy.Author') title = models.CharField(max_length=80) date_published = models.DateField() -class Chapter(models.Model): +class Chapter(TimestampedModel): title = models.CharField(max_length=80) book = models.ForeignKey('fantasy.Book') ordering = models.PositiveIntegerField() @@ -37,12 +45,12 @@ class Meta: ) -class Store(models.Model): +class Store(TimestampedModel): name = models.CharField(max_length=80) books = models.ManyToManyField('fantasy.Book') -class Photo(models.Model): +class Photo(TimestampedModel): title = models.CharField(max_length=80) uri = models.URLField() diff --git a/django/utils.py b/django/utils.py index 1ea0fb5..196cd03 100644 --- a/django/utils.py +++ b/django/utils.py @@ -1,4 +1,6 @@ +from datetime import datetime + def translate_fixture(data): """ @@ -10,6 +12,8 @@ def translate_fixture(data): results.append({ 'pk': author['id'], 'model': 'fantasy.author', 'fields': { + 'created_at': datetime.now().isoformat(), + 'updated_at': datetime.now().isoformat(), 'name': author['name'], 'date_of_birth': author['date_of_birth'], 'date_of_death': author['date_of_death'], @@ -20,6 +24,8 @@ def translate_fixture(data): results.append({ 'pk': series['id'], 'model': 'fantasy.series', 'fields': { + 'created_at': datetime.now().isoformat(), + 'updated_at': datetime.now().isoformat(), 'title': series['title'], } }) @@ -28,6 +34,8 @@ def translate_fixture(data): results.append({ 'pk': book['id'], 'model': 'fantasy.book', 'fields': { + 'created_at': datetime.now().isoformat(), + 'updated_at': datetime.now().isoformat(), 'series': book['series_id'], 'author': book['author_id'], 'title': book['title'], @@ -39,6 +47,8 @@ def translate_fixture(data): results.append({ 'pk': chapter['id'], 'model': 'fantasy.chapter', 'fields': { + 'created_at': datetime.now().isoformat(), + 'updated_at': datetime.now().isoformat(), 'title': chapter['title'], 'book': chapter['book_id'], 'ordering': chapter['ordering'], @@ -49,6 +59,8 @@ def translate_fixture(data): results.append({ 'pk': store['id'], 'model': 'fantasy.store', 'fields': { + 'created_at': datetime.now().isoformat(), + 'updated_at': datetime.now().isoformat(), 'name': store['name'], 'books': [sb['book_id'] for sb in data['books_stores'] if sb['store_id'] == store['id']], } @@ -64,6 +76,8 @@ def translate_fixture(data): results.append({ 'pk': photo['id'], 'model': 'fantasy.photo', 'fields': { + 'created_at': datetime.now().isoformat(), + 'updated_at': datetime.now().isoformat(), 'imageable_id': photo['imageable_id'], 'imageable_type': types_map[photo['imageable_type']], 'title': photo['title'], From e32aef9c11c61f26924755b176d9358b213aa299 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 20:45:28 -0400 Subject: [PATCH 06/15] Bump setuptools version to 2.0.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8a4ce4b..2e55b53 100644 --- a/setup.py +++ b/setup.py @@ -71,7 +71,7 @@ def run_tests(self): setup( name='fantasy-database', - version='2.0.0', + version='2.0.1', license='MIT', description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.', From dcd40e5ee5813ac6889c59f4f151fa562df509c5 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 1 Aug 2015 21:09:13 -0400 Subject: [PATCH 07/15] Use timzone aware datetimes --- django/tests/settings.py | 3 +++ django/utils.py | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/django/tests/settings.py b/django/tests/settings.py index 19ee684..a1194e8 100644 --- a/django/tests/settings.py +++ b/django/tests/settings.py @@ -21,3 +21,6 @@ ROOT_URLCONF = 'tests.urls' + + +USE_TZ = True diff --git a/django/utils.py b/django/utils.py index 196cd03..e73059b 100644 --- a/django/utils.py +++ b/django/utils.py @@ -1,5 +1,6 @@ from datetime import datetime +from django.utils import timezone def translate_fixture(data): @@ -7,13 +8,14 @@ def translate_fixture(data): Translate the contents of the `data.json` file into a django compatible fixture. """ results = [] + now = datetime.now().replace(tzinfo=timezone.UTC()).isoformat() for author in data['authors']: results.append({ 'pk': author['id'], 'model': 'fantasy.author', 'fields': { - 'created_at': datetime.now().isoformat(), - 'updated_at': datetime.now().isoformat(), + 'created_at': now, + 'updated_at': now, 'name': author['name'], 'date_of_birth': author['date_of_birth'], 'date_of_death': author['date_of_death'], @@ -24,8 +26,8 @@ def translate_fixture(data): results.append({ 'pk': series['id'], 'model': 'fantasy.series', 'fields': { - 'created_at': datetime.now().isoformat(), - 'updated_at': datetime.now().isoformat(), + 'created_at': now, + 'updated_at': now, 'title': series['title'], } }) @@ -34,8 +36,8 @@ def translate_fixture(data): results.append({ 'pk': book['id'], 'model': 'fantasy.book', 'fields': { - 'created_at': datetime.now().isoformat(), - 'updated_at': datetime.now().isoformat(), + 'created_at': now, + 'updated_at': now, 'series': book['series_id'], 'author': book['author_id'], 'title': book['title'], @@ -47,8 +49,8 @@ def translate_fixture(data): results.append({ 'pk': chapter['id'], 'model': 'fantasy.chapter', 'fields': { - 'created_at': datetime.now().isoformat(), - 'updated_at': datetime.now().isoformat(), + 'created_at': now, + 'updated_at': now, 'title': chapter['title'], 'book': chapter['book_id'], 'ordering': chapter['ordering'], @@ -59,8 +61,8 @@ def translate_fixture(data): results.append({ 'pk': store['id'], 'model': 'fantasy.store', 'fields': { - 'created_at': datetime.now().isoformat(), - 'updated_at': datetime.now().isoformat(), + 'created_at': now, + 'updated_at': now, 'name': store['name'], 'books': [sb['book_id'] for sb in data['books_stores'] if sb['store_id'] == store['id']], } @@ -76,8 +78,8 @@ def translate_fixture(data): results.append({ 'pk': photo['id'], 'model': 'fantasy.photo', 'fields': { - 'created_at': datetime.now().isoformat(), - 'updated_at': datetime.now().isoformat(), + 'created_at': now, + 'updated_at': now, 'imageable_id': photo['imageable_id'], 'imageable_type': types_map[photo['imageable_type']], 'title': photo['title'], From 072fbe8172e971b683c1adfc892c276a24065a97 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 2 Aug 2015 15:07:21 -0400 Subject: [PATCH 08/15] Fix package and fixture installation issues - `find_packages()` does not respect `package_dir` and needs to be explicitly told to search a sub directory package. - `install` and `develop` were generating the fixture in the /tmp directory, but the files were not copied to the target directory. - The `test` command on python 2 uses an 'in place' install of the package, so the build_py phase is never executed. It's necessary for the test command to manually build the fixture before execution. --- setup.py | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index 2e55b53..c25187b 100644 --- a/setup.py +++ b/setup.py @@ -2,8 +2,7 @@ import sys import json from setuptools import setup, find_packages -from setuptools.command.develop import develop -from setuptools.command.install import install +from setuptools.command.build_py import build_py from setuptools.command.test import test @@ -17,31 +16,39 @@ sys.path.append(os.path.join(BASE_DIR, 'django')) -def build_fixture(): +def build_fixture(input_path, output_path): from utils import translate_fixture contents = None - with open(os.path.join(BASE_DIR, 'data.json')) as f: - contents = json.loads(f.read()) + with open(input_path) as infile: + contents = json.loads(infile.read()) + print BASE_DIR contents = translate_fixture(contents) - with open(os.path.join(BASE_DIR, 'django/fantasy/fixtures/fantasy-database.json'), 'w') as f: - f.write(json.dumps(contents)) + with open(output_path, 'w') as outfile: + outfile.write(json.dumps(contents)) -class Develop(develop): +class BuildPy(build_py): + # adapted from: + # http://www.digip.org/blog/2011/01/generating-data-files-in-setup.py.html def run(self): - develop.run(self) - build_fixture() + # honor the --dry-run flag + if not self.dry_run: + target_dir = os.path.join(self.build_lib, 'fantasy/fixtures') + # mkpath is a distutils helper to create directories + self.mkpath(target_dir) -class Install(install): + input_path = os.path.join(BASE_DIR, 'data.json') + output_path = os.path.join(target_dir, 'fantasy-database.json') - def run(self): - install.run(self) - build_fixture() + build_fixture(input_path, output_path) + + # distutils uses old-style classes, so no super() + build_py.run(self) class Test(test): @@ -62,7 +69,14 @@ def finalize_options(self): def run_tests(self): from tests.runner import main - build_fixture() + + # We still need to build the fixture manually during test, since + # setuptools runs tests on PY2 'in place'. + target_dir = os.path.join(BASE_DIR, 'django/fantasy/fixtures') + build_fixture( + os.path.join(BASE_DIR, 'data.json'), + os.path.join(target_dir, 'fantasy-database.json') + ) test_labels = self.test_labels.split() djtest_args = self.djtest_args.split() @@ -78,14 +92,14 @@ def run_tests(self): long_description=README, url='https://github.com/tkellen/fantasy-database', author='Tyler Kellen', + author_email='tyler@sleekcode.net', package_dir={'': 'django'}, - packages=find_packages(), + packages=find_packages('django', exclude=['tests']), tests_require=['django>=1.7'], cmdclass={ - 'develop': Develop, - 'install': Install, + 'build_py': BuildPy, 'test': Test, }, From dc8bfc4f650e0009327b639b03e56de2afb1c556 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 2 Aug 2015 17:27:03 -0400 Subject: [PATCH 09/15] Restructure into python.django_fantasy subpackage --- README.md | 2 +- django/tests/__init__.py | 0 {django => python}/README.md | 5 ++- python/django_fantasy/__init__.py | 2 ++ python/django_fantasy/apps.py | 8 +++++ .../fixtures/fantasy-database.json | 0 .../migrations/0001_initial.py | 0 .../django_fantasy/migrations}/__init__.py | 0 .../django_fantasy}/models.py | 0 .../migrations => python/tests}/__init__.py | 0 {django => python}/tests/runner.py | 4 +-- {django => python}/tests/settings.py | 2 +- .../tests/test_django.py | 2 +- {django => python}/tests/urls.py | 0 {django => python}/utils.py | 31 ++++++++++++++++--- setup.py | 18 +++++------ 16 files changed, 55 insertions(+), 19 deletions(-) delete mode 100644 django/tests/__init__.py rename {django => python}/README.md (94%) create mode 100644 python/django_fantasy/__init__.py create mode 100644 python/django_fantasy/apps.py rename {django/fantasy => python/django_fantasy}/fixtures/fantasy-database.json (100%) rename {django/fantasy => python/django_fantasy}/migrations/0001_initial.py (100%) rename {django/fantasy => python/django_fantasy/migrations}/__init__.py (100%) rename {django/fantasy => python/django_fantasy}/models.py (100%) rename {django/fantasy/migrations => python/tests}/__init__.py (100%) rename {django => python}/tests/runner.py (86%) rename {django => python}/tests/settings.py (94%) rename django/tests/test_fixture.py => python/tests/test_django.py (91%) rename {django => python}/tests/urls.py (100%) rename {django => python}/utils.py (83%) diff --git a/README.md b/README.md index 1d58d43..7c506cd 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ Make this repository a dependency of your project and automate the process of co Because this repository is meant to be used by multiple programming languages, there are no affordances for auto-migrating your database (PRs welcome!). Use [schema.sql](https://github.com/endpoints/fantasy-database/blob/master/schema.sql) as a reference for building migrations, and [data.json](https://github.com/endpoints/fantasy-database/blob/master/data.json) for seeding if you'd like to test in something other than SQLite. #### Usage notes -- [Django](https://github.com/endpoints/fantasy-database/blob/master/django/README.md) +- [Python](https://github.com/endpoints/fantasy-database/blob/master/python/README.md) diff --git a/django/tests/__init__.py b/django/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django/README.md b/python/README.md similarity index 94% rename from django/README.md rename to python/README.md index 0dd5771..7073960 100644 --- a/django/README.md +++ b/python/README.md @@ -3,6 +3,9 @@ > A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc. + +## Django + This test app for Django provides models, migrations, and fixtures that implement the fantasy-database. It's recommended that app installation be limited to testing only. @@ -17,7 +20,7 @@ TESTING = len(sys.argv) > 1 and sys.argv[1] in ('test', 'testserver') if TESTING: INSTALLED_APPS += ( - 'fantasy', + 'django_fantasy', ) ... diff --git a/python/django_fantasy/__init__.py b/python/django_fantasy/__init__.py new file mode 100644 index 0000000..15682dc --- /dev/null +++ b/python/django_fantasy/__init__.py @@ -0,0 +1,2 @@ + +default_app_config = 'django_fantasy.apps.FantasyConfig' diff --git a/python/django_fantasy/apps.py b/python/django_fantasy/apps.py new file mode 100644 index 0000000..de3481a --- /dev/null +++ b/python/django_fantasy/apps.py @@ -0,0 +1,8 @@ + +from django.apps import AppConfig + + +class FantasyConfig(AppConfig): + name = 'django_fantasy' + label = 'fantasy' + verbose_name = "Fantasy Database" diff --git a/django/fantasy/fixtures/fantasy-database.json b/python/django_fantasy/fixtures/fantasy-database.json similarity index 100% rename from django/fantasy/fixtures/fantasy-database.json rename to python/django_fantasy/fixtures/fantasy-database.json diff --git a/django/fantasy/migrations/0001_initial.py b/python/django_fantasy/migrations/0001_initial.py similarity index 100% rename from django/fantasy/migrations/0001_initial.py rename to python/django_fantasy/migrations/0001_initial.py diff --git a/django/fantasy/__init__.py b/python/django_fantasy/migrations/__init__.py similarity index 100% rename from django/fantasy/__init__.py rename to python/django_fantasy/migrations/__init__.py diff --git a/django/fantasy/models.py b/python/django_fantasy/models.py similarity index 100% rename from django/fantasy/models.py rename to python/django_fantasy/models.py diff --git a/django/fantasy/migrations/__init__.py b/python/tests/__init__.py similarity index 100% rename from django/fantasy/migrations/__init__.py rename to python/tests/__init__.py diff --git a/django/tests/runner.py b/python/tests/runner.py similarity index 86% rename from django/tests/runner.py rename to python/tests/runner.py index e570259..3b183a3 100644 --- a/django/tests/runner.py +++ b/python/tests/runner.py @@ -6,11 +6,11 @@ base = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) # add test eggs to path -eggs = os.path.join(base, ".eggs/*.egg") +eggs = os.path.join(base, "*.egg") sys.path += glob.glob(eggs) # also add parent directory to path (to find tests) -pkg_base = os.path.join(base, 'django') +pkg_base = os.path.join(base, 'python') sys.path.append(pkg_base) os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' diff --git a/django/tests/settings.py b/python/tests/settings.py similarity index 94% rename from django/tests/settings.py rename to python/tests/settings.py index a1194e8..a698e19 100644 --- a/django/tests/settings.py +++ b/python/tests/settings.py @@ -15,7 +15,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'fantasy', + 'django_fantasy', 'tests', ) diff --git a/django/tests/test_fixture.py b/python/tests/test_django.py similarity index 91% rename from django/tests/test_fixture.py rename to python/tests/test_django.py index b323bcf..ce39862 100644 --- a/django/tests/test_fixture.py +++ b/python/tests/test_django.py @@ -1,6 +1,6 @@ from django.test import TestCase -from fantasy import models +from django_fantasy import models class FixtureTest(TestCase): diff --git a/django/tests/urls.py b/python/tests/urls.py similarity index 100% rename from django/tests/urls.py rename to python/tests/urls.py diff --git a/django/utils.py b/python/utils.py similarity index 83% rename from django/utils.py rename to python/utils.py index e73059b..153c441 100644 --- a/django/utils.py +++ b/python/utils.py @@ -1,14 +1,37 @@ -from datetime import datetime -from django.utils import timezone +from datetime import datetime, timedelta, tzinfo -def translate_fixture(data): +# copied from django.utils.timezone +ZERO = timedelta(0) + + +class UTC(tzinfo): + """ + UTC implementation taken from Python's docs. + Used only when pytz isn't available. + """ + + def __repr__(self): + return "" + + def utcoffset(self, dt): + return ZERO + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return ZERO + + +def translate_django_fixture(data): """ Translate the contents of the `data.json` file into a django compatible fixture. """ + results = [] - now = datetime.now().replace(tzinfo=timezone.UTC()).isoformat() + now = datetime.now().replace(tzinfo=UTC()).isoformat() for author in data['authors']: results.append({ diff --git a/setup.py b/setup.py index c25187b..b4bd2a5 100644 --- a/setup.py +++ b/setup.py @@ -6,25 +6,25 @@ from setuptools.command.test import test -README = open(os.path.join(os.path.dirname(__file__), 'django/README.md')).read() +README = open(os.path.join(os.path.dirname(__file__), 'python/README.md')).read() # allow setup.py to be run from any path os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) -# append the django directory to our path so we can import utils +# append the python directory to our path so we can import utils BASE_DIR = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(os.path.join(BASE_DIR, 'django')) +sys.path.append(os.path.join(BASE_DIR, 'python')) def build_fixture(input_path, output_path): - from utils import translate_fixture + from utils import translate_django_fixture contents = None with open(input_path) as infile: contents = json.loads(infile.read()) print BASE_DIR - contents = translate_fixture(contents) + contents = translate_django_fixture(contents) with open(output_path, 'w') as outfile: outfile.write(json.dumps(contents)) @@ -37,7 +37,7 @@ class BuildPy(build_py): def run(self): # honor the --dry-run flag if not self.dry_run: - target_dir = os.path.join(self.build_lib, 'fantasy/fixtures') + target_dir = os.path.join(self.build_lib, 'django_fantasy/fixtures') # mkpath is a distutils helper to create directories self.mkpath(target_dir) @@ -72,7 +72,7 @@ def run_tests(self): # We still need to build the fixture manually during test, since # setuptools runs tests on PY2 'in place'. - target_dir = os.path.join(BASE_DIR, 'django/fantasy/fixtures') + target_dir = os.path.join(BASE_DIR, 'python/django_fantasy/fixtures') build_fixture( os.path.join(BASE_DIR, 'data.json'), os.path.join(target_dir, 'fantasy-database.json') @@ -93,8 +93,8 @@ def run_tests(self): url='https://github.com/tkellen/fantasy-database', author='Tyler Kellen', author_email='tyler@sleekcode.net', - package_dir={'': 'django'}, - packages=find_packages('django', exclude=['tests']), + package_dir={'': 'python'}, + packages=find_packages('python', exclude=['tests']), tests_require=['django>=1.7'], From 3f783fad02360cf70037d2d0340244baa41d9e41 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 2 Aug 2015 21:31:02 -0400 Subject: [PATCH 10/15] Modify test command to not build module 'in place' --- README.md | 2 +- python/setup_commands.py | 102 +++++++++++++++++++++++++++++++++++++++ setup.py | 71 ++------------------------- 3 files changed, 107 insertions(+), 68 deletions(-) create mode 100644 python/setup_commands.py diff --git a/README.md b/README.md index 7c506cd..afe9910 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ Make this repository a dependency of your project and automate the process of co Because this repository is meant to be used by multiple programming languages, there are no affordances for auto-migrating your database (PRs welcome!). Use [schema.sql](https://github.com/endpoints/fantasy-database/blob/master/schema.sql) as a reference for building migrations, and [data.json](https://github.com/endpoints/fantasy-database/blob/master/data.json) for seeding if you'd like to test in something other than SQLite. #### Usage notes -- [Python](https://github.com/endpoints/fantasy-database/blob/master/python/README.md) +- [Python](python) diff --git a/python/setup_commands.py b/python/setup_commands.py new file mode 100644 index 0000000..7bafafd --- /dev/null +++ b/python/setup_commands.py @@ -0,0 +1,102 @@ + +import os +import sys +import json +from setuptools.command.build_py import build_py +from setuptools.command.test import test + +BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') + + +def build_fixture(input_path, output_path): + from utils import translate_django_fixture + + contents = None + with open(input_path) as infile: + contents = json.loads(infile.read()) + print BASE_DIR + + contents = translate_django_fixture(contents) + + with open(output_path, 'w') as outfile: + outfile.write(json.dumps(contents)) + + +class BuildPy(build_py): + + # adapted from: + # http://www.digip.org/blog/2011/01/generating-data-files-in-setup.py.html + def run(self): + # honor the --dry-run flag + if not self.dry_run: + target_dir = os.path.join(self.build_lib, 'django_fantasy/fixtures') + + # mkpath is a distutils helper to create directories + self.mkpath(target_dir) + + input_path = os.path.join(BASE_DIR, 'data.json') + output_path = os.path.join(target_dir, 'fantasy-database.json') + + build_fixture(input_path, output_path) + + # distutils uses old-style classes, so no super() + build_py.run(self) + + +class Test(test): + user_options = [ + ('test-labels=', 'l', "Test labels to pass to runner.py test"), + ('djtest-args=', 'a', "Arguments to pass to runner.py test"), + ] + + def initialize_options(self): + test.initialize_options(self) + self.test_labels = 'tests' + self.djtest_args = '' + + def finalize_options(self): + test.finalize_options(self) + self.test_args = [] + self.test_suite = True + + # This is almost a direct copy of the original method. The difference is + # that this method only performs a non-'inplace' build. + def with_project_on_sys_path(self, func): + from pkg_resources import * + + # Ensure metadata is up-to-date + self.reinitialize_command('build_py', inplace=0) + self.run_command('build_py') + bpy_cmd = self.get_finalized_command("build_py") + build_path = normalize_path(bpy_cmd.build_lib) + + # Build extensions + self.reinitialize_command('egg_info', egg_base=build_path) + self.run_command('egg_info') + + self.reinitialize_command('build_ext', inplace=0) + self.run_command('build_ext') + + ei_cmd = self.get_finalized_command("egg_info") + + old_path = sys.path[:] + old_modules = sys.modules.copy() + + try: + sys.path.insert(0, normalize_path(ei_cmd.egg_base)) + working_set.__init__() + add_activation_listener(lambda dist: dist.activate()) + require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version)) + func() + finally: + sys.path[:] = old_path + sys.modules.clear() + sys.modules.update(old_modules) + working_set.__init__() + + def run_tests(self): + from tests.runner import main + + test_labels = self.test_labels.split() + djtest_args = self.djtest_args.split() + main(['runner.py', 'test'] + test_labels + djtest_args) diff --git a/setup.py b/setup.py index b4bd2a5..2577516 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,6 @@ import os import sys -import json from setuptools import setup, find_packages -from setuptools.command.build_py import build_py -from setuptools.command.test import test README = open(os.path.join(os.path.dirname(__file__), 'python/README.md')).read() @@ -16,71 +13,11 @@ sys.path.append(os.path.join(BASE_DIR, 'python')) -def build_fixture(input_path, output_path): - from utils import translate_django_fixture +def get_commands(): + from setup_commands import Test, BuildPy + return Test, BuildPy - contents = None - with open(input_path) as infile: - contents = json.loads(infile.read()) - print BASE_DIR - - contents = translate_django_fixture(contents) - - with open(output_path, 'w') as outfile: - outfile.write(json.dumps(contents)) - - -class BuildPy(build_py): - - # adapted from: - # http://www.digip.org/blog/2011/01/generating-data-files-in-setup.py.html - def run(self): - # honor the --dry-run flag - if not self.dry_run: - target_dir = os.path.join(self.build_lib, 'django_fantasy/fixtures') - - # mkpath is a distutils helper to create directories - self.mkpath(target_dir) - - input_path = os.path.join(BASE_DIR, 'data.json') - output_path = os.path.join(target_dir, 'fantasy-database.json') - - build_fixture(input_path, output_path) - - # distutils uses old-style classes, so no super() - build_py.run(self) - - -class Test(test): - user_options = [ - ('test-labels=', 'l', "Test labels to pass to runner.py test"), - ('djtest-args=', 'a', "Arguments to pass to runner.py test"), - ] - - def initialize_options(self): - test.initialize_options(self) - self.test_labels = 'tests' - self.djtest_args = '' - - def finalize_options(self): - test.finalize_options(self) - self.test_args = [] - self.test_suite = True - - def run_tests(self): - from tests.runner import main - - # We still need to build the fixture manually during test, since - # setuptools runs tests on PY2 'in place'. - target_dir = os.path.join(BASE_DIR, 'python/django_fantasy/fixtures') - build_fixture( - os.path.join(BASE_DIR, 'data.json'), - os.path.join(target_dir, 'fantasy-database.json') - ) - - test_labels = self.test_labels.split() - djtest_args = self.djtest_args.split() - main(['runner.py', 'test'] + test_labels + djtest_args) +Test, BuildPy = get_commands() setup( From 68c88189d68b51186f9fb65f4abc58250d87f4ec Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Wed, 2 Sep 2015 13:05:18 -0400 Subject: [PATCH 11/15] Fix source dist --- MANIFEST.in | 3 ++- setup.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index e4455d3..07fdb04 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include LICENSE include README.md -include data.json \ No newline at end of file +include python/README.md +include data.json diff --git a/setup.py b/setup.py index 2577516..c851a31 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ def get_commands(): author='Tyler Kellen', author_email='tyler@sleekcode.net', package_dir={'': 'python'}, + py_modules=['setup_commands', 'utils'], packages=find_packages('python', exclude=['tests']), tests_require=['django>=1.7'], From 2f3cfcf59e2d54bc776260a0d1534c6c1581f808 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Fri, 11 Mar 2016 02:05:12 -0500 Subject: [PATCH 12/15] Add universal wheel --- setup.cfg | 2 ++ setup.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2a9acf1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal = 1 diff --git a/setup.py b/setup.py index c851a31..9ba9426 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def get_commands(): setup( name='fantasy-database', - version='2.0.1', + version='2.0.2', license='MIT', description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.', From e7cc84fc91e3046ac189658ac5c9ca540e8bc190 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Fri, 11 Mar 2016 02:05:40 -0500 Subject: [PATCH 13/15] Fix setup cmd base directory --- python/setup_commands.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/setup_commands.py b/python/setup_commands.py index 7bafafd..ce75bc3 100644 --- a/python/setup_commands.py +++ b/python/setup_commands.py @@ -5,7 +5,7 @@ from setuptools.command.build_py import build_py from setuptools.command.test import test -BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') +BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) def build_fixture(input_path, output_path): diff --git a/setup.py b/setup.py index 9ba9426..f4b3812 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def get_commands(): setup( name='fantasy-database', - version='2.0.2', + version='2.0.3', license='MIT', description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.', From 3ebb05197a19ee8fe0fd11ced9e1d6e22e082545 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 13 Mar 2016 22:03:46 -0400 Subject: [PATCH 14/15] Remove errant print statement --- python/setup_commands.py | 1 - setup.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/python/setup_commands.py b/python/setup_commands.py index ce75bc3..cf80ce5 100644 --- a/python/setup_commands.py +++ b/python/setup_commands.py @@ -14,7 +14,6 @@ def build_fixture(input_path, output_path): contents = None with open(input_path) as infile: contents = json.loads(infile.read()) - print BASE_DIR contents = translate_django_fixture(contents) diff --git a/setup.py b/setup.py index f4b3812..e0dce10 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def get_commands(): setup( name='fantasy-database', - version='2.0.3', + version='2.0.3-post.1', license='MIT', description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.', From fff5488c0066d7d48521469f63bcefc003f89865 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sun, 13 Mar 2016 23:29:38 -0400 Subject: [PATCH 15/15] Explicitly import pkg_resources (py3k compat) --- python/setup_commands.py | 4 +++- setup.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/setup_commands.py b/python/setup_commands.py index cf80ce5..6ec85e6 100644 --- a/python/setup_commands.py +++ b/python/setup_commands.py @@ -61,7 +61,9 @@ def finalize_options(self): # This is almost a direct copy of the original method. The difference is # that this method only performs a non-'inplace' build. def with_project_on_sys_path(self, func): - from pkg_resources import * + from pkg_resources import ( + normalize_path, working_set, add_activation_listener, require + ) # Ensure metadata is up-to-date self.reinitialize_command('build_py', inplace=0) diff --git a/setup.py b/setup.py index e0dce10..7a52ec8 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def get_commands(): setup( name='fantasy-database', - version='2.0.3-post.1', + version='2.0.3-post.2', license='MIT', description='A database with a few fantasy books in it for testing query builders, orms, rest frameworks, etc.',