Skip to content

Commit f1cd364

Browse files
committed
Add package_metadata from tony/cookiecutter-pypackage. Update setup.py and doc/conf.py
1 parent 3ba4809 commit f1cd364

File tree

6 files changed

+109
-39
lines changed

6 files changed

+109
-39
lines changed

CHANGES

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Changelog
44

55
Here you can find the recent changes to tmuxp.
66

7-
current
8-
-------
7+
0.1.5-dev
8+
---------
99

1010
- [docs] section heading normalization.
1111
- [docs] tao of tmux section now treated as a chatper. tao of tmux may be
1212
split off into its own project.
13+
- [internals] use conventions from `tony/cookiecutter-pypackage`_
1314

1415
0.1.4
1516
-----
@@ -577,5 +578,6 @@ current
577578
.. _pep257: http://www.python.org/dev/peps/pep-0257/
578579
.. _pep8: http://www.python.org/dev/peps/pep-0008/
579580
.. _pep440: http://www.python.org/dev/peps/pep-0440/
581+
.. _tony/cookiecutter-pypackage: https://github.com/tony/cookiecutter-pypackage.
580582

581583
.. todo:: # vim: set filetype=rst:

doc/about.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Differences from tmuxinator / teamocil
2929
please free to `edit this page`_ on github.
3030

3131
Similarities
32-
""""""""""""
32+
~~~~~~~~~~~~
3333

3434
**Load sessions** Loads tmux sessions from config
3535

@@ -39,7 +39,7 @@ Similarities
3939
simplified markup for panes that have one command.
4040

4141
Missing
42-
"""""""
42+
~~~~~~~
4343

4444
**Stability** tmuxinator and teamocil are far more stable and
4545
well-developed than tmuxp.
@@ -50,7 +50,7 @@ well-developed than tmuxp.
5050
tmuxinator may have support for earlier versions.
5151

5252
Differences
53-
"""""""""""
53+
~~~~~~~~~~~
5454

5555
**Programming Language** python. teamocil and tmuxinator uses ruby.
5656

doc/conf.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616

1717
from tmuxp import __version__
1818

19-
sys.path.append(os.path.abspath('.'))
20-
sys.path.append(os.path.abspath('_themes'))
19+
# Get the project root dir, which is the parent dir of this
20+
cwd = os.getcwd()
21+
project_root = os.path.dirname(cwd)
22+
23+
# Insert the project root dir as the first element in the PYTHONPATH.
24+
# This lets us ensure that the source package is imported, and that its
25+
# version is used.
26+
sys.path.insert(0, project_root)
27+
from ..package_metadata import p
2128

2229
# If extensions (or modules to document with autodoc) are in another directory,
2330
# add these directories to sys.path here. If the directory is relative to the
@@ -52,8 +59,8 @@
5259
master_doc = 'index'
5360

5461
# General information about the project.
55-
project = u'tmuxp'
56-
copyright = u'2013, Tony Narlock'
62+
project = p.title
63+
copyright = p.copyright
5764

5865
rst_prolog = """
5966
.. note::
@@ -70,9 +77,9 @@
7077
# built documents.
7178
#
7279
# The short X.Y version.
73-
version = __version__
80+
version = '%s' % ('.'.join(p.version.split('.'))[:2])
7481
# The full version, including alpha/beta/rc tags.
75-
release = __version__
82+
release = '%s' % (p.version)
7683

7784
# The language for content autogenerated by Sphinx. Refer to documentation
7885
# for a list of supported languages.
@@ -196,8 +203,7 @@
196203
#html_file_suffix = None
197204

198205
# Output file base name for HTML help builder.
199-
htmlhelp_basename = 'tmuxpdoc'
200-
206+
htmlhelp_basename = '%sdoc' % p.title
201207

202208
# -- Options for LaTeX output --------------------------------------------------
203209

@@ -215,8 +221,8 @@
215221
# Grouping the document tree into LaTeX files. List of tuples
216222
# (source start file, target name, title, author, documentclass [howto/manual]).
217223
latex_documents = [
218-
('index', 'tmuxp.tex', u'tmuxp Documentation',
219-
u'Tony Narlock', 'manual'),
224+
('index', '{0}.tex'.format(p.package_name), '{0} Documentation'.format(p.title),
225+
p.author, 'manual'),
220226
]
221227

222228
# The name of an image file (relative to this directory) to place at the top of
@@ -245,8 +251,8 @@
245251
# One entry per manual page. List of tuples
246252
# (source start file, name, description, authors, manual section).
247253
man_pages = [
248-
('index', 'tmuxp', u'tmuxp Documentation',
249-
[u'Tony Narlock'], 1)
254+
('index', p.package_name, '{0} Documentation'.format(p.title),
255+
p.author, 1),
250256
]
251257

252258
# If true, show URL addresses after external links.
@@ -259,9 +265,8 @@
259265
# (source start file, target name, title, author,
260266
# dir menu entry, description, category)
261267
texinfo_documents = [
262-
('index', 'tmuxp', u'tmuxp Documentation',
263-
u'Tony Narlock', 'tmuxp', 'tmuxp',
264-
'Miscellaneous'),
268+
('index', '{0}'.format(p.package_name), '{0} Documentation'.format(p.title),
269+
p.author, p.package_name, p.description, 'Miscellaneous'),
265270
]
266271

267272
# Documents to append as an appendix to all manuals.
@@ -273,6 +278,8 @@
273278
# How to display URL addresses: 'footnote', 'no', or 'inline'.
274279
#texinfo_show_urls = 'footnote'
275280

281+
# If true, do not generate a @detailmenu in the "Top" node's menu.
282+
#texinfo_no_detailmenu = False
276283

277284
# Example configuration for intersphinx: refer to the Python standard library.
278285
intersphinx_mapping = {'http://docs.python.org/': None}
@@ -284,5 +291,4 @@
284291
scale=.75,
285292
aspect=0.5,
286293
proportional=True,
287-
#linewidth=.5,
288294
)

package_metadata.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import absolute_import, division, print_function, \
5+
with_statement, unicode_literals
6+
7+
import os
8+
import sys
9+
import re
10+
11+
package_file = os.path.join(os.path.dirname(__file__), "tmuxp/__init__.py")
12+
file_content = open(package_file, "rt").read()
13+
14+
15+
class Package_Metadata(dict):
16+
__getattr__ = dict.__getitem__
17+
__setattr__ = dict.__setitem__
18+
19+
attributes = [
20+
'title', 'package_name', 'author', 'description', 'email',
21+
'version', 'license', 'copyright'
22+
]
23+
24+
@staticmethod
25+
def get_attribute(attr, file_content):
26+
regex_expression = r"^__{0}__ = ['\"]([^'\"]*)['\"]".format(attr)
27+
mo = re.search(regex_expression, file_content, re.M)
28+
if mo:
29+
return mo.group(1)
30+
else:
31+
raise RuntimeError("Unable to find version string in %s." % (package_file,))
32+
33+
def refresh(self, attributes):
34+
35+
file_content = open(self.package_file, "rt").read()
36+
37+
for k in attributes:
38+
attr_val = self.get_attribute(k, file_content)
39+
if attr_val:
40+
self[k] = attr_val
41+
42+
def __init__(self, package_file, attributes=None):
43+
44+
if attributes:
45+
self.attributes = attributes
46+
47+
self.package_file = package_file
48+
49+
self.refresh(self.attributes)
50+
51+
52+
p = Package_Metadata(package_file)
53+
54+
55+
def print_metadata():
56+
for k, v in p.items():
57+
print('%s: %s' % (k, v))
58+
59+
if __name__ == '__main__':
60+
print_metadata()
61+
sys.exit()

setup.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
Manage tmux workspaces from JSON and YAML, pythonic API, shell completion.
77
88
"""
9+
import os
910
import sys
11+
1012
from setuptools import setup
1113

14+
sys.path.insert(0, os.getcwd()) # we want to grab this:
15+
from package_metadata import p
16+
17+
1218
with open('requirements.pip') as f:
1319
install_reqs = [line for line in f.read().split('\n') if line]
1420
tests_reqs = []
@@ -17,35 +23,27 @@
1723
install_reqs += ['argparse']
1824
tests_reqs += ['unittest2']
1925

20-
import re
21-
VERSIONFILE = "tmuxp/__init__.py"
22-
verstrline = open(VERSIONFILE, "rt").read()
23-
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
24-
mo = re.search(VSRE, verstrline, re.M)
25-
if mo:
26-
__version__ = mo.group(1)
27-
else:
28-
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
29-
26+
readme = open('README.rst').read()
27+
history = open('CHANGES').read().replace('.. :changelog:', '')
3028

3129
setup(
32-
name='tmuxp',
33-
version=__version__,
30+
name=p.title,
31+
version=p.version,
3432
url='http://github.com/tony/tmuxp/',
3533
download_url='https://pypi.python.org/pypi/tmuxp',
36-
license='BSD',
37-
author='Tony Narlock',
38-
author_email='[email protected]',
39-
description='Manage tmux workspaces from JSON and YAML, pythonic API, '
40-
'shell completion',
41-
long_description=open('README.rst').read(),
34+
license=p.license,
35+
author=p.author,
36+
author_email=p.email,
37+
description=p.description,
38+
long_description=readme,
4239
packages=['tmuxp', 'tmuxp.testsuite',
4340
'tmuxp._vendor', 'tmuxp._vendor.colorama'],
4441
include_package_data=True,
4542
install_requires=install_reqs,
4643
tests_require=tests_reqs,
4744
test_suite='tmuxp.testsuite',
4845
zip_safe=False,
46+
keywords=p.title,
4947
scripts=['pkg/tmuxp.bash', 'pkg/tmuxp.zsh', 'pkg/tmuxp.tcsh'],
5048
entry_points=dict(console_scripts=['tmuxp=tmuxp:cli.main']),
5149
classifiers=[

tmuxp/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
with_statement, unicode_literals
1313

1414
__title__ = 'tmuxp'
15+
__package_name__ = 'tmuxp'
1516
__version__ = '0.1.4'
17+
__description__ = 'Manage tmux sessions thru JSON, YAML configs. Features Python API'
18+
__email__ = '[email protected]'
1619
__author__ = 'Tony Narlock'
1720
__license__ = 'BSD'
1821
__copyright__ = 'Copyright 2013 Tony Narlock'

0 commit comments

Comments
 (0)