|
1 | 1 | #!/usr/bin/env python |
| 2 | +import importlib |
| 3 | +import logging |
| 4 | +import os |
| 5 | +from pathlib import Path |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | + |
2 | 9 | from setuptools import config, find_packages, setup |
3 | 10 |
|
4 | | -try: |
5 | | - from dunamai import Version |
6 | | -except ImportError: |
7 | | - import sys |
8 | | - import subprocess |
| 11 | +BUILT_PACKAGES = {'numpy': [], 'pyproj': [], 'shapely': []} |
| 12 | +is_conda = (Path(sys.prefix) / 'conda-meta').exists() |
9 | 13 |
|
10 | | - subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'dunamai']) |
11 | | - from dunamai import Version |
| 14 | +if is_conda: |
| 15 | + conda_packages = [] |
| 16 | + for conda_package in BUILT_PACKAGES: |
| 17 | + try: |
| 18 | + importlib.import_module(conda_package) |
| 19 | + except: |
| 20 | + conda_packages.append(conda_package) |
| 21 | + if len(conda_packages) > 0: |
| 22 | + subprocess.check_call(['conda', 'install', '-y', *conda_packages]) |
12 | 23 |
|
13 | | -try: |
14 | | - import pyproj |
15 | | -except ImportError: |
16 | | - import platform |
| 24 | +if os.name == 'nt': |
| 25 | + for required_package, pipwin_dependencies in BUILT_PACKAGES.items(): |
| 26 | + try: |
| 27 | + importlib.import_module(required_package) |
| 28 | + except: |
| 29 | + try: |
| 30 | + import pipwin |
| 31 | + except: |
| 32 | + subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pipwin']) |
| 33 | + |
| 34 | + failed_pipwin_packages = [] |
| 35 | + for pipwin_package in pipwin_dependencies + [required_package]: |
| 36 | + try: |
| 37 | + subprocess.check_call([sys.executable, '-m', 'pipwin', 'install', pipwin_package.lower()]) |
| 38 | + except subprocess.CalledProcessError: |
| 39 | + failed_pipwin_packages.append(pipwin_package) |
17 | 40 |
|
18 | | - if platform.system() == 'Windows': |
| 41 | + if len(failed_pipwin_packages) > 0: |
| 42 | + raise RuntimeError( |
| 43 | + f'failed to download or install non-conda Windows build(s) of {" and ".join(failed_pipwin_packages)}; you can either\n' |
| 44 | + '1) install within an Anaconda environment, or\n' |
| 45 | + f'2) `pip install <file>.whl`, with `<file>.whl` downloaded from {" and ".join("https://www.lfd.uci.edu/~gohlke/pythonlibs/#" + value.lower() for value in failed_pipwin_packages)} for your Python version' |
| 46 | + ) |
| 47 | + |
| 48 | +try: |
| 49 | + try: |
| 50 | + from dunamai import Version |
| 51 | + except ImportError: |
19 | 52 | import subprocess |
| 53 | + import sys |
| 54 | + |
| 55 | + subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'dunamai']) |
| 56 | + from dunamai import Version |
20 | 57 |
|
21 | | - subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pipwin']) |
22 | | - subprocess.check_call([sys.executable, '-m', 'pipwin', 'install', 'pyproj']) |
| 58 | + version = Version.from_any_vcs().serialize() |
| 59 | +except RuntimeError as error: |
| 60 | + logging.exception(error) |
| 61 | + version = '0.0.0' |
23 | 62 |
|
24 | 63 | metadata = config.read_configuration('setup.cfg')['metadata'] |
25 | 64 |
|
26 | 65 | setup( |
27 | 66 | name=metadata['name'], |
28 | | - version=Version.from_any_vcs().serialize(), |
| 67 | + version=version, |
29 | 68 | author=metadata['author'], |
30 | 69 | author_email=metadata['author_email'], |
31 | 70 | description=metadata['description'], |
|
48 | 87 | 'requests', |
49 | 88 | 'shapely', |
50 | 89 | 'sshtunnel', |
51 | | - 'tablecrow>=1.3.1', |
| 90 | + 'tablecrow>=1.3.2', |
52 | 91 | ], |
53 | 92 | extras_require={ |
54 | 93 | 'testing': ['flake8', 'pytest', 'pytest-cov', 'pytz'], |
|
0 commit comments