|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # setup |
3 | | -# Setup script for baleen |
| 3 | +# Setup script for installing baleen |
4 | 4 | # |
5 | 5 | # Author: Benjamin Bengfort <benjamin@bengfort.com> |
6 | 6 | # Created: Fri Sep 19 10:59:24 2014 -0400 |
7 | 7 | # |
8 | | -# Copyright (C) 2014 District Data Labs |
| 8 | +# Copyright (C) 2014 Bengfort.com |
9 | 9 | # For license information, see LICENSE.txt and NOTICE.md |
10 | 10 | # |
11 | 11 | # ID: setup.py [] benjamin@bengfort.com $ |
12 | 12 |
|
13 | 13 | """ |
14 | | -Setup script for baleen |
| 14 | +Setup script for installing baleen. |
| 15 | +See http://bbengfort.github.io/programmer/2016/01/20/packaging-with-pypi.html |
15 | 16 | """ |
16 | 17 |
|
17 | 18 | ########################################################################## |
18 | 19 | ## Imports |
19 | 20 | ########################################################################## |
20 | 21 |
|
21 | | -try: |
22 | | - from setuptools import setup |
23 | | - from setuptools import find_packages |
24 | | -except ImportError: |
25 | | - raise ImportError("Could not import \"setuptools\"." |
26 | | - "Please install the setuptools package.") |
| 22 | +import os |
| 23 | +import re |
| 24 | +import codecs |
| 25 | + |
| 26 | +from setuptools import setup |
| 27 | +from setuptools import find_packages |
27 | 28 |
|
28 | 29 | ########################################################################## |
29 | 30 | ## Package Information |
30 | 31 | ########################################################################## |
31 | 32 |
|
32 | | -## Discover the packages |
33 | | -packages = find_packages(where=".", exclude=("tests", "bin", "docs", "fixtures",)) |
| 33 | +## Basic information |
| 34 | +NAME = "baleen" |
| 35 | +DESCRIPTION = "An automated ingestion service for blogs to construct a corpus for NLP research." |
| 36 | +AUTHOR = "Benjamin Bengfort" |
| 37 | +EMAIL = "benjamin@bengfort.com" |
| 38 | +LICENSE = "MIT" |
| 39 | +REPOSITORY = "https://github.com/bbengfort/baleen" |
| 40 | +PACKAGE = "baleen" |
34 | 41 |
|
35 | | -## Load the requirements |
36 | | -requires = [] |
37 | | -with open('requirements.txt', 'r') as reqfile: |
38 | | - for line in reqfile: |
39 | | - requires.append(line.strip()) |
| 42 | +## Define the keywords |
| 43 | +KEYWORDS = ('nlp', 'baleen', 'ingestion', 'blogs', 'rss') |
40 | 44 |
|
41 | 45 | ## Define the classifiers |
42 | | -classifiers = ( |
| 46 | +## See https://pypi.python.org/pypi?%3Aaction=list_classifiers |
| 47 | +CLASSIFIERS = ( |
43 | 48 | 'Development Status :: 4 - Beta', |
44 | 49 | 'Environment :: Console', |
45 | 50 | 'Intended Audience :: Developers', |
|
53 | 58 | 'Topic :: Utilities', |
54 | 59 | ) |
55 | 60 |
|
56 | | -## Define the keywords |
57 | | -keywords = ('nlp', 'baleen', 'ingestion', 'blogs', 'rss') |
| 61 | +## Important Paths |
| 62 | +PROJECT = os.path.abspath(os.path.dirname(__file__)) |
| 63 | +REQUIRE_PATH = "requirements.txt" |
| 64 | +VERSION_PATH = os.path.join(PACKAGE, "version.py") |
| 65 | +PKG_DESCRIBE = "DESCRIPTION.txt" |
| 66 | + |
| 67 | +## Directories to ignore in find_packages |
| 68 | +EXCLUDES = ( |
| 69 | + "tests", "bin", "docs", "fixtures", "register", "notebooks", |
| 70 | +) |
| 71 | + |
| 72 | +########################################################################## |
| 73 | +## Helper Functions |
| 74 | +########################################################################## |
58 | 75 |
|
| 76 | +def read(*parts): |
| 77 | + """ |
| 78 | + Assume UTF-8 encoding and return the contents of the file located at the |
| 79 | + absolute path from the REPOSITORY joined with *parts. |
| 80 | + """ |
| 81 | + with codecs.open(os.path.join(PROJECT, *parts), 'rb', 'utf-8') as f: |
| 82 | + return f.read() |
| 83 | + |
| 84 | + |
| 85 | +def get_version(path=VERSION_PATH): |
| 86 | + """ |
| 87 | + Reads the __init__.py defined in the VERSION_PATH to find the get_version |
| 88 | + function, and executes it to ensure that it is loaded correctly. |
| 89 | + """ |
| 90 | + namespace = {} |
| 91 | + exec(read(path), namespace) |
| 92 | + return namespace['get_version']() |
| 93 | + |
| 94 | + |
| 95 | +def get_requires(path=REQUIRE_PATH): |
| 96 | + """ |
| 97 | + Yields a generator of requirements as defined by the REQUIRE_PATH which |
| 98 | + should point to a requirements.txt output by `pip freeze`. |
| 99 | + """ |
| 100 | + for line in read(path).splitlines(): |
| 101 | + line = line.strip() |
| 102 | + if line and not line.startswith('#'): |
| 103 | + yield line |
| 104 | + |
| 105 | +########################################################################## |
59 | 106 | ## Define the configuration |
| 107 | +########################################################################## |
| 108 | + |
60 | 109 | config = { |
61 | | - "name": "baleen", |
62 | | - "version": "0.1.0", |
63 | | - "description": "An automated ingestion service for blogs to construct a corpus for NLP research.", |
64 | | - "license": "MIT", |
65 | | - "author": "Benjamin Bengfort", |
66 | | - "author_email": "benjamin@bengfort.com", |
67 | | - "url": "https://github.com/bbengfort/baleen", |
68 | | - "download_url": 'https://github.com/bbengfort/baleen/tarball/v0.1.0', |
69 | | - "packages": packages, |
70 | | - "install_requires": requires, |
71 | | - "classifiers": classifiers, |
72 | | - "keywords": keywords, |
73 | | - "zip_safe": True, |
| 110 | + "name": NAME, |
| 111 | + "version": get_version(), |
| 112 | + "description": DESCRIPTION, |
| 113 | + "long_description": read(PKG_DESCRIBE), |
| 114 | + "license": LICENSE, |
| 115 | + "author": AUTHOR, |
| 116 | + "author_email": EMAIL, |
| 117 | + "maintainer": AUTHOR, |
| 118 | + "maintainer_email": EMAIL, |
| 119 | + "url": REPOSITORY, |
| 120 | + "download_url": "{}/tarball/v{}".format(REPOSITORY, get_version()), |
| 121 | + "packages": find_packages(where=PROJECT, exclude=EXCLUDES), |
| 122 | + "install_requires": list(get_requires()), |
| 123 | + "classifiers": CLASSIFIERS, |
| 124 | + "keywords": KEYWORDS, |
| 125 | + "zip_safe": False, |
74 | 126 | "scripts": ['bin/baleen'], |
75 | 127 | } |
76 | 128 |
|
|
0 commit comments