From b0056e75e26a2b50319e46c05acc4052c5aca677 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 13:43:51 -0700 Subject: [PATCH 1/9] adds setup.py packaging for native python installing --- MANIFEST.in | 3 +++ southwest/VERSION | 1 + southwest/__init__.py | 5 +++++ checkin.py => southwest/checkin.py | 7 +++++-- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 MANIFEST.in create mode 100644 southwest/VERSION rename checkin.py => southwest/checkin.py (98%) diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..fb9f59b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include README +include LICENSE +include southwest/VERSION \ No newline at end of file diff --git a/southwest/VERSION b/southwest/VERSION new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/southwest/VERSION @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/southwest/__init__.py b/southwest/__init__.py index 6cfa8d1..b935ca6 100644 --- a/southwest/__init__.py +++ b/southwest/__init__.py @@ -1,2 +1,7 @@ +import pkgutil + from .southwest import Reservation from .openflights import timezone_for_airport + +__library_name__ = "southwest" +__version__ = pkgutil.get_data(__library_name__, "VERSION").decode("utf-8") diff --git a/checkin.py b/southwest/checkin.py similarity index 98% rename from checkin.py rename to southwest/checkin.py index d8e4358..861eaba 100755 --- a/checkin.py +++ b/southwest/checkin.py @@ -85,8 +85,8 @@ def auto_checkin(reservation_number, first_name, last_name, verbose=False): break -if __name__ == '__main__': - +def checkin(): + """main function: for entry_point""" arguments = docopt(__doc__, version='Southwest Checkin 3') reservation_number = arguments['CONFIRMATION_NUMBER'] first_name = arguments['FIRST_NAME'] @@ -102,3 +102,6 @@ def auto_checkin(reservation_number, first_name, last_name, verbose=False): except KeyboardInterrupt: print("Ctrl+C detected, canceling checkin") sys.exit() + +if __name__ == '__main__': + checkin() From 20c904845cd80f123f000e677df2b4ef50639316 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:21:15 -0700 Subject: [PATCH 2/9] fixes tests/docker for new packaging method --- .dockerignore | 1 - .gitignore | 6 ++++- Dockerfile | 4 +--- MANIFEST.in | 2 +- Makefile | 6 ++++- entrypoint.sh | 2 +- setup.py | 54 +++++++++++++++++++++++++++++++++++++++++++ tests/checkin_test.py | 2 +- 8 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 setup.py diff --git a/.dockerignore b/.dockerignore index 5c4a3fb..3379372 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,4 @@ *.pyc Dockerfile -README.md htmlcov/ *.xml diff --git a/.gitignore b/.gitignore index 5e928d9..388a772 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,8 @@ .cache/ .coverage htmlcov/ -coverage.xml \ No newline at end of file +coverage.xml +.DS_Store +*.egg-info/ +dist/ +*venv diff --git a/Dockerfile b/Dockerfile index c4cdf13..3d33c5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,7 @@ FROM python:3.7 WORKDIR /usr/src/app -COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt - COPY . . +RUN pip install .[dev] --no-cache-dir ENTRYPOINT ["./entrypoint.sh"] diff --git a/MANIFEST.in b/MANIFEST.in index fb9f59b..2ec3af3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include README +include README.md include LICENSE include southwest/VERSION \ No newline at end of file diff --git a/Makefile b/Makefile index 707faae..ccde432 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: init test lint init: - pip install -r requirements.txt + pip install -e .[dev] test: pytest --cov=southwest/ --cov=checkin @@ -11,6 +11,10 @@ lint: docker: docker build -t pyro2927/southwestcheckin . +docker-test: docker + docker run --rm -it pyro2927/southwestcheckin bash + + release: docker push pyro2927/southwestcheckin diff --git a/entrypoint.sh b/entrypoint.sh index 7c99f5b..ceda5f5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,7 @@ set -e if [ "$1" != "/bin/sh" ]; then - python -u ./checkin.py "$@" + checkin "$@" else exec "$@" fi diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0fc2b1b --- /dev/null +++ b/setup.py @@ -0,0 +1,54 @@ +"""setup.py + +Packaging for direct pypi distribution and cli entrypoints + +""" +from setuptools import setup, find_packages +from pathlib import Path +from codecs import open + +__library_name__ = "southwest" +__here__ = Path(__file__).resolve().parent + +with open(__here__/"README.md", "rb") as f: + __readme__ = f.read() + +with open(__here__/__library_name__/"VERSION", "r") as f: + __version__ = f.read().strip() + + +setup( + name="SouthwestCheckin", + description="Python script to checkin to a Southwest Flight", + long_description=__readme__, + long_description_content_type="text/markdown", + url="https://github.com/pyro2927/SouthwestCheckin", + license="GPL-3.0", + packages=find_packages(exclude=["tests"]), + version=__version__, + install_requires=[ + "datetime", + "docopts", + "python-dateutil", + "pytz", + "requests", + "uuid", + "vcrpy", + ], + extras_require={ + "dev": [ + "pycodestyle", + "pytest", + "pytest-cov", + "pytest-mock", + "requests_mock", + ] + }, + entry_points={ + "console_scripts":[ + "checkin={}.checkin:checkin".format(__library_name__) + ] + }, + package_data={"": ["README.md", "LICENSE"], __library_name__: ["VERSION"]}, + include_package_data=True, +) diff --git a/tests/checkin_test.py b/tests/checkin_test.py index a8fd8c9..0b5bd35 100644 --- a/tests/checkin_test.py +++ b/tests/checkin_test.py @@ -2,7 +2,7 @@ import pytest import requests import southwest -import checkin +from southwest import checkin from datetime import datetime, timedelta from .my_vcr import custom_vcr from pytz import timezone From 2fffa6f8861701972770799bca6a81c9804bd4e8 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:21:54 -0700 Subject: [PATCH 3/9] black setup.py --- setup.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 0fc2b1b..c1c54e6 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,10 @@ __library_name__ = "southwest" __here__ = Path(__file__).resolve().parent -with open(__here__/"README.md", "rb") as f: +with open(__here__ / "README.md", "rb") as f: __readme__ = f.read() -with open(__here__/__library_name__/"VERSION", "r") as f: +with open(__here__ / __library_name__ / "VERSION", "r") as f: __version__ = f.read().strip() @@ -36,18 +36,10 @@ "vcrpy", ], extras_require={ - "dev": [ - "pycodestyle", - "pytest", - "pytest-cov", - "pytest-mock", - "requests_mock", - ] + "dev": ["pycodestyle", "pytest", "pytest-cov", "pytest-mock", "requests_mock",] }, entry_points={ - "console_scripts":[ - "checkin={}.checkin:checkin".format(__library_name__) - ] + "console_scripts": ["checkin={}.checkin:checkin".format(__library_name__)] }, package_data={"": ["README.md", "LICENSE"], __library_name__: ["VERSION"]}, include_package_data=True, From 80451c511388846e70c8f96393f811b70b919fa0 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:24:20 -0700 Subject: [PATCH 4/9] fixes travis command and updates README instructions --- .travis.yml | 2 ++ Makefile | 4 ---- README.md | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index b18c94b..9b1f296 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: python env: global: - CC_TEST_REPORTER_ID=3d0abe23b60c405d5de7e038f366649a8002c4ccedccabad3da0e3b3e9b5049b +install: + pip install .[dev] python: - "2.7.15" - "3.7.1" diff --git a/Makefile b/Makefile index ccde432..7aeabcc 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,6 @@ lint: docker: docker build -t pyro2927/southwestcheckin . -docker-test: docker - docker run --rm -it pyro2927/southwestcheckin bash - - release: docker push pyro2927/southwestcheckin diff --git a/README.md b/README.md index 0c2a5bb..5f294ec 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ This script can either be ran directly on your host or within Docker. #### Install Base Package Requirements ```bash -$ pip install -r requirements.txt +$ pip install . ``` #### Usage ```bash -$ python ./checkin.py CONFIRMATION_NUMBER FIRST_NAME LAST_NAME +$ checkin CONFIRMATION_NUMBER FIRST_NAME LAST_NAME ``` ### Docker From 0892c36309c566153360101c47c2f49f4e376eb9 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:32:49 -0700 Subject: [PATCH 5/9] fixes travis install problem --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c1c54e6..4e1d6da 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ __library_name__ = "southwest" __here__ = Path(__file__).resolve().parent -with open(__here__ / "README.md", "rb") as f: +with open(__here__ / "README.md", "r", "utf-8") as f: __readme__ = f.read() with open(__here__ / __library_name__ / "VERSION", "r") as f: From 9f4536ea4120a7b833bfcc6a442092f121f3b4e5 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:34:46 -0700 Subject: [PATCH 6/9] fixes pycodestyle error --- southwest/checkin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/southwest/checkin.py b/southwest/checkin.py index 861eaba..ca80929 100755 --- a/southwest/checkin.py +++ b/southwest/checkin.py @@ -103,5 +103,6 @@ def checkin(): print("Ctrl+C detected, canceling checkin") sys.exit() + if __name__ == '__main__': checkin() From 136f2faeff9bc18f1d4efabd61d2ba644c6a2a52 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:39:33 -0700 Subject: [PATCH 7/9] removing pathlib to support py2 --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 4e1d6da..1c153ab 100644 --- a/setup.py +++ b/setup.py @@ -4,16 +4,16 @@ """ from setuptools import setup, find_packages -from pathlib import Path +from os import path from codecs import open __library_name__ = "southwest" -__here__ = Path(__file__).resolve().parent +__here__ = path.dirname(__file__) -with open(__here__ / "README.md", "r", "utf-8") as f: +with open(path.join(__here__,"README.md"), "r", "utf-8") as f: __readme__ = f.read() -with open(__here__ / __library_name__ / "VERSION", "r") as f: +with open(path.join(__here__, __library_name__ , "VERSION"), "r") as f: __version__ = f.read().strip() From 383d390b8461b8dac463c05dd04b387995b76010 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:44:42 -0700 Subject: [PATCH 8/9] fixes py2 import error --- southwest/checkin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/southwest/checkin.py b/southwest/checkin.py index ca80929..db975bd 100755 --- a/southwest/checkin.py +++ b/southwest/checkin.py @@ -18,7 +18,7 @@ from docopt import docopt from math import trunc from pytz import utc -from southwest import Reservation, openflights +from . import Reservation, openflights from threading import Thread import sys import time From d0fa161f99a8bf0897c1345a9ba3961f50051ec3 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 18 Aug 2021 14:49:57 -0700 Subject: [PATCH 9/9] black setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 1c153ab..adbdd5b 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,10 @@ __library_name__ = "southwest" __here__ = path.dirname(__file__) -with open(path.join(__here__,"README.md"), "r", "utf-8") as f: +with open(path.join(__here__, "README.md"), "r", "utf-8") as f: __readme__ = f.read() -with open(path.join(__here__, __library_name__ , "VERSION"), "r") as f: +with open(path.join(__here__, __library_name__, "VERSION"), "r") as f: __version__ = f.read().strip()