Skip to content

Commit 9c41a99

Browse files
Update resources to load for pypi builds.
1 parent 5ccc7fb commit 9c41a99

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
.. figure:: verto/images/verto-logo.png
2-
:alt: Verto Logo
1+
|Verto Image|
32

43
|Build Status| |Code Climate Status|
54

@@ -52,3 +51,7 @@ The changelog is available within the `documentation`_.
5251
.. |Code Climate Status| image:: https://codeclimate.com/github/uccser/verto/badges/gpa.svg
5352
:target: https://codeclimate.com/github/uccser/verto
5453
:alt: Code Climate
54+
55+
.. |Verto Image| image:: https://raw.githubusercontent.com/uccser/verto/master/verto/images/verto-logo.png
56+
:target: https://github.com/uccser/verto
57+
:alt: Verto GitHub

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ markdown==2.6.8
33
beautifulsoup4==4.5.3
44
Jinja2==2.9.6
55
python-slugify==1.2.2
6+
pkg_resources
67

78
# Required dependencies for building documentation
89
sphinx==1.5.5

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
long_description=open('README.rst').read(),
1313
url='https://github.com/uccser/verto',
1414
author='University of Canterbury Computer Science Education Research Group',
15+
author_email='csse-education-research@canterbury.ac.nz',
1516
license='MIT',
1617
classifiers=[
1718
'Development Status :: 3 - Alpha',
@@ -25,13 +26,13 @@
2526
'Topic :: Text Processing :: Markup',
2627
'Topic :: Text Processing :: Markup :: HTML'
2728
],
29+
keywords='markdown verto development textbook converter media richtext interactive education html book author extension',
2830
packages=find_packages(),
2931
include_package_data=True,
3032
install_requires=[
3133
'markdown>=2.6.8',
32-
'bs4>=0.0.1',
33-
'Jinja2>=2.9.5',
34-
'python-slugify>=1.2.1'
35-
],
36-
zip_safe=False
34+
'beautifulsoup4==4.5.3',
35+
'Jinja2>=2.9.6',
36+
'python-slugify>=1.2.2'
37+
]
3738
)

verto/VertoExtension.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import json
3333

3434
from jinja2 import Environment, PackageLoader, select_autoescape
35+
import pkg_resources
3536

3637

3738
class VertoExtension(Extension):
@@ -204,7 +205,7 @@ def loadProcessorInfo(self):
204205
Returns:
205206
The json object of the file where objects are ordered dictionaries.
206207
'''
207-
json_data = open(os.path.join(os.path.dirname(__file__), 'processor-info.json')).read()
208+
json_data = pkg_resources.resource_string('verto', 'processor-info.json').decode('utf-8')
208209
return json.loads(json_data, object_pairs_hook=OrderedDict)
209210

210211
def get_heading_tree(self):

verto/tests/BaseTest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import unittest
2+
import pkg_resources
3+
24

35
class BaseTest(unittest.TestCase):
46
'''A base test class for individual test classes.'''
@@ -11,7 +13,7 @@ def __init__(self, *args, **kwargs):
1113
test failures.
1214
'''
1315
unittest.TestCase.__init__(self, *args, **kwargs)
14-
self.test_file_path = 'verto/tests/assets/{test_type}/{filename}'
16+
self.test_file_path = 'tests/assets/{test_type}/{filename}'
1517
self.maxDiff = None
1618

1719
def read_test_file(self, test_type, filename, strip=False):
@@ -20,8 +22,7 @@ def read_test_file(self, test_type, filename, strip=False):
2022
This function reads a file from a given filename in UTF-8 encoding.
2123
'''
2224
file_path = self.test_file_path.format(test_type=test_type, filename=filename)
23-
file_object = open(file_path, encoding='utf-8')
24-
text = file_object.read()
25+
text = pkg_resources.resource_string('verto', file_path).decode('utf-8')
2526
if strip:
2627
text = text.rstrip('\r\n')
2728
return text

verto/tests/ProcessorTest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import pkg_resources
23
import json
34
import markdown
45
from verto.VertoExtension import VertoExtension
@@ -36,7 +37,7 @@ def loadJinjaTemplate(self, template):
3637
def loadProcessorInfo(self):
3738
'''Loads the processor info similar to the verto extension.
3839
'''
39-
pattern_data = open('verto/processor-info.json').read()
40+
pattern_data = pkg_resources.resource_string('verto', 'processor-info.json').decode('utf-8')
4041
return json.loads(pattern_data)
4142

4243
def to_blocks(self, string):

verto/tests/SmokeTests.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest, os, subprocess
2+
import pkg_resources
23
from verto import Verto
34

45
class SmokeDocsTest(unittest.TestCase):
@@ -9,7 +10,7 @@ def __init__(self, *args, **kwargs):
910
self.maxDiff = None
1011
self.build_path = 'docs/build'
1112

12-
@unittest.skipIf(not os.path.isdir('docs') and os.name not in ['nt', 'posix'], 'Docs are not present')
13+
@unittest.skipIf(not pkg_resources.resource_isdir('verto', 'docs') and os.name not in ['nt', 'posix'], 'Docs are not present')
1314
def test_compile_docs(self):
1415
'''This test is skipped if the docs directory is not found.
1516
'''
@@ -42,7 +43,7 @@ def __init__(self, *args, **kwargs):
4243
unittest.TestCase.__init__(self, *args, **kwargs)
4344
self.maxDiff = None
4445
self.verto = None
45-
self.assets_template = 'verto/tests/assets/smoke/{}'
46+
self.assets_template = 'tests/assets/smoke/{}'
4647

4748
def setUp(self):
4849
'''Run before any testcases.
@@ -58,14 +59,13 @@ def test_compile_files(self):
5859
'''Tests that some example files are converted.
5960
'''
6061
for chapter in ['algorithms.md', 'introduction.md']:
61-
with open(self.assets_template.format(chapter), 'r') as f:
62-
text = f.read()
63-
result = self.verto.convert(text)
62+
text = pkg_resources.resource_string('verto', self.assets_template.format(chapter)).decode('utf-8')
63+
result = self.verto.convert(text)
6464

65-
self.assertIsNot(result, None)
66-
self.assertIsNot(result.title, None)
67-
self.assertIsNot(result.html_string, None)
68-
self.assertTrue(len(result.html_string) > 0)
65+
self.assertIsNot(result, None)
66+
self.assertIsNot(result.title, None)
67+
self.assertIsNot(result.html_string, None)
68+
self.assertTrue(len(result.html_string) > 0)
6969

7070
def test_compile_files_custom(self):
7171
'''Tests that some example files are converted with custom
@@ -78,11 +78,10 @@ def test_compile_files_custom(self):
7878

7979
verto = Verto(html_templates=custom_templates)
8080
for chapter in ['algorithms.md', 'introduction.md']:
81-
with open(self.assets_template.format(chapter), 'r') as f:
82-
text = f.read()
83-
result = verto.convert(text)
81+
text = pkg_resources.resource_string('verto', self.assets_template.format(chapter)).decode('utf-8')
82+
result = verto.convert(text)
8483

85-
self.assertIsNot(result, None)
86-
self.assertIsNot(result.title, None)
87-
self.assertIsNot(result.html_string, None)
88-
self.assertTrue(len(result.html_string) > 0)
84+
self.assertIsNot(result, None)
85+
self.assertIsNot(result.title, None)
86+
self.assertIsNot(result.html_string, None)
87+
self.assertTrue(len(result.html_string) > 0)

0 commit comments

Comments
 (0)