-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
79 lines (65 loc) · 2.65 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
from distutils.core import setup
from distutils.command.install import install
from distutils.command.install_data import install_data
from distutils.command.build_ext import build_ext
from distutils.command.clean import clean
# from distutils.command.egg_info import egg_info
import os
import shutil
from zipfile import ZipFile
import sys
from digitaledition_jekylltheme import __version__
# minimal python setup script,
# to support a standardized way of including this theme via zipfile
# in python projects
ZIPFILE_PATH = os.path.join('digitaledition_jekylltheme',
'digitaledition-jekylltheme.zip')
def create_zipfile():
# before installation, generate a fresh zipfile of the site contents
exclude_dirs = ['./.git', './_site', 'digitaledition_jekylltheme']
exclude_files = ['digitaledition-jekylltheme.zip']
with ZipFile(ZIPFILE_PATH, 'w') as zipdata:
# directory within the zipfile where everything should go
base_zip_dir = 'digitaledition-jekylltheme'
for root, dirs, files in os.walk('.'):
if any(root.startswith(d) for d in exclude_dirs):
continue
for filename in files:
if filename in exclude_files:
continue
zipdata.write(os.path.join(root, filename),
os.path.join(base_zip_dir, root, filename))
# note: extending both install and build_ext commands so that
# zip will be created for both pip install -e and regular pip install
class PrepInstall(install):
def run(self):
print '** install'
create_zipfile()
install.run(self)
class PrepBuildExt(build_ext):
def run(self):
print '** build_ext'
create_zipfile()
build_ext.run(self)
# extend clean command to also remove the zipfile
class CleanZip(clean):
def run(self):
# remove zip file and then do any other normal cleaning
try:
os.remove(ZIPFILE_PATH)
except OSError:
pass
clean.run(self)
setup(name='digitaledition_jekylltheme',
version=__version__,
description='Jekyll theme for annotated digital facsimile editions',
author='Emory Center for Digital Scholarship and Emory LITS',
author_email='[email protected]',
url='https://github.com/emory-libraries-ecds/digitaledition-jekylltheme',
packages=['digitaledition_jekylltheme'],
package_dir={'digitaledition-jekylltheme': 'digitaledition_jekylltheme'},
package_data={'digitaledition_jekylltheme': ['digitaledition-jekylltheme.zip']},
cmdclass={'install': PrepInstall, 'build_ext': PrepBuildExt,
'clean': CleanZip},
)