Skip to content

Commit 546888b

Browse files
committed
A few more changes for v2.3.3
1 parent 48ad2ac commit 546888b

File tree

8 files changed

+444
-21
lines changed

8 files changed

+444
-21
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ cache:
77

88
python:
99
- "2.7"
10-
- "3.4"
1110
- "3.5"
1211
- "3.6"
1312

Pipfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[[source]]
2+
url = "https://pypi.python.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
Django = "*"
8+
"psycopg2" = "*"
9+
Sphinx = "*"
10+
sphinx-autobuild = "*"
11+
twine = "*"
12+
"flake8" = "*"
13+
coverage = "*"
14+
python-coveralls = "*"
15+
tox = "*"
16+
17+
[dev-packages]
18+
19+
[requires]
20+
python_version = "3.6"

Pipfile.lock

Lines changed: 401 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ The ``to_csv`` manager method only requires one argument, the path to where the
461461
================= =========================================================
462462
Argument Description
463463
================= =========================================================
464-
``csv_path`` The path to a file to write out the CSV. Optional.
465-
If you don't provide one, the comma-delimited data is
466-
returned as a string.
464+
``csv_path`` The path to a file to write out the CSV. Also accepts
465+
file-like objects. Optional. If you don't provide one,
466+
the comma-delimited data is returned as a string.
467467

468468
``fields`` Strings corresponding to the model fields to be exported.
469469
All fields on the model are exported by default. Fields

postgres_copy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .copy_from import CopyMapping
44
from .copy_to import SQLCopyToCompiler, CopyToQuery
55
from .managers import CopyManager, CopyQuerySet
6-
__version__ = '2.3.2'
6+
__version__ = '2.3.3'
77

88

99
__all__ = (

postgres_copy/copy_to.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def setup_query(self):
3434
)
3535
self.select.append(selection)
3636

37-
def execute_sql(self, csv_path=None):
37+
def execute_sql(self, csv_path_or_obj=None):
3838
"""
3939
Run the COPY TO query.
4040
"""
41-
logger.debug("Copying data to {}".format(csv_path))
41+
logger.debug("Copying data to {}".format(csv_path_or_obj))
4242

4343
# adapt SELECT query parameters to SQL syntax
4444
params = self.as_sql()[1]
@@ -67,12 +67,12 @@ def execute_sql(self, csv_path=None):
6767
logger.debug(copy_to_sql)
6868

6969
# If a file-like object was provided, write it out there.
70-
if hasattr(csv_path, 'write'):
71-
c.cursor.copy_expert(copy_to_sql, csv_path)
70+
if hasattr(csv_path_or_obj, 'write'):
71+
c.cursor.copy_expert(copy_to_sql, csv_path_or_obj)
7272
return
7373
# If a file path was provided, write it out there.
74-
elif csv_path:
75-
with open(csv_path, 'wb') as stdout:
74+
elif csv_path_or_obj:
75+
with open(csv_path_or_obj, 'wb') as stdout:
7676
c.cursor.copy_expert(copy_to_sql, stdout)
7777
return
7878
# If there's no csv_path, return the output as a string.

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def run(self):
7272

7373
setup(
7474
name='django-postgres-copy',
75-
version='2.3.2',
75+
version='2.3.3',
7676
description="Quickly import and export delimited data with Django support for PostgreSQL's COPY command",
7777
author='Ben Welsh',
7878
author_email='ben.welsh@gmail.com',
@@ -85,7 +85,6 @@ def run(self):
8585
'Development Status :: 5 - Production/Stable',
8686
'Programming Language :: Python',
8787
'Programming Language :: Python :: 2.7',
88-
'Programming Language :: Python :: 3.4',
8988
'Programming Language :: Python :: 3.5',
9089
'Programming Language :: Python :: 3.6',
9190
'Framework :: Django',

tests/tests.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import io
12
import os
23
import csv
34
from datetime import date
4-
import io
55
from .models import (
66
MockObject,
77
MockFKObject,
@@ -49,7 +49,10 @@ class PostgresCopyToTest(BaseTest):
4949
def setUp(self):
5050
super(PostgresCopyToTest, self).setUp()
5151
self.export_path = os.path.join(os.path.dirname(__file__), 'export.csv')
52-
self.export_file = io.StringIO()
52+
self.export_files = [
53+
io.StringIO(),
54+
io.BytesIO()
55+
]
5356

5457
def tearDown(self):
5558
super(PostgresCopyToTest, self).tearDown()
@@ -74,12 +77,13 @@ def test_export(self):
7477

7578
def test_export_to_file(self):
7679
self._load_objects(self.name_path)
77-
MockObject.objects.to_csv(self.export_file)
78-
reader = csv.DictReader(self.export_file)
79-
self.assertTrue(
80-
['BEN', 'JOE', 'JANE'],
81-
[i['name'] for i in reader]
82-
)
80+
for f in self.export_files:
81+
MockObject.objects.to_csv(f)
82+
reader = csv.DictReader(f)
83+
self.assertTrue(
84+
['BEN', 'JOE', 'JANE'],
85+
[i['name'] for i in reader]
86+
)
8387

8488
def test_export_to_str(self):
8589
self._load_objects(self.name_path)

0 commit comments

Comments
 (0)