Skip to content

Commit 1ab1cdc

Browse files
Merge pull request #43 from UMDBPP/develop
update function usage
2 parents d2c0e71 + c87c123 commit 1ab1cdc

File tree

3 files changed

+63
-23
lines changed

3 files changed

+63
-23
lines changed

packetraven/connections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from serial import Serial
1313
from shapely.geometry import Point
1414
from tablecrow import PostGresTable
15-
from tablecrow.table import split_URL_port
15+
from tablecrow.utilities import split_hostname_port
1616

1717
from .base import (
1818
APRSPacketSink,
@@ -260,7 +260,7 @@ def __init__(self, hostname: str, database: str, table: str, **kwargs):
260260
kwargs['primary_key'] = 'time'
261261
kwargs['fields'] = {**self.__default_fields, **kwargs['fields']}
262262
PostGresTable.__init__(
263-
self, hostname=hostname, database=database, name=table, **kwargs
263+
self, hostname=hostname, database=database, table_name=table, **kwargs
264264
)
265265
PacketSource.__init__(
266266
self, f'postgresql://{self.hostname}:{self.port}/{self.database}/{self.name}'
@@ -475,7 +475,7 @@ def __packet_record(packet: LocationPacket) -> {str: Any}:
475475
class APRSis(APRSPacketSink, APRSPacketSource, NetworkConnection):
476476
def __init__(self, callsigns: [str] = None, hostname: str = None):
477477
if hostname is not None:
478-
self.__hostname, self.__port = split_URL_port(hostname)
478+
self.__hostname, self.__port = split_hostname_port(hostname)
479479
else:
480480
self.__hostname, self.__port = ('rotate.aprs.net', 10152)
481481

setup.py

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,70 @@
11
#!/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+
29
from setuptools import config, find_packages, setup
310

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()
913

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])
1223

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)
1740

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:
1952
import subprocess
53+
import sys
54+
55+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'dunamai'])
56+
from dunamai import Version
2057

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'
2362

2463
metadata = config.read_configuration('setup.cfg')['metadata']
2564

2665
setup(
2766
name=metadata['name'],
28-
version=Version.from_any_vcs().serialize(),
67+
version=version,
2968
author=metadata['author'],
3069
author_email=metadata['author_email'],
3170
description=metadata['description'],
@@ -48,7 +87,7 @@
4887
'requests',
4988
'shapely',
5089
'sshtunnel',
51-
'tablecrow>=1.3.1',
90+
'tablecrow>=1.3.2',
5291
],
5392
extras_require={
5493
'testing': ['flake8', 'pytest', 'pytest-cov', 'pytz'],

tests/test_database.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import psycopg2
66
import pytest
77
from sshtunnel import SSHTunnelForwarder
8-
from tablecrow.table import random_open_tcp_port, split_URL_port
8+
from tablecrow.table import random_open_tcp_port
99
from tablecrow.tables.postgres import PostGresTable, SSH_DEFAULT_PORT, database_has_table
10+
from tablecrow.utilities import split_hostname_port
1011

1112
from packetraven.connections import APRSDatabaseTable
1213
from packetraven.packets import APRSPacket
@@ -36,11 +37,11 @@
3637
'ssh_hostname' in CREDENTIALS['database']
3738
and CREDENTIALS['database']['ssh_hostname'] is not None
3839
):
39-
hostname, port = split_URL_port(CREDENTIALS['database']['hostname'])
40+
hostname, port = split_hostname_port(CREDENTIALS['database']['hostname'])
4041
if port is None:
4142
port = PostGresTable.DEFAULT_PORT
4243

43-
ssh_hostname, ssh_port = split_URL_port(CREDENTIALS['database']['ssh_hostname'])
44+
ssh_hostname, ssh_port = split_hostname_port(CREDENTIALS['database']['ssh_hostname'])
4445
if ssh_port is None:
4546
ssh_port = SSH_DEFAULT_PORT
4647

@@ -68,7 +69,7 @@
6869

6970
@pytest.fixture
7071
def connection() -> psycopg2.connect:
71-
hostname, port = split_URL_port(CREDENTIALS['database']['hostname'])
72+
hostname, port = split_hostname_port(CREDENTIALS['database']['hostname'])
7273
if port is None:
7374
port = PostGresTable.DEFAULT_PORT
7475

0 commit comments

Comments
 (0)