This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
setup.py
111 lines (86 loc) · 3.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# encoding: utf-8
"""
Installation for command-line ADS to BibDesk
Run::
python setup.py install
and the binary adsbibdesk will be installed into your path.
To build the Add to BibDesk service, run::
python setup.py service
"""
import os
import re
import logging
from xml.etree import ElementTree
from setuptools import setup, Command
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def read(fname):
with open(rel_path(fname), 'r') as fh:
return fh.read()
def rel_path(path):
return os.path.join(os.path.dirname(__file__), path)
def get_version():
with open(rel_path("adsbibdesk.py")) as f:
for line in f:
if line.startswith("VERSION"):
version = re.findall(r'\"(.+?)\"', line)[0]
return version
return "0.0.0.dev"
class BuildService(Command):
"""Setuptools Command to build the Service and App.
This replaces the build.py script.
"""
description = "build Add to BibDesk.service(.app)"
user_options = []
def initialize_options(self):
"""Init options"""
pass
def finalize_options(self):
"""Finalize options"""
pass
def run(self):
"""Runner"""
service_path = rel_path(os.path.join("build",
"Add to BibDesk.workflow", "Contents", "document.wflow"))
app_path = rel_path(os.path.join("build", "ADS to BibDesk.app",
"Contents", "document.wflow"))
py_path = rel_path("adsbibdesk.py")
for workflow in (service_path, app_path):
with open(workflow, 'r') as fh:
xml = ElementTree.fromstring(fh.read())
for arr in xml.find('dict').find('array').getchildren():
# fetch Python code inside the xml
py = [c for c in arr.find('dict').getchildren()
if c.tag == 'dict' and
any([i.text and '/usr/bin/env' in i.text
for i in c.getchildren()])]
# rewrite with current file
if py:
logger.info("Inserting {0} into {1}".format(py_path,
workflow))
py[0].find('string').text = open(py_path).read()
logger.info("Saving {0}".format(workflow))
with open(workflow, 'wb') as fh:
fh.write(ElementTree.tostring(xml))
logger.info("Completed ADS to BibDesk build step")
setup(
name='adsbibdesk',
version=get_version(),
author='Jonathan Sick',
author_email='[email protected]',
url="http://www.jonathansick.ca/adsbibdesk/",
description="Add papers from arxiv.org or NASA/SAO ADS to your BibDesk"
" bibliography.",
long_description=read('README.rst'),
keywords="bibtex astronomy",
classifiers=["Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: MacOS :: MacOS X",
"Topic :: Scientific/Engineering :: Astronomy"],
py_modules=['adsbibdesk'],
entry_points={'console_scripts': ['adsbibdesk = adsbibdesk:main']},
use_2to3=True,
cmdclass={'service': BuildService}
)