Skip to content

Commit

Permalink
Fixes for installing in Python 3 (#410)
Browse files Browse the repository at this point in the history
* setup.py: Python 3 doesn't support octal numbers in this syntax

* setup.py: ensure we can actually use the install_requires

* setup.py: ensure self.www_dir exists before we write to it

* setup.py: replace 'stdout.write' with 'print()'

Attempting to work around this error thrown on line 152:

    ValueError: underlying buffer has been detached

* setup.py: create the necessary directories in Python 3
  • Loading branch information
alexwlchan authored and bcail committed Mar 5, 2018
1 parent 14fd219 commit b45f4c6
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# setup.py

from __future__ import print_function

from grp import getgrnam
from pwd import getpwnam
from setuptools import setup
Expand Down Expand Up @@ -142,22 +145,25 @@ def __make_directories(self):
self.log_dir,
self.config_dir
]
map(self.__init_dir, loris_directories)
for d in loris_directories:
self.__init_dir(d)

def __init_dir(self, d):
# Could do something here to warn if dir exists but permissions or
# ownership aren't sufficient.
if not os.path.exists(d):
os.makedirs(d)
stdout.write('Created %s\n' % (d,))
print('Created %s' % d)
os.chown(d, self.loris_owner_id, self.loris_group_id)
stdout.write('Changed ownership of %s to %s:%s\n' %
(d,self.loris_owner,self.loris_group))
print(
'Changed ownership of %s to %s:%s' %
(d, self.loris_owner, self.loris_group)
)

s = os.stat(d)
permissions = oct(stat.S_IMODE(s.st_mode))
if permissions != oct(0755):
os.chmod(d, 0755)
if permissions != oct(0o755):
os.chmod(d, 0o755)
stdout.write('Set permissions for %s to 0755\n' % (d,))

def __write_wsgi(self):
Expand All @@ -170,9 +176,10 @@ def __write_wsgi(self):
# site.addsitedir('/path/to/my/virtualenv/lib/python2.x/site-packages')
application = create_app(config_file_path='%s')
''' % (config_file_path,)

with open(wsgi_file_path, 'w') as f:
f.write(content)
os.chmod(wsgi_file_path, 0755)
os.chmod(wsgi_file_path, 0o755)
os.chown(wsgi_file_path, self.loris_owner_id, self.loris_group_id)
@property
def __here(self):
Expand All @@ -189,7 +196,7 @@ def __copy_index_and_favicon(self):
shutil.copyfile(index_src, index_target)
shutil.copyfile(favicon_src, favicon_target)
for f in (index_target, favicon_target):
os.chmod(f, 0644)
os.chmod(f, 0o644)
os.chown(f, self.loris_owner_id, self.loris_group_id)

def __update_and_deploy_config(self):
Expand Down Expand Up @@ -235,7 +242,7 @@ def _read(fname):
license='Simplified BSD',
version=VERSION,
packages=['loris'],
install_requires=install_requires
install_requires=[str(ir.req) for ir in install_requires]
)


Expand Down

0 comments on commit b45f4c6

Please sign in to comment.