Skip to content

Commit

Permalink
slim down winmake.py
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 21, 2024
1 parent a6beca1 commit 608be3d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install pydeps ${{ matrix.os }}
if: matrix.os == 'windows-latest'
run: |
python.exe -m pip install --upgrade pypiwin32 wmi pyopenssl psutil pytest
python.exe -m pip install --upgrade pypiwin32 wmi pyopenssl psutil pytest pyasyncore pyasynchat
- name: Install pydeps ${{ matrix.os }}
if: matrix.os != 'windows-latest'
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ install-pip: ## Install pip (no-op if already installed).

install-pydeps-test: ## Install python deps necessary to run unit tests.
${MAKE} install-pip
$(PYTHON) -m pip install $(PIP_INSTALL_ARGS) pip # upgrade pip to latest version
$(PYTHON) -m pip install $(PIP_INSTALL_ARGS) pip setuptools
$(PYTHON) -m pip install $(PIP_INSTALL_ARGS) `$(PYTHON) -c "import setup; print(' '.join(setup.TEST_DEPS))"`

install-pydeps-dev: ## Install python deps meant for local development.
${MAKE} install-git-hooks
${MAKE} install-pip
$(PYTHON) -m pip install $(PIP_INSTALL_ARGS) pip # upgrade pip to latest version
$(PYTHON) -m pip install $(PIP_INSTALL_ARGS) pip setuptools
$(PYTHON) -m pip install $(PIP_INSTALL_ARGS) `$(PYTHON) -c "import setup; print(' '.join(setup.TEST_DEPS + setup.DEV_DEPS))"`

# ===================================================================
Expand Down
26 changes: 4 additions & 22 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,12 @@

rem ==========================================================================
rem Shortcuts for various tasks, emulating UNIX "make" on Windows.
rem It is primarly intended as a shortcut for compiling / installing
rem psutil ("make.bat build", "make.bat install") and running tests
rem ("make.bat test").
rem
rem To compile for a specific Python version run:
rem set PYTHON=C:\Python34\python.exe & make.bat build
rem
rem To use a different test script:
rem set PYTHON=C:\Python34\python.exe & set TSCRIPT=foo.py & make.bat test
rem To use a specific Python version run:
rem set PYTHON=C:\Python34\python.exe & make.bat test
rem ==========================================================================

if "%PYTHON%" == "" (
if exist "C:\Python37\python.exe" (
set PYTHON=C:\Python37\python.exe
) else (
set PYTHON=C:\Python27\python.exe
)
set PYTHON=python
)

if "%TSCRIPT%" == "" (
set TSCRIPT=psutil\tests\__main__.py
)

rem Needed to locate the .pypirc file and upload exes on PyPI.
set HOME=%USERPROFILE%

%PYTHON% scripts\winmake.py %1 %2 %3 %4 %5 %6
%PYTHON% scripts\internal\winmake.py %1 %2 %3 %4 %5 %6
125 changes: 12 additions & 113 deletions scripts/internal/winmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@


import argparse
import atexit
import ctypes
import errno
import fnmatch
import os
Expand All @@ -25,11 +23,9 @@


PYTHON = os.getenv('PYTHON', sys.executable)
PY3 = sys.version_info[0] >= 3
PYTEST_ARGS = "-v -s --tb=short"
HERE = os.path.abspath(os.path.dirname(__file__))
ROOT_DIR = os.path.realpath(os.path.join(HERE, "..", ".."))
PYPY = '__pypy__' in sys.builtin_module_names
WINDOWS = os.name == "nt"


Expand All @@ -40,14 +36,6 @@
TEST_DEPS = setup.TEST_DEPS
DEV_DEPS = setup.DEV_DEPS

_cmds = {}

GREEN = 2
LIGHTBLUE = 3
YELLOW = 6
RED = 4
DEFAULT_COLOR = 7


# ===================================================================
# utils
Expand All @@ -73,28 +61,6 @@ def safe_print(text, file=sys.stdout):
file.write("\n")


def stderr_handle():
GetStdHandle = ctypes.windll.Kernel32.GetStdHandle
STD_ERROR_HANDLE_ID = ctypes.c_ulong(0xFFFFFFF4)
GetStdHandle.restype = ctypes.c_ulong
handle = GetStdHandle(STD_ERROR_HANDLE_ID)
atexit.register(ctypes.windll.Kernel32.CloseHandle, handle)
return handle


def win_colorprint(s, color=LIGHTBLUE):
if not WINDOWS:
return print(s)
color += 8 # bold
handle = stderr_handle()
SetConsoleTextAttribute = ctypes.windll.Kernel32.SetConsoleTextAttribute
SetConsoleTextAttribute(handle, color)
try:
print(s)
finally:
SetConsoleTextAttribute(handle, DEFAULT_COLOR)


def sh(cmd, nolog=False):
if not nolog:
safe_print("cmd: " + cmd)
Expand Down Expand Up @@ -193,60 +159,13 @@ def recursive_rm(*patterns):
# ===================================================================


def build():
"""Build / compile."""
# Make sure setuptools is installed (needed for 'develop' /
# edit mode).
sh(f'{PYTHON} -c "import setuptools"')

cmd = [PYTHON, "setup.py", "build"]
# Print coloured warnings in real time.
p = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
)
try:
for line in iter(p.stdout.readline, ''):
line = line.strip()
if 'warning' in line:
win_colorprint(line, YELLOW)
elif 'error' in line:
win_colorprint(line, RED)
else:
print(line)
# retcode = p.poll()
p.communicate()
if p.returncode:
win_colorprint("failure", RED)
sys.exit(p.returncode)
finally:
p.terminate()
p.wait()

# Make sure it actually worked.
sh(f'{PYTHON} -c "import pyftpdlib"')
win_colorprint("build + import successful", GREEN)


def wheel():
"""Create wheel file."""
build()
sh(f"{PYTHON} setup.py bdist_wheel")


def upload_wheels():
"""Upload wheel files on PyPI."""
build()
sh(f"{PYTHON} -m twine upload dist/*.whl")


def install_pip():
"""Install pip."""
sh('%s %s' % (PYTHON, os.path.join(HERE, "install_pip.py")))


def install():
"""Install in develop / edit mode."""
build()
sh(f"{PYTHON} setup.py develop")


Expand Down Expand Up @@ -333,48 +252,42 @@ def install_pydeps_dev():

def test(args=""):
"""Run tests."""
build()
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} {args}")


def test_authorizers():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_authorizers.py")
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} pyftpdlib/test/test_authorizers.py")


def test_filesystems():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_filesystems.py")
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} pyftpdlib/test/test_filesystems.py")


def test_functional():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_functional.py")
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} pyftpdlib/test/test_functional.py")


def test_functional_ssl():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_functional_ssl.py")
sh(
f"{PYTHON} -m pytest"
f" {PYTEST_ARGS} pyftpdlib/test/test_functional_ssl.py"
)


def test_ioloop():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_ioloop.py")
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} pyftpdlib/test/test_ioloop.py")


def test_cli():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_cli.py")
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} pyftpdlib/test/test_cli.py")


def test_servers():
build()
sh(f"{PYTHON} pyftpdlib\\test\\test_servers.py")
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} pyftpdlib/test/test_servers.py")


def coverage():
"""Run coverage tests."""
build()
sh(f"{PYTHON} -m coverage run -m pytest {PYTEST_ARGS}")
sh(f"{PYTHON} -m coverage report")
sh(f"{PYTHON} -m coverage html")
Expand All @@ -383,13 +296,11 @@ def coverage():

def test_by_name(name):
"""Run test by name."""
build()
test(name)


def test_last_failed():
"""Re-run tests which failed on last run."""
build()
sh(f"{PYTHON} -m pytest {PYTEST_ARGS} --last-failed")


Expand All @@ -414,15 +325,6 @@ def get_python(path):
# try to look for a python installation given a shortcut name
path = path.replace('.', '')
vers = (
'27',
'27-32',
'27-64',
'36',
'36-32',
'36-64',
'37',
'37-32',
'37-64',
'38',
'38-32',
'38-64',
Expand All @@ -440,24 +342,21 @@ def parse_args():
# option shared by all commands
parser.add_argument('-p', '--python', help="use python executable path")
sp = parser.add_subparsers(dest='command', title='targets')
sp.add_parser('build', help="build")
sp.add_parser('clean', help="deletes dev files")
sp.add_parser('coverage', help="run coverage tests.")
sp.add_parser('help', help="print this help")
sp.add_parser('install', help="build + install in develop/edit mode")
sp.add_parser('install', help="install in develop/edit mode")
sp.add_parser('install-git-hooks', help="install GIT pre-commit hook")
sp.add_parser('install-pip', help="install pip")
sp.add_parser('install-pydeps-dev', help="install dev python deps")
sp.add_parser('install-pydeps-test', help="install python test deps")
sp.add_parser('test', help="run tests")
sp.add_parser('test-authorizers')
sp.add_parser('test-filesystems')
sp.add_parser('test-functional')
sp.add_parser('test-functional-ssl')
sp.add_parser('test-ioloop')
sp.add_parser('test-misc')
sp.add_parser('test-servers')
sp.add_parser('lint', help="run flake8 against all py files")
test = sp.add_parser('test', help="[ARG] run tests")
test_by_name = sp.add_parser('test-by-name', help="<ARG> run test by name")
sp.add_parser('uninstall', help="uninstall")
Expand All @@ -484,7 +383,7 @@ def main():
"can't find any python installation matching %r" % args.python
)
os.putenv('PYTHON', PYTHON)
win_colorprint("using " + PYTHON)
print("using " + PYTHON)

fname = args.command.replace('-', '_')
fun = getattr(sys.modules[__name__], fname) # err if fun not defined
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"twine",
]
if WINDOWS:
DEV_DEPS.extend(["pyreadline", "pdbpp"])
DEV_DEPS.extend(["pyreadline3", "pdbpp"])


def get_version():
Expand Down

0 comments on commit 608be3d

Please sign in to comment.