Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Python #7

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ jobs:

env:
PY_COLORS: "1"
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 7
max-parallel: 6
matrix:
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pip setuptools
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install sbvirtualdisplay
Expand Down
2 changes: 1 addition & 1 deletion sbvirtualdisplay/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# sbvirtualdisplay package
__version__ = "1.2.0"
__version__ = "1.3.0"
2 changes: 0 additions & 2 deletions sbvirtualdisplay/abstractdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def start(self):
if self.use_xauth:
self._setup_xauth()
EasyProcess.start(self)
# https://github.com/ponty/PyVirtualDisplay/issues/2
# https://github.com/ponty/PyVirtualDisplay/issues/14
self.old_display_var = os.environ.get("DISPLAY", None)
self.redirect_display(True)
# wait until X server is active
Expand Down
6 changes: 2 additions & 4 deletions sbvirtualdisplay/display.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
This module contains a customized version of pyvirtualdisplay.
These helper methods SHOULD NOT be called directly from tests.
"""
"""This module contains a customized version of pyvirtualdisplay.
These helper methods SHOULD NOT be called directly from tests."""
from sbvirtualdisplay.abstractdisplay import AbstractDisplay
from sbvirtualdisplay.xephyr import XephyrDisplay
from sbvirtualdisplay.xvfb import XvfbDisplay
Expand Down
39 changes: 2 additions & 37 deletions sbvirtualdisplay/easyprocess.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Easy to use python subprocess interface."""

from sbvirtualdisplay.unicodeutil import (
split_command,
unidecode,
Expand Down Expand Up @@ -37,8 +36,7 @@ def __str__(self):

class EasyProcessCheckInstalledError(Exception):
"""This exception is raised when a process run by check() returns
a non-zero exit status or OSError is raised.
"""
a non-zero exit status or OSError is raised."""

def __init__(self, easy_process):
self.easy_process = easy_process
Expand Down Expand Up @@ -66,11 +64,6 @@ class EasyProcess(object):

simple interface for :mod:`subprocess`

shell is not supported (shell=False)

.. warning::
unicode is supported only for string list command (Python2.x)
(check :mod:`shlex` for more information)
:param cmd: string ('ls -l') or list of strings (['ls','-l'])
:param cwd: working directory
:param use_temp_files: use temp files instead of pipes for
Expand Down Expand Up @@ -111,7 +104,7 @@ def __init__(
self.cwd = cwd
cmd = split_command(cmd)
self.cmd = cmd
self.cmd_as_string = " ".join(self.cmd) # TODO: not perfect
self.cmd_as_string = " ".join(self.cmd)
log.debug('param: "%s" ', self.cmd_param)
log.debug("command: %s", self.cmd)
log.debug("joined command: %s", self.cmd_as_string)
Expand Down Expand Up @@ -238,13 +231,6 @@ def is_alive(self):
return False

def wait(self, timeout=None):
"""Wait for command to complete.
Timeout:
- discussion:
http://stackoverflow.com/questions/1191374/subprocess-with-timeout
- implementation: threading
:rtype: self
"""
if timeout is not None:
if not self._thread:
self._thread = threading.Thread(target=self._wait4process)
Expand All @@ -257,7 +243,6 @@ def wait(self, timeout=None):
self.timeout_happened or self._thread.isAlive()
)
else:
# no timeout and no existing thread
self._wait4process()
return self

Expand All @@ -281,7 +266,6 @@ def remove_ending_lf(s):
return
time.sleep(POLL_TIME)
else:
# wait() blocks process, timeout not possible
self.popen.wait()
self._outputs_processed = True
self._stdout_file.seek(0)
Expand All @@ -291,15 +275,6 @@ def remove_ending_lf(s):
self._stdout_file.close()
self._stderr_file.close()
else:
# This will deadlock when using stdout=PIPE and/or stderr=PIPE
# and the child process generates enough output to a pipe such
# that it blocks waiting for the OS pipe buffer
# to accept more data.
# Use communicate() to avoid that.
# self.popen.wait()
# self.stdout = self.popen.stdout.read()
# self.stderr = self.popen.stderr.read()
# communicate() blocks process, timeout not possible
self._outputs_processed = True
(self.stdout, self.stderr) = self.popen.communicate()
log.debug("process has ended")
Expand All @@ -310,12 +285,6 @@ def remove_ending_lf(s):
log.debug("stderr=%s", self.stderr)

def stop(self):
"""Kill process and wait for command to complete.
same as:
1. :meth:`sendstop`
2. :meth:`wait`
:rtype: self
"""
return self.sendstop().wait()

def sendstop(self):
Expand Down Expand Up @@ -345,10 +314,6 @@ def sendstop(self):
return self

def sleep(self, sec):
"""
sleeping (same as :func:`time.sleep`)
:rtype: self
"""
time.sleep(sec)
return self

Expand Down
38 changes: 2 additions & 36 deletions sbvirtualdisplay/unicodeutil.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import shlex
import sys
import unicodedata


PY3 = sys.version_info[0] >= 3

if PY3:
string_types = (str,)
else:
string_types = (basestring,) # noqa: ignore=F821


class EasyProcessUnicodeError(Exception):
pass
string_types = (str,)


def split_command(cmd, posix=None):
Expand All @@ -26,38 +15,15 @@ def split_command(cmd, posix=None):
# cmd is string list
pass
else:
if not PY3:
# cmd is string
# The shlex module currently does not support Unicode input in 2.x
if isinstance(cmd, unicode): # noqa: ignore=F821
try:
cmd = unicodedata.normalize("NFKD", cmd).encode(
"ascii", "strict"
)
except UnicodeEncodeError:
raise EasyProcessUnicodeError(
'unicode command "%s" can not be processed.' % cmd + ""
"Use string list instead of string"
)
if posix is None:
posix = "win" not in sys.platform
cmd = shlex.split(cmd, posix=posix)
return cmd


def uniencode(s):
if PY3:
pass
else:
if isinstance(s, unicode): # noqa: ignore=F821
s = s.encode("utf-8")
return s


def unidecode(s):
if PY3:
s = s.decode("utf-8", "ignore")
else:
if isinstance(s, str):
s = s.decode("utf-8", "ignore")
return s
return s.decode("utf-8", "ignore")
59 changes: 31 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
*** sbvirtualdisplay ***
"""*** sbvirtualdisplay ***
A modified version of pyvirtualdisplay for optimized SeleniumBase performance.
(Python 2.7+ and Python 3.6+)
"""

(Python 3.7+)"""
from setuptools import setup
import os
import sys
Expand Down Expand Up @@ -33,13 +30,11 @@
if sys.argv[-1] == "publish":
reply = None
input_method = input
if not sys.version_info[0] >= 3:
input_method = raw_input # noqa: F821
confirm_text = ">>> Confirm release PUBLISH to PyPI? (yes/no): "
reply = str(input_method(confirm_text)).lower().strip()
if reply == "yes":
print("\n*** Checking code health with flake8:\n")
os.system("python -m pip install 'flake8==5.0.4'")
os.system("python -m pip install 'flake8==6.1.0'")
flake8_status = os.system("flake8 --exclude=recordings,temp")
if flake8_status != 0:
print("\nWARNING! Fix flake8 issues before publishing to PyPI!\n")
Expand All @@ -50,11 +45,23 @@
os.system("rm -f dist/*.egg; rm -f dist/*.tar.gz; rm -f dist/*.whl")
os.system("rm -rf build/bdist.*; rm -rf build/lib")
print("\n*** Installing build: *** (Required for PyPI uploads)\n")
os.system("python -m pip install --upgrade 'build>=0.9.0'")
os.system("python -m pip install --upgrade 'build'")
print("\n*** Installing pkginfo: *** (Required for PyPI uploads)\n")
os.system("python -m pip install --upgrade 'pkginfo'")
print("\n*** Installing readme-renderer: *** (For PyPI uploads)\n")
os.system("python -m pip install --upgrade 'readme-renderer'")
print("\n*** Installing jaraco.classes: *** (For PyPI uploads)\n")
os.system("python -m pip install --upgrade 'jaraco.classes'")
print("\n*** Installing more-itertools: *** (For PyPI uploads)\n")
os.system("python -m pip install --upgrade 'more-itertools'")
print("\n*** Installing zipp: *** (Required for PyPI uploads)\n")
os.system("python -m pip install --upgrade 'zipp'")
print("\n*** Installing importlib-metadata: *** (For PyPI uploads)\n")
os.system("python -m pip install --upgrade 'importlib-metadata'")
print("\n*** Installing keyring, requests-toolbelt: *** (For PyPI)\n")
os.system("python -m pip install --upgrade keyring requests-toolbelt")
print("\n*** Installing twine: *** (Required for PyPI uploads)\n")
os.system("python -m pip install --upgrade 'twine>=4.0.1'")
print("\n*** Installing tqdm: *** (Required for PyPI uploads)\n")
os.system("python -m pip install --upgrade tqdm")
os.system("python -m pip install --upgrade 'twine'")
print("\n*** Rebuilding distribution packages: ***\n")
os.system("python -m build") # Create new tar/wheel
print("\n*** Publishing The Release to PyPI: ***\n")
Expand Down Expand Up @@ -98,8 +105,6 @@
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand All @@ -116,29 +121,27 @@
"Topic :: Software Development :: Testing :: Traffic Generation",
"Topic :: Utilities",
],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*", # noqa: E501
python_requires=">=3.7",
install_requires=[],
extras_require={
# pip install -e .[coverage]
# Usage: coverage run -m pytest; coverage html; coverage report
"coverage": [
'coverage==5.5;python_version<"3.6"',
'coverage==6.2;python_version>="3.6" and python_version<"3.7"',
'coverage==6.5.0;python_version>="3.7"',
'pytest-cov==2.12.1;python_version<"3.6"',
'pytest-cov==4.0.0;python_version>="3.6"',
'coverage==7.2.7;python_version<"3.8"',
'coverage==7.3.2;python_version>="3.8"',
'pytest-cov==4.1.0',
],

# pip install -e .[flake8]
# Usage: flake8
"flake8": [
'flake8==3.7.9;python_version<"3.6"',
'flake8==5.0.4;python_version>="3.6"',
'mccabe==0.6.1;python_version<"3.6"',
'mccabe==0.7.0;python_version>="3.6"',
'pyflakes==2.1.1;python_version<"3.6"',
'pyflakes==2.5.0;python_version>="3.6"',
'pycodestyle==2.5.0;python_version<"3.6"',
'pycodestyle==2.9.1;python_version>="3.6"',
'flake8==5.0.4;python_version<"3.9"',
'flake8==6.1.0;python_version>="3.9"',
"mccabe==0.7.0",
'pyflakes==2.5.0;python_version<"3.9"',
'pyflakes==3.1.0;python_version>="3.9"',
'pycodestyle==2.9.1;python_version<"3.9"',
'pycodestyle==2.11.1;python_version>="3.9"',
],
},
packages=[
Expand Down