|
17 | 17 | from setuptools.command.build_py import build_py
|
18 | 18 | from setuptools.command.test import test as TestCommand
|
19 | 19 |
|
20 |
| -from git import Repo |
21 |
| -from git.exc import InvalidGitRepositoryError |
22 | 20 |
|
23 | 21 | here = os.path.abspath(os.path.dirname(__file__))
|
24 | 22 | README = open(os.path.join(here, 'README.rst')).read()
|
25 | 23 | pkg_name = 'oil_library'
|
26 |
| -pkg_version = '1.1.2' |
27 | 24 |
|
| 25 | +def get_version(): |
| 26 | + """ |
| 27 | + return the version number from the __init__ |
| 28 | + """ |
| 29 | + for line in open(os.path.join(pkg_name, "__init__.py")): |
| 30 | + if line.startswith("__version__"): |
| 31 | + version = line.strip().split('=')[1].strip().strip("'").strip('"') |
| 32 | + return version |
| 33 | + raise ValueError("can't find version string in __init__") |
28 | 34 |
|
29 |
| -# try to get update date from repo |
30 |
| -try: |
31 |
| - repo = Repo('.') |
| 35 | +pkg_version = get_version() |
| 36 | + |
| 37 | + |
| 38 | +def get_repo_data(): |
32 | 39 | try:
|
33 |
| - branch_name = repo.active_branch.name |
34 |
| - except TypeError: |
35 |
| - branch_name = 'no-branch' |
36 |
| - last_update = next(repo.iter_commits()).committed_datetime.isoformat() |
37 |
| -except InvalidGitRepositoryError: |
38 |
| - # not building in a valid git repo |
39 |
| - # use today's date. |
40 |
| - print("not in a valid git repo -- using today's date as build date") |
41 |
| - branch_name = 'no-branch' |
42 |
| - last_update = datetime.now().isoformat() |
| 40 | + from git import Repo |
| 41 | + from git.exc import InvalidGitRepositoryError |
| 42 | + |
| 43 | + repo = Repo('.') |
| 44 | + try: |
| 45 | + branch_name = repo.active_branch.name |
| 46 | + except TypeError: |
| 47 | + branch_name = 'no-branch' |
| 48 | + last_update = next(repo.iter_commits()).committed_datetime.isoformat() |
| 49 | + except: # bare excepts are not good, but in this case, |
| 50 | + # anything that goes wrong results in the same thing. |
| 51 | + print("something wrong with accessing git repo -- using today's date as build date") |
| 52 | + branch_name = 'no branch' |
| 53 | + last_update = datetime.now().isoformat() |
| 54 | + return branch_name, last_update |
43 | 55 |
|
44 | 56 |
|
45 | 57 | def clean_files(del_db=False):
|
@@ -150,49 +162,53 @@ def run(self):
|
150 | 162 | # build_py is an old-style class, so we can't use super()
|
151 | 163 | build_py.run(self)
|
152 | 164 |
|
153 |
| - |
154 |
| -s = setup(name=pkg_name, |
155 |
| - version=pkg_version, |
156 |
| - description=('{}: The NOAA library of oils and their properties.\n' |
157 |
| - 'Branch: {}\n' |
158 |
| - 'LastUpdate: {}' |
159 |
| - .format(pkg_name, branch_name, last_update)), |
160 |
| - long_description=README, |
161 |
| - author='ADIOS/GNOME team at NOAA ORR', |
162 |
| - author_email='orr.gnome@noaa.gov', |
163 |
| - url='', |
164 |
| - keywords='adios weathering oilspill modeling', |
165 |
| - packages=find_packages(), |
166 |
| - include_package_data=True, |
167 |
| - package_data={'oil_library': ['OilLib.db', |
168 |
| - 'OilLib', |
169 |
| - 'OilLibTest', |
170 |
| - 'OilLibNorway', |
171 |
| - 'blacklist_whitelist.txt', |
172 |
| - 'tests/*.py', |
173 |
| - 'tests/sample_data/*']}, |
174 |
| - cmdclass={'remake_oil_db': remake_oil_db, |
175 |
| - 'cleanall': cleanall, |
176 |
| - 'test': PyTest, |
177 |
| - 'build_py': BuildPyCommand, |
| 165 | +DESCRIPTION = ('{}: The NOAA library of oils and their properties.\n' |
| 166 | + 'Branch: {}\n' |
| 167 | + 'LastUpdate: {}' |
| 168 | + .format(pkg_name, *get_repo_data()) |
| 169 | + ) |
| 170 | + |
| 171 | + |
| 172 | +setup(name=pkg_name, |
| 173 | + version=pkg_version, |
| 174 | + description=DESCRIPTION, |
| 175 | + long_description=README, |
| 176 | + author='ADIOS/GNOME team at NOAA ORR', |
| 177 | + author_email='orr.gnome@noaa.gov', |
| 178 | + url='', |
| 179 | + keywords='adios weathering oilspill modeling', |
| 180 | + packages=find_packages(), |
| 181 | + include_package_data=True, |
| 182 | + package_data={'oil_library': ['OilLib.db', |
| 183 | + 'OilLib', |
| 184 | + 'OilLibTest', |
| 185 | + 'OilLibNorway', |
| 186 | + 'blacklist_whitelist.txt', |
| 187 | + 'tests/*.py', |
| 188 | + 'tests/sample_data/*']}, |
| 189 | + cmdclass={'remake_oil_db': remake_oil_db, |
| 190 | + 'cleanall': cleanall, |
| 191 | + 'test': PyTest, |
| 192 | + 'build_py': BuildPyCommand, |
| 193 | + }, |
| 194 | + entry_points={'console_scripts': [('initialize_OilLibrary_db = ' |
| 195 | + 'oil_library.initializedb' |
| 196 | + ':make_db'), |
| 197 | + ('diff_import_files = ' |
| 198 | + 'oil_library.scripts.oil_import' |
| 199 | + ':diff_import_files_cmd'), |
| 200 | + ('add_header_to_import_file = ' |
| 201 | + 'oil_library.scripts.oil_import' |
| 202 | + ':add_header_to_csv_cmd'), |
| 203 | + ('get_import_record_dates = ' |
| 204 | + 'oil_library.scripts.oil_import' |
| 205 | + ':get_import_record_dates_cmd'), |
| 206 | + ], |
178 | 207 | },
|
179 |
| - entry_points={'console_scripts': [('initialize_OilLibrary_db = ' |
180 |
| - 'oil_library.initializedb' |
181 |
| - ':make_db'), |
182 |
| - ('diff_import_files = ' |
183 |
| - 'oil_library.scripts.oil_import' |
184 |
| - ':diff_import_files_cmd'), |
185 |
| - ('add_header_to_import_file = ' |
186 |
| - 'oil_library.scripts.oil_import' |
187 |
| - ':add_header_to_csv_cmd'), |
188 |
| - ('get_import_record_dates = ' |
189 |
| - 'oil_library.scripts.oil_import' |
190 |
| - ':get_import_record_dates_cmd'), |
191 |
| - ], |
192 |
| - }, |
193 |
| - zip_safe=False, |
194 |
| - ) |
195 |
| - |
196 |
| - |
197 |
| -if 'develop' in s.script_args and '--uninstall' not in s.script_args: |
| 208 | + zip_safe=False, |
| 209 | + ) |
| 210 | + |
| 211 | + |
| 212 | +if 'develop' in sys.argv and '--uninstall' not in sys.argv: |
198 | 213 | init_db()
|
| 214 | + |
0 commit comments