Skip to content

Commit d7469e9

Browse files
authored
Add python2 support (#2)
1 parent 27a1ecd commit d7469e9

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ language: python
33
matrix:
44
include:
55
- python: 3.5
6+
- python: 2.7
67

78
install:
89
- pip install numpy Pillow tqdm
10+
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
11+
pip install backports.tempfile;
12+
fi
913
- python setup.py install
1014
- pip install flake8 coveralls pytest-cov
1115

1216
# command to run tests
1317
script:
14-
- py.test --cov image_dataset_viz --cov-report term-missing
1518
- flake8
19+
- py.test --cov image_dataset_viz --cov-report term-missing
20+
1621

1722
after_success:
1823
- coveralls

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
Observe dataset of images and targets in few shots
77

8-
**Python 3 only**
9-
108
![VEDAI example](examples/vedai_example.png)
119

1210
## Descriptions
@@ -18,11 +16,11 @@ in few shots.
1816
## Installation
1917

2018
```bash
21-
python3 setup.py install
19+
python setup.py install
2220
```
2321
or
2422
```bash
25-
pip3 install git+https://github.com/vfdev-5/ImageDatasetViz.git
23+
pip install git+https://github.com/vfdev-5/ImageDatasetViz.git
2624
```
2725

2826
## Usage
@@ -79,6 +77,7 @@ def read_img_fn(img_filepath):
7977
```
8078
and let's say the annotations are just lines with points and a label, e.g. `12 23 34 45 56 67 car`
8179
```python
80+
from pathlib import Path
8281
import numpy as np
8382

8483
def read_target_fn(target_filepath):

image_dataset_viz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
__version__ = '0.1'
33

4-
from .dataset_exporter import DatasetExporter, render_datapoint
4+
from image_dataset_viz.dataset_exporter import DatasetExporter, render_datapoint

image_dataset_viz/dataset_exporter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
from __future__ import division
12
import sys
2-
from pathlib import Path
3+
4+
try:
5+
from pathlib import Path
6+
except ImportError:
7+
from pathlib2 import Path
38

49
import numpy as np
510
from PIL import ImageDraw, ImageFont, Image

setup.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
from codecs import open as codecs_open
1+
import os
2+
import io
3+
import re
24
from setuptools import setup, find_packages
3-
from image_dataset_viz import __version__
45

56

6-
# Get the long description from the relevant file
7-
with codecs_open('README.md', encoding='utf-8') as f:
8-
long_description = f.read()
7+
def read(*names, **kwargs):
8+
with io.open(os.path.join(os.path.dirname(__file__), *names),
9+
encoding=kwargs.get("encoding", "utf8")) as fp:
10+
return fp.read()
11+
12+
13+
def find_version(*file_paths):
14+
version_file = read(*file_paths)
15+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
16+
if version_match:
17+
return version_match.group(1)
18+
raise RuntimeError("Unable to find version string.")
19+
20+
21+
long_description = read("README.md")
22+
version = find_version('image_dataset_viz', '__init__.py')
923

1024

1125
setup(
1226
name="image_dataset_viz",
13-
version=__version__,
27+
version=version,
1428
description=u"Observe dataset of images and targets in few shots",
1529
long_description=long_description,
1630
author="vfdev-5",
@@ -19,7 +33,8 @@
1933
install_requires=[
2034
'numpy',
2135
'Pillow',
22-
'tqdm'
36+
'tqdm',
37+
'pathlib2;python_version<"3"'
2338
],
2439
license='MIT',
2540
test_suite="tests",

tests/test_dataset_exporter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

2-
import tempfile
3-
from pathlib import Path
2+
import sys
3+
4+
if sys.version_info[0] < 3:
5+
from backports import tempfile
6+
from pathlib2 import Path
7+
else:
8+
import tempfile
9+
from pathlib import Path
410

511
from unittest import TestCase, main
612

0 commit comments

Comments
 (0)