Skip to content

Commit

Permalink
update setup to ease install on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Jul 8, 2021
1 parent e4f67bf commit 1a6b19d
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from setuptools import config, find_packages, setup

BUILT_PACKAGES = {'numpy': [], 'pyproj': [], 'shapely': ['gdal']}
BUILT_PACKAGES = {'numpy': [], 'pandas': ['numpy'], 'pyproj': [], 'shapely': ['gdal']}
is_conda = (Path(sys.prefix) / 'conda-meta').exists()

if is_conda:
Expand All @@ -22,21 +22,26 @@
subprocess.check_call(['conda', 'install', '-y', *conda_packages])

if os.name == 'nt':
packages_to_install = {}
for required_package, pipwin_dependencies in BUILT_PACKAGES.items():
failed_pipwin_packages = []
iterations = len(pipwin_dependencies)
try:
importlib.import_module(required_package)
except:
packages_to_install[required_package] = pipwin_dependencies
if len(packages_to_install) > 0:
try:
import pipwin
except:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pipwin'])
subprocess.check_call([sys.executable, '-m', 'pipwin', 'refresh'])

for _ in range(iterations):
try:
importlib.import_module(required_package)
except:
for required_package, pipwin_dependencies in packages_to_install.items():
failed_pipwin_packages = []
for _ in range(1 + len(pipwin_dependencies)):
for pipwin_package in [required_package] + pipwin_dependencies:
try:
import pipwin
importlib.import_module(pipwin_package)
except:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pipwin'])
subprocess.check_call([sys.executable, '-m', 'pipwin', 'refresh'])

for pipwin_package in pipwin_dependencies + [required_package]:
try:
subprocess.check_call(
[sys.executable, '-m', 'pipwin', 'install', pipwin_package.lower()]
Expand All @@ -46,14 +51,17 @@
except subprocess.CalledProcessError:
failed_pipwin_packages.append(pipwin_package)

if len(failed_pipwin_packages) == 0:
break
# since we don't know the dependencies here, repeat this process n number of times (worst case is O(n), when the first package is dependant on all the others)
if len(failed_pipwin_packages) == 0:
break

if len(failed_pipwin_packages) > 0:
try:
importlib.import_module(required_package)
except:
raise RuntimeError(
f'failed to download or install non-conda Windows build(s) of {" and ".join(failed_pipwin_packages)}; you can either\n'
f'failed to download or install non-conda Windows build(s) of ({", ".join(failed_pipwin_packages)}); you can either\n'
'1) install within an Anaconda environment, or\n'
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'
f'2) `pip install <file>.whl`, with `<file>.whl` downloaded from ({", ".join("https://www.lfd.uci.edu/~gohlke/pythonlibs/#" + value.lower() for value in failed_pipwin_packages)}) for your Python version'
)

try:
Expand Down Expand Up @@ -84,11 +92,11 @@
url=metadata['url'],
packages=find_packages(),
python_requires='>=3.8',
setup_requires=['dunamai', 'setuptools>=41.2', 'wheel'],
setup_requires=['dunamai', 'setuptools>=41.2'],
install_requires=[
'aprslib',
'humanize',
'numpy>=1.20.0',
'numpy',
'pandas',
'pyserial',
'geojson',
Expand All @@ -104,7 +112,7 @@
],
extras_require={
'testing': ['pytest', 'pytest-cov', 'pytest-xdist', 'pytz'],
'development': ['flake8', 'isort', 'oitnb'],
'development': ['flake8', 'isort', 'oitnb', 'wheel'],
},
entry_points={'console_scripts': ['packetraven=packetraven.__main__:main']},
)

0 comments on commit 1a6b19d

Please sign in to comment.