diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index dd95a4a..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: test - -on: [push] - -jobs: - ci: - name: Python-${{ matrix.python }} ${{ matrix.qt.qt_api }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - qt: - - package: PyQt5 - qt_api: "pyqt5" - - package: PyQt6 - qt_api: "pyqt6" - - package: PySide2 - qt_api: "pyside2" - - package: PySide6 - qt_api: "pyside6" - python: [3.6, 3.7, 3.8, 3.9] - - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - architecture: x64 - - name: Install pipenv - run: | - python -m pip install --upgrade pipenv wheel - - name: Install dependencies - run: | - pipenv install --dev - pipenv run pip install ${{ matrix.qt.package }} pytest - - name: Install Libxcb dependencies - run: | - sudo apt-get update - sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev - - name: Run headless test - uses: GabrielBB/xvfb-action@v1 - env: - QT_API: ${{ matrix.qt.qt_api }} - with: - run: pipenv run py.test --forked -v diff --git a/Pipfile b/Pipfile deleted file mode 100644 index bfe9dad..0000000 --- a/Pipfile +++ /dev/null @@ -1,16 +0,0 @@ -[[source]] -url = "https://pypi.org/simple" -name = "pypi" -verify_ssl = true - -[dev-packages] -atomicwrites = "*" -pytest = "*" -pytest-forked = "*" -pytest-raises = "*" - -[packages] - -[dev-packages.phantomjs] -editable = true -path = "." diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/phantompy/__main__.py b/__main__.py similarity index 69% rename from phantompy/__main__.py rename to __main__.py index bbc9d62..6b975db 100644 --- a/phantompy/__main__.py +++ b/__main__.py @@ -1,13 +1,10 @@ #!/usr/local/bin/python3.sh # -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -* -from __future__ import absolute_import -import sys - -from .qasync_phantompy import iMain +from qasync_phantompy import iMain try: - from .support_phantompy import vsetup_logging + from support_phantompy import vsetup_logging d = int(os.environ.get('DEBUG', 0)) if d > 0: vsetup_logging(10, stream=sys.stderr) @@ -17,4 +14,4 @@ try: except: pass if __name__ == '__main__': - iMain(sys.argv[1:]) + iMain(sys.argv[1:], bgui=False) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8241a6d..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,22 +0,0 @@ -environment: - matrix: - - PYTHON: "C:\\Python36" - - PYTHON: "C:\\Python37" - - PYTHON: "C:\\Python38" - - PYTHON: "C:\\Python39" - -init: - - set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH% - -install: - - pip install pipenv - - pipenv install --dev - - pipenv run pip install PyQt5 PySide2 - # FIX: colorama not installed by pipenv - - pipenv run pip install colorama - -build: off - -test_script: - - set QT_API=PyQt5&& pipenv run py.test -v - - set QT_API=PySide2&& pipenv run py.test -v diff --git a/phantompy/lookupdns.py b/lookupdns.py similarity index 100% rename from phantompy/lookupdns.py rename to lookupdns.py diff --git a/phantompy/phantompy.py b/phantompy.py similarity index 93% rename from phantompy/phantompy.py rename to phantompy.py index e8da790..a2bff2d 100644 --- a/phantompy/phantompy.py +++ b/phantompy.py @@ -118,20 +118,21 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import importlib +import sys import os -import sys # noqa +import traceback +import atexit +import time -from qasync import QtModuleName -from qasync.QtCore import QUrl - -QPrinter = importlib.import_module(QtModuleName + ".QtPrintSupport.QPrinter", package=QtModuleName) -QWebEnginePage = importlib.import_module(QtModuleName + ".QtWebEngineWidgets.QWebEnginePage", package=QtModuleName) +from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QTimer +from PyQt5.QtWidgets import QApplication +from PyQt5.QtPrintSupport import QPrinter +from PyQt5.QtWebEngineWidgets import QWebEnginePage global LOG import logging import warnings - warnings.filterwarnings('ignore') LOG = logging.getLogger() @@ -180,19 +181,19 @@ class Render(QWebEnginePage): self.htmlfile = htmlfile self.pdffile = pdffile self.outfile = pdffile or htmlfile - LOG.debug(f"phantom.py: URL={url} htmlfile={htmlfile} pdffile={pdffile} JSFILE={jsfile}") + LOG.debug(f"phantom.py: URL={url} OUTFILE={outfile} JSFILE={jsfile}") qurl = QUrl.fromUserInput(url) # The PDF generation only happens when the special string __PHANTOM_PY_DONE__ # is sent to console.log(). The following JS string will be executed by # default, when no external JavaScript file is specified. - self.js_contents = "setTimeout(function() { console.log('__PHANTOM_PY_DONE__') }, 5000);" + self.js_contents = "setTimeout(function() { console.log('__PHANTOM_PY_DONE__') }, 5000);"; if jsfile: try: with open(self.jsfile, 'rt') as f: self.js_contents = f.read() - except Exception as e: # noqa + except Exception as e: LOG.exception(f"error reading jsfile {self.jsfile}") self.loadFinished.connect(self._loadFinished) @@ -238,7 +239,7 @@ class Render(QWebEnginePage): """print(self, QPrinter, Callable[[bool], None])""" if type(args[0]) is str: self._save(args[0]) - self._onConsoleMessage(0, "__PHANTOM_PY_SAVED__", 0, '') + self._onConsoleMessage(0, "__PHANTOM_PY_SAVED__", 0 , '') def _save(self, html): sfile = self.htmlfile @@ -253,7 +254,7 @@ class Render(QWebEnginePage): i = 1 else: i = 0 - self._onConsoleMessage(i, "__PHANTOM_PY_PRINTED__", 0, '') + self._onConsoleMessage(i, "__PHANTOM_PY_PRINTED__", 0 , '') def _print(self): sfile = self.pdffile @@ -261,7 +262,7 @@ class Render(QWebEnginePage): printer.setPageMargins(10, 10, 10, 10, QPrinter.Millimeter) printer.setPaperSize(QPrinter.A4) printer.setCreator("phantom.py by Michael Karl Franzl") - printer.setOutputFormat(QPrinter.PdfFormat) + printer.setOutputFormat(QPrinter.PdfFormat); printer.setOutputFileName(sfile) self.print(printer, self._printer_callback) LOG.debug("phantom.py: Printed") @@ -271,3 +272,4 @@ class Render(QWebEnginePage): LOG.debug(f"phantom.py: Exiting with val {val}") # threadsafe? self._app.ldone.append(self.uri) + diff --git a/phantompy/__init__.py b/phantompy/__init__.py deleted file mode 100644 index b8cbc42..0000000 --- a/phantompy/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 2; coding: utf-8 -*- - -__version__ = "0.1.0" diff --git a/phantompy/qasync_phantompy.py b/qasync_phantompy.py similarity index 90% rename from phantompy/qasync_phantompy.py rename to qasync_phantompy.py index 5a01d65..99927ba 100644 --- a/phantompy/qasync_phantompy.py +++ b/qasync_phantompy.py @@ -1,30 +1,26 @@ #!/usr/local/bin/python3.sh # -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -* -import asyncio -import os import sys +import os +import asyncio +import time +import random # let qasync figure out what Qt we are using - we dont care -from qasync import QApplication, QEventLoop, QtWidgets +from qasync import QApplication, QtWidgets, QEventLoop from phantompy import Render # if you want an example of looking for things in downloaded HTML: # from lookupdns import LookFor as Render -from support_phantompy import omain_argparser, vsetup_logging +from support_phantompy import vsetup_logging, omain_argparser global LOG import logging import warnings - warnings.filterwarnings('ignore') LOG = logging.getLogger() -try: - import shtab -except: - shtab = None - class Widget(QtWidgets.QWidget): def __init__(self): QtWidgets.QWidget.__init__(self) @@ -42,17 +38,13 @@ class Widget(QtWidgets.QWidget): self.progress.setValue(int(text)) class ContextManager: - def __init__(self) -> None: self._seconds = 0 - async def __aenter__(self): LOG.debug("ContextManager enter") return self - async def __aexit__(self, *args): LOG.debug("ContextManager exit") - async def tick(self): await asyncio.sleep(1) self._seconds += 1 @@ -73,15 +65,13 @@ async def main(widget, app, ilen): # raise asyncio.CancelledError return LOG.debug(f"{app.ldone} {seconds}") - except asyncio.CancelledError as ex: # noqa + except asyncio.CancelledError as ex: LOG.debug("Task cancelled") def iMain(largs): parser = omain_argparser() - if shtab: - shtab.add_argument_to(parser, ["-s", "--print-completion"]) # magic! oargs = parser.parse_args(largs) - bgui = oargs.show_gui + bgui=oargs.show_gui try: d = int(os.environ.get('DEBUG', 0)) @@ -125,4 +115,6 @@ def iMain(largs): loop.run_until_complete(asyncio.gather(*tasks)) if __name__ == '__main__': + iMain(sys.argv[1:]) + diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 4d1c6bd..0000000 --- a/setup.cfg +++ /dev/null @@ -1,57 +0,0 @@ -[metadata] -classifiers = - License :: OSI Approved - License :: OSI Approved :: BSD 1-clause - Intended Audience :: Web Developers - Operating System :: Microsoft :: Windows - Operating System :: POSIX :: BSD :: FreeBSD - Operating System :: POSIX :: Linux - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: Implementation :: CPython - Framework :: AsyncIO - -[options] -zip_safe = false -python_requires = ~=3.6 -packages = find: -include_package_data = false -install_requires = - qasync - attrs - typing-extensions ; python_version < '3.8' - -[options.entry_points] -console_scripts = - phantompy = phantompy.__main__:iMain - -[easy_install] -zip_ok = false - -[flake8] -jobs = 1 -max-line-length = 88 -ignore = - E111 - E114 - E128 - E225 - E225 - E261 - E302 - E305 - E402 - E501 - E502 - E541 - E701 - E704 - E722 - E741 - F508 - F541 - W503 - \ No newline at end of file diff --git a/setup.py b/setup.py index b3aceb4..bdf9f6e 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,8 @@ # -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -* -import re from setuptools import setup -with open("qasync/__init__.py") as f: - version = re.search(r'__version__\s+=\s+"(.*)"', f.read()).group(1) +__version__ = "0.1.0" long_description = "\n\n".join([ open("README.md").read(), @@ -22,9 +20,9 @@ if __name__ == '__main__': packages=['phantompy'], # url="", # download_url="https://", - keywords=['JavaScript', 'phantomjs', 'asyncio'], + keywords=['JavaScript', 'phantomjs'], # maybe less - nothing fancy - python_requires="~=3.6", + python_requires=">=3.6", # probably works on PyQt6 and PySide2 but untested # https://github.com/CabbageDevelopment/qasync/ install_requires=['qasync', 'PyQt5'], diff --git a/phantompy/support_phantompy.py b/support_phantompy.py similarity index 98% rename from phantompy/support_phantompy.py rename to support_phantompy.py index 4b957b4..1c81f3f 100644 --- a/phantompy/support_phantompy.py +++ b/support_phantompy.py @@ -1,22 +1,21 @@ #!/usr/local/bin/python3.sh # -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -* -import argparse -import os import sys +import os +import argparse try: if 'COLOREDLOGS_LEVEL_STYLES' not in os.environ: os.environ['COLOREDLOGS_LEVEL_STYLES'] = 'spam=22;debug=28;verbose=34;notice=220;warning=202;success=118,bold;error=124;critical=background=red' # https://pypi.org/project/coloredlogs/ import coloredlogs -except ImportError: +except ImportError as e: coloredlogs = False global LOG import logging import warnings - warnings.filterwarnings('ignore') LOG = logging.getLogger() @@ -25,7 +24,7 @@ def vsetup_logging(log_level, logfile='', stream=sys.stdout): add = True # stem fucks up logging - # from stem.util import log + from stem.util import log logging.getLogger('stem').setLevel(30) logging._defaultFormatter = logging.Formatter(datefmt='%m-%d %H:%M:%S') diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 2d4eff1..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- - -# (c) 2018 Gerard Marull-Paretas -# (c) 2014 Mark Harviston -# (c) 2014 Arve Knudsen -# BSD License - -# phantompy test - just test qasync for now - -import os -import logging -from pytest import fixture - -logging.basicConfig( - level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s" -) - -@fixture(scope="session") -def application(): - from phantompy.qasync_phantompy import QApplication - - return QApplication([])