Taking the quickstart for a spin with Python 3 and hitting this issue -- possibly related to #15.
$ pip install Flask-Diamond
$ mkdir my-app
$ cd my-app
$ flask-diamond scaffold app
$ make install docs
..
$ make test
SETTINGS=$PWD/etc/conf/testing.conf $(which nosetests) my_app -c etc/nose/test.cfg
..
Traceback (most recent call last):
File "/path/to/venv/lib/python3.6/site-packages/nose/case.py", line 134, in run
self.runTest(result)
File "/path/to/venv/lib/python3.6/site-packages/nose/case.py", line 152, in runTest
test(result)
File "/path/to/venv/lib/python3.6/site-packages/flask_testing/utils.py", line 91, in __call__
self._pre_setup()
File "/path/to/venv/lib/python3.6/site-packages/flask_testing/utils.py", line 97, in _pre_setup
self.app = self.create_app()
File "/path/to/my_app/tests/mixins.py", line 15, in create_app
app = create_app()
File "/path/to/my_app/__init__.py", line 54, in create_app
application.facet("configuration")
File "/path/to/venv/lib/python3.6/site-packages/flask_diamond/__init__.py", line 61, in facet
result = method_to_call(self, *args, **kwargs)
File "/path/to/venv/lib/python3.6/site-packages/flask_diamond/facets/configuration.py", line 14, in init_configuration
self.app.config.from_envvar('SETTINGS')
File "/path/to/venv/lib/python3.6/site-packages/flask/config.py", line 109, in from_envvar
return self.from_pyfile(rv, silent=silent)
File "/path/to/venv/lib/python3.6/site-packages/flask/config.py", line 130, in from_pyfile
exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
File "/path/to/etc/conf/testing.conf", line 8
SECRET_KEY = ""H\xf9\xc7\xb9\xe6\xcb\xd3\xd7?\x19\xde\xd3Ry\xe9wI6\xcc'q2\xc3N"
^
SyntaxError: invalid syntax
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/path/to/venv/bin/nosetests", line 11, in <module>
load_entry_point('nose==1.3.4', 'console_scripts', 'nosetests')()
File "/path/to/venv/lib/python3.6/site-packages/nose/core.py", line 121, in __init__
**extra_args)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/main.py", line 95, in __init__
self.runTests()
File "/path/to/venv/lib/python3.6/site-packages/nose/core.py", line 207, in runTests
result = self.testRunner.run(self.test)
File "/path/to/venv/lib/python3.6/site-packages/nose/core.py", line 62, in run
test(result)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 178, in __call__
return self.run(*arg, **kw)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 225, in run
test(orig)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 178, in __call__
return self.run(*arg, **kw)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 225, in run
test(orig)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 178, in __call__
return self.run(*arg, **kw)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 225, in run
test(orig)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 178, in __call__
return self.run(*arg, **kw)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 225, in run
test(orig)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 178, in __call__
return self.run(*arg, **kw)
File "/path/to/venv/lib/python3.6/site-packages/nose/suite.py", line 225, in run
test(orig)
File "/path/to/venv/lib/python3.6/site-packages/nose/case.py", line 46, in __call__
return self.run(*arg, **kwarg)
File "/path/to/venv/lib/python3.6/site-packages/nose/case.py", line 139, in run
result.addError(self, err)
File "/path/to/venv/lib/python3.6/site-packages/nose/proxy.py", line 132, in addError
self.result.addError(self.test, self._prepareErr(err))
File "/path/to/venv/lib/python3.6/site-packages/nose/result.py", line 61, in addError
exc_info = self._exc_info_to_string(err, test)
File "/path/to/venv/lib/python3.6/site-packages/nose/result.py", line 187, in _exc_info_to_string
return _TextTestResult._exc_info_to_string(self, err, test)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/result.py", line 186, in _exc_info_to_string
exctype, value, tb, limit=length, capture_locals=self.tb_locals)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/traceback.py", line 504, in __init__
self.filename = exc_value.filename
AttributeError: 'SyntaxError' object has no attribute 'filename'
make: *** [test] Error 1
$ make db
SETTINGS=$PWD/etc/conf/dev.conf bin/manage.py init_db
..
Traceback (most recent call last):
File "bin/manage.py", line 16, in <module>
app = create_app()
File "./my_app/__init__.py", line 54, in create_app
application.facet("configuration")
File "/path/to/venv/lib/python3.6/site-packages/flask_diamond/__init__.py", line 61, in facet
result = method_to_call(self, *args, **kwargs)
File "/path/to/venv/lib/python3.6/site-packages/flask_diamond/facets/configuration.py", line 14, in init_configuration
self.app.config.from_envvar('SETTINGS')
File "/path/to/venv/lib/python3.6/site-packages/flask/config.py", line 109, in from_envvar
return self.from_pyfile(rv, silent=silent)
File "/path/to/venv/lib/python3.6/site-packages/flask/config.py", line 130, in from_pyfile
exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
File "/path/to/etc/conf/dev.conf", line 8
SECRET_KEY = ""H\xf9\xc7\xb9\xe6\xcb\xd3\xd7?\x19\xde\xd3Ry\xe9wI6\xcc'q2\xc3N"
^
SyntaxError: invalid syntax
make: *** [db] Error 1
From the generated etc/conf/dev.conf
:
SECRET_KEY = ""H\xf9\xc7\xb9\xe6\xcb\xd3\xd7?\x19\xde\xd3Ry\xe9wI6\xcc'q2\xc3N"
The issue is in bin/flask-diamond:
secret_str = repr(os.urandom(24).replace(b"\"", b"#").replace(b"%", b"#"))[1:-1]
Looking at the repr
result in Python 2, so the [1:-1]
slice makes sense:
>>> repr(os.urandom(24).replace(b"\"", b"#").replace(b"%", b"#"))
"'\\xcc\\xc5\\x14\\xe6\\xfc7Q\\xf8\\x98\\x83\\xa3\\xf0sk\\xd5\\xfd\\xac\\xce\\\\\\x8f\\xf0\\xb4\\x93\\xd4'"
Using the slice method Python 3 we see that it would need to be [2:-1]
:
>>> repr(os.urandom(24).replace(b"\"", b"#").replace(b"%", b"#"))
'b"\\x89\\xd95\\xe3\\xc2\\x00\\xd2\\xfb>R\\x91\\xec\\xd2\'\\x87\\x94\\xd5\\x92F\\xfc@J\\xf1r"'
But rather than setting up a conditional for the slice, maybe it would be better if we got away from byte conversion and did something like:
import string
import random
chars = string.ascii_letters + string.digits + string.punctuation
secret_str = ''.join([random.choice(chars) for x in range(24)])
Fixed with on #26 to develop (w/ bump #25 ) or #27 to master