From 0b45dde3b65214a3642547a588df3920cf51e57c Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Wed, 11 Mar 2020 23:16:33 -0400 Subject: [PATCH] use __main__.py --- .github/workflows/ci.yml | 10 ++++++++-- README.md | 9 ++++++--- setup.cfg | 11 +++++------ src/findssh/__init__.py | 1 + FindSSH.py => src/findssh/__main__.py | 12 ++++++------ src/findssh/tests/test_coro.py | 8 +------- 6 files changed, 27 insertions(+), 24 deletions(-) rename FindSSH.py => src/findssh/__main__.py (85%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac949d2..4ea4235 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,7 @@ on: paths: - "**.py" pull_request: - paths: - - "**.py" + release: jobs: @@ -21,9 +20,13 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: pip install .[tests,lint] + - run: flake8 - run: mypy . + - run: pytest + - run: findssh + integration: runs-on: ${{ matrix.os }} @@ -35,5 +38,8 @@ jobs: - uses: actions/setup-python@v1 with: python-version: '3.x' + - run: pip install .[tests] + - run: pytest + - run: findssh diff --git a/README.md b/README.md index ee84bad..b2fc77f 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,6 @@ Although speed advantages weren't seen in our testing, `findssh` works with PyPy ## Install -Just run `FindSSH.py` directly. -To allow use from other programs, you can install by: - ```sh pip install findssh ``` @@ -40,6 +37,12 @@ from command line: findssh ``` +or + +```sh +python -m findssh +``` + ### Command line options * `-s` check the string from the server to attempt to verify the correct service has been found diff --git a/setup.cfg b/setup.cfg index 0b320d5..9b897bf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = findssh -version = 1.3.1 +version = 1.4.0 author = Michael Hirsch, Ph.D. author_email = scivision@users.noreply.github.com url = https://github.com/scivision/findssh @@ -37,8 +37,6 @@ python_requires = >= 3.5 packages = find: zip_safe = False include_package_data = True -scripts = - FindSSH.py install_requires = package_dir= =src @@ -46,6 +44,10 @@ package_dir= [options.packages.find] where=src +[options.entry_points] +console_scripts = + findssh = findssh.__main__:main + [options.extras_require] tests = pytest @@ -56,9 +58,6 @@ lint = flake8-blind-except mypy -[options.entry_points] -console_scripts = - findssh = FindSSH:main [flake8] max-line-length = 132 diff --git a/src/findssh/__init__.py b/src/findssh/__init__.py index 726d8b3..6c2b40f 100644 --- a/src/findssh/__init__.py +++ b/src/findssh/__init__.py @@ -1,2 +1,3 @@ from .coro import get_hosts from .base import netfromaddress, getLANip +from .runner import runner diff --git a/FindSSH.py b/src/findssh/__main__.py similarity index 85% rename from FindSSH.py rename to src/findssh/__main__.py index e0f465c..7f6c754 100755 --- a/FindSSH.py +++ b/src/findssh/__main__.py @@ -18,10 +18,10 @@ import ipaddress as ip from argparse import ArgumentParser -from findssh.base import getLANip, netfromaddress -from findssh.runner import runner -import findssh.coro as coro -import findssh.threadpool as threadpool +from .base import getLANip, netfromaddress +from .runner import runner +from .coro import get_hosts as coro_get_hosts +from .threadpool import get_hosts as threadpool_get_hosts PORT = 22 TIMEOUT = 1.0 @@ -50,9 +50,9 @@ def main(): print("searching", net) if P.threadpool or isinstance(net, ip.IPv6Network): - hosts = threadpool.get_hosts(net, P.port, P.service, P.timeout, debug=P.verbose) + hosts = threadpool_get_hosts(net, P.port, P.service, P.timeout, debug=P.verbose) else: - hosts = runner(coro.get_hosts, net, P.port, P.service, P.timeout) + hosts = runner(coro_get_hosts, net, P.port, P.service, P.timeout) for host, svc in hosts: print(host, svc) diff --git a/src/findssh/tests/test_coro.py b/src/findssh/tests/test_coro.py index a107eff..ca1cec5 100755 --- a/src/findssh/tests/test_coro.py +++ b/src/findssh/tests/test_coro.py @@ -1,23 +1,17 @@ #!/usr/bin/env python import pytest -import subprocess import ipaddress import findssh -from findssh.runner import runner PORT = 22 SERVICE = "" TIMEOUT = 1.0 -def test_script(): - subprocess.check_call(["FindSSH"]) - - def test_coroutine(): net = findssh.netfromaddress(findssh.getLANip()) - hosts = runner(findssh.get_hosts, net, PORT, SERVICE, TIMEOUT) + hosts = findssh.runner(findssh.get_hosts, net, PORT, SERVICE, TIMEOUT) if len(hosts) > 0: host = hosts[0] assert isinstance(host[0], ipaddress.IPv4Address)