Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ pkutils is intended to be used directly as a Python library.

__version__ = '0.5.4'

__title__ = 'my_package'
__author__ = 'Reuben Cummings'
__description__ = 'My super awesome great package'
__email__ = 'reubano@gmail.com'
__license__ = 'MIT'
__copyright__ = 'Copyright 2015 Reuben Cummings'

You can ``__title__`` explicitly in your Python file. If you leave
``__title__`` unset, pkutils will use:

* The parent directory for paths ending in ``__init__.py``.
* The filename before the extention for other paths
(e.g. ``my_package`` for ``my_package.py``).

``setup.py``

.. code-block:: python
Expand Down
15 changes: 10 additions & 5 deletions pkutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

__version__ = '1.0.0'

__title__ = 'pkutils'
__author__ = 'Reuben Cummings'
__description__ = 'Python packaging utility library'
__email__ = 'reubano@gmail.com'
Expand Down Expand Up @@ -236,19 +235,20 @@ def parse_module(filename, encoding='utf-8'):
(obj): An object whose attributes are accessible in a dict like manner.

Examples:
>>> import os
>>> from tempfile import NamedTemporaryFile
>>>
>>> text = (
... "from os import path as p\\n__version__ = '0.12.4'\\n"
... "__title__ = 'pkutils'\\n__author__ = 'Reuben Cummings'\\n"
... "__author__ = 'Reuben Cummings'\\n"
... "__email__ = 'reubano@gmail.com'\\n__license__ = 'MIT'\\n")
>>>
>>> with NamedTemporaryFile() as f:
>>> with NamedTemporaryFile(suffix='.py') as f:
... bool(f.write(text.encode('utf-8')) or True)
... bool(f.seek(0) or True)
... module = parse_module(f.name)
... module.__version__ == '0.12.4'
... module.__title__ == module.get('__title__') == 'pkutils'
... module.__title__ == os.path.splitext(os.path.basename(f.name))[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I made this line too long for lint. @reubano, it's probably easier for you to fix that directly, but I can file a fixup PR if it would help.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm workin on it. No worries.

... module.__email__ == module['__email__'] == 'reubano@gmail.com'
... module.missing == module.get('missing') == None
True
Expand All @@ -258,8 +258,13 @@ def parse_module(filename, encoding='utf-8'):
True
True
"""
attrs = {}
if filename == '__init__.py':
attrs['__title__'] = p.basename(p.dirname(filename))
else:
attrs['__title__'] = p.splitext(p.basename(filename))[0]
with open(filename, encoding=encoding) as f:
attrs = dict(_get_attrs(f))
attrs.update(_get_attrs(f))

return Dictlike(attrs)

Expand Down
2 changes: 2 additions & 0 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys

from io import open
import os.path

try:
from setuptools import setup
Expand All @@ -25,6 +26,7 @@ def read(filename):


def parse_module(filename):
yield ('__title__', os.path.splitext(filename)[0])
with open(filename, encoding='utf-8') as f:
for line in f:
if line.startswith('__'):
Expand Down