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

Drop Python 2.7 support #2481

Merged
merged 82 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
7c274a4
port setup.py
giampaolo Dec 18, 2024
c48d3c5
assume enum always exist
giampaolo Dec 18, 2024
c79b6b4
rm `from psutil.tests import mock`
giampaolo Dec 18, 2024
a71e88d
import ipaddress directly
giampaolo Dec 18, 2024
abfb67f
remove raise_from() wrapper
giampaolo Dec 18, 2024
3479b0c
rm `if PY3` logic from _aix.py
giampaolo Dec 18, 2024
a7fed78
rm `if PY3` logic from _pslinux.py
giampaolo Dec 18, 2024
e8061da
rm py2 unicode wrapper around disk_usage()
giampaolo Dec 18, 2024
a428016
rm `if PY3` logic from _pssunos.py
giampaolo Dec 18, 2024
d8dd607
adjust test/__init__.py and test/test_windows.py
giampaolo Dec 18, 2024
0f7d25b
address io.StringIO
giampaolo Dec 18, 2024
2686c8a
rm other PY3 occurrences
giampaolo Dec 18, 2024
c5f2ac1
remove appveyor + py2 CI tests
giampaolo Dec 18, 2024
9c5f455
rm other PY3 occurrences
giampaolo Dec 18, 2024
06253c2
adjust mock.patch("builtins.open", ...)
giampaolo Dec 18, 2024
2dbf1c8
adjust test/test_linux.py
giampaolo Dec 18, 2024
03bfa06
make build: always use --parallel N option
giampaolo Dec 18, 2024
30952bf
adjust _pswindows.py
giampaolo Dec 18, 2024
c7567d2
get rid of long
giampaolo Dec 18, 2024
5abd217
get rid of range / xrange
giampaolo Dec 18, 2024
8470427
get rid of unicode
giampaolo Dec 18, 2024
e3b76fc
get rid of basestring
giampaolo Dec 18, 2024
411f386
get rid of b() literal
giampaolo Dec 18, 2024
e4a348b
get rid of super()
giampaolo Dec 18, 2024
8ed58ea
rm builtin exceptions
giampaolo Dec 18, 2024
6c982f5
rm functools.lru_cache()
giampaolo Dec 18, 2024
421d5df
rm shutil.which()
giampaolo Dec 18, 2024
b900695
rm shutil.get_terminal_size()
giampaolo Dec 18, 2024
726e415
rm subprocess.TimeoutExpired
giampaolo Dec 18, 2024
72b9f55
rm contextlib.redirect_stderr()
giampaolo Dec 18, 2024
83e096a
delete _compat.py - this module was 15 years old, added in 5bab8cdd4
giampaolo Dec 18, 2024
4db1d07
rm contextlib.closing()
giampaolo Dec 18, 2024
7715d0c
rm python 2.7 compatibility requires no comma
giampaolo Dec 18, 2024
2af9f65
WindowsError.winerror should always be present in python 3
giampaolo Dec 18, 2024
01381b6
rm prlimit() hack based on ctypes
giampaolo Dec 18, 2024
28cb0cb
rm comments & docstrings about python 2
giampaolo Dec 18, 2024
5deeb2d
rm python 2 from setup.py metadata
giampaolo Dec 18, 2024
e35318e
update README and comments / docstrings about python 2
giampaolo Dec 18, 2024
6d28d58
remove importlib wrappers
giampaolo Dec 18, 2024
bcfbfc1
rm references to sys.version_info
giampaolo Dec 18, 2024
856e831
remove further 2.7 references from internal scripts
giampaolo Dec 18, 2024
4612b86
rm `from __future__ import` and utf8 shebang
giampaolo Dec 18, 2024
7892daf
fix build.yml
giampaolo Dec 18, 2024
de16ba3
fix winmake.py test-parallel
giampaolo Dec 18, 2024
a7caf3a
fix winmake.py test-parallel
giampaolo Dec 18, 2024
ba2111e
replace IOError and EnvironmentError with OSError (they are both alia…
giampaolo Dec 18, 2024
3bf7a9f
Merge branch 'rm-py2-2' into rm-py2
giampaolo Dec 18, 2024
4cba2d8
run pyupgrade to modernize code
giampaolo Dec 18, 2024
e789bf1
use list.copy() instead of list[:]
giampaolo Dec 18, 2024
ac56cbb
use f-string instead of str.format()
giampaolo Dec 18, 2024
d11448c
remove _compat.py refs
giampaolo Dec 18, 2024
2bc1738
merge from master
giampaolo Dec 18, 2024
c3dce20
update doc
giampaolo Dec 18, 2024
706383e
replace WindowsError with OSError
giampaolo Dec 18, 2024
22d0bfe
rm backport of PyErr_SetFromWindowsErr on PYPY 2.7
giampaolo Dec 18, 2024
b2065af
small refact
giampaolo Dec 19, 2024
24cfdbd
disable flaky test
giampaolo Dec 19, 2024
50297f0
adjust PyInit for linux
giampaolo Dec 19, 2024
c1d2d66
merge from master
giampaolo Dec 19, 2024
96e873d
adjust PyInit for _psutil_posix.c
giampaolo Dec 19, 2024
6d99c46
try to adjust WindowsError.winerror
giampaolo Dec 19, 2024
756d2f4
rm worarounds for missing PyUnicode_DecodeFS on py2
giampaolo Dec 19, 2024
be74133
adjust PyLong_FromPid
giampaolo Dec 19, 2024
976b27e
adjust PyInit for _psutil_bsd.c
giampaolo Dec 19, 2024
046b014
adjust PyInit for _psutil_osx.c
giampaolo Dec 19, 2024
196f0c7
adjust PyInit for _psutil_windows.c
giampaolo Dec 19, 2024
3bbfe69
unify PyInt_FromLong
giampaolo Dec 19, 2024
8d7bd96
rm py2 C handling of disk_usage() on windows
giampaolo Dec 19, 2024
d77664c
adjust PyInit for _psutil_aix.c
giampaolo Dec 19, 2024
6843ee1
adjust PyInit for _psutil_sunosù.c
giampaolo Dec 19, 2024
b31f9b2
rm py2 comments + small refact
giampaolo Dec 19, 2024
0b7bfb8
update doc
giampaolo Dec 19, 2024
b438d68
merge from master
giampaolo Dec 19, 2024
0ad0b4b
merge from master
giampaolo Dec 19, 2024
e7cf363
merge from master
giampaolo Dec 19, 2024
6b18b17
Popen: better exception msg on AttributeError
giampaolo Dec 19, 2024
74f9b36
make setup.py print last psutil version supporting Python 2.7
giampaolo Dec 20, 2024
85a5a7d
update doc
giampaolo Dec 20, 2024
615fc0e
revert nice __getattr__ / raise x from None change. Let's keep the py…
giampaolo Dec 20, 2024
fdc14e4
update build.yml
giampaolo Dec 20, 2024
161ce41
rename download_wheels_github.py -> download_wheels.py
giampaolo Dec 20, 2024
4c09586
update doc
giampaolo Dec 20, 2024
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
57 changes: 17 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Runs CI tests and generates wheels on the following platforms:
#
# * Linux (py2 and py3)
# * macOS (py2 and py3)
# * Windows (py3, py2 is done by appveyor)
# * Linux
# * macOS
# * Windows
#
# Useful URLs:
# * https://github.com/pypa/cibuildwheel
Expand All @@ -16,9 +15,10 @@ concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.sha || '' }}
cancel-in-progress: true
jobs:
# Linux + macOS + Windows Python 3
py3:
name: "py3, ${{ matrix.os }}, ${{ matrix.arch }}"

# Run tests on Linux, macOS, Windows
tests:
name: "tests, ${{ matrix.os }}, ${{ matrix.arch }}"
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-py3-${{ matrix.os }}-${{ matrix.arch }}
name: wheels-${{ matrix.os }}-${{ matrix.arch }}
path: wheelhouse

- name: Generate .tar.gz
Expand All @@ -74,42 +74,19 @@ jobs:
python setup.py sdist
mv dist/psutil*.tar.gz wheelhouse/

# Linux + macOS + Python 2
py2:
name: py2, ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# Test python 2.7 fallback installation message produced by setup.py
py2-fallback:
name: py2.7 setup.py check
runs-on: ubuntu-24.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-13]
env:
CIBW_BUILD: 'cp27-*'
CIBW_TEST_EXTRAS: test
CIBW_TEST_COMMAND:
make -C {project} PYTHON="env python" PSUTIL_SCRIPTS_DIR="{project}/scripts" install-sysdeps install-pydeps-test install print-sysinfo test test-memleaks

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Create wheels + run tests
uses: pypa/cibuildwheel@v1.12.0

- name: Upload wheels
uses: actions/upload-artifact@v4
- uses: LizardByte/setup-python-action@master
with:
name: wheels-py2-${{ matrix.os }}
path: wheelhouse

- name: Generate .tar.gz
if: matrix.os == 'ubuntu-latest'
run: |
make generate-manifest
python setup.py sdist
mv dist/psutil*.tar.gz wheelhouse/
python-version: '2.7'
- run: python scripts/internal/test_python2_setup_py.py

# Run linters
linters:
Expand All @@ -124,9 +101,9 @@ jobs:
python3 -m pip install ruff black rstcheck toml-sort sphinx
make lint-all

# upload weels as a single artefact
# Produce wheels as artifacts.
upload-wheels:
needs: [py2, py3]
needs: [tests]
runs-on: ubuntu-latest
steps:
- uses: actions/upload-artifact/merge@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
on the situation.
"""

from __future__ import print_function

import functools
import json
Expand Down Expand Up @@ -42,7 +41,7 @@
"windows", "win32", "WinError", "WindowsError", "win10", "win7",
"win ", "mingw", "msys", "studio", "microsoft", "make.bat",
"CloseHandle", "GetLastError", "NtQuery", "DLL", "MSVC", "TCHAR",
"WCHAR", ".bat", "OpenProcess", "TerminateProcess", "appveyor",
"WCHAR", ".bat", "OpenProcess", "TerminateProcess",
"windows error", "NtWow64", "NTSTATUS", "Visual Studio",
],
"macos": [
Expand Down Expand Up @@ -89,7 +88,7 @@
],
# tests
"tests": [
" test ", "tests", "travis", "coverage", "cirrus", "appveyor",
" test ", "tests", "travis", "coverage", "cirrus",
"continuous integration", "unittest", "pytest", "unit test",
],
# critical errors
Expand Down
14 changes: 14 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*

7.0.0 (IN DEVELOPMENT)
======================

XXXX-XX-XX

**Enhancements**

- 2480_: Dropped Python 2.7 support.

**Compatibility notes**

- 2480_: Python 2.7 is no longer supported. Latest version supporting Python
2.7 is psutil 6.1.X. Install it with: ``pip2 install psutil==6.1.*``.

6.1.1
=====

Expand Down
1 change: 0 additions & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Troubleshooting
Install pip
-----------

Pip is shipped by default with Python 2.7.9+ and 3.4+.
If you don't have pip you can install it with wget::

wget https://bootstrap.pypa.io/get-pip.py -O - | python3
Expand Down
6 changes: 2 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ include docs/requirements.txt
include make.bat
include psutil/__init__.py
include psutil/_common.py
include psutil/_compat.py
include psutil/_psaix.py
include psutil/_psbsd.py
include psutil/_pslinux.py
Expand Down Expand Up @@ -177,14 +176,12 @@ include scripts/fans.py
include scripts/free.py
include scripts/ifconfig.py
include scripts/internal/README
include scripts/internal/appveyor_run_with_compiler.cmd
include scripts/internal/bench_oneshot.py
include scripts/internal/bench_oneshot_2.py
include scripts/internal/check_broken_links.py
include scripts/internal/clinter.py
include scripts/internal/convert_readme.py
include scripts/internal/download_wheels_appveyor.py
include scripts/internal/download_wheels_github.py
include scripts/internal/download_wheels.py
include scripts/internal/generate_manifest.py
include scripts/internal/git_pre_commit.py
include scripts/internal/install-sysdeps.sh
Expand All @@ -197,6 +194,7 @@ include scripts/internal/print_downloads.py
include scripts/internal/print_hashes.py
include scripts/internal/print_timeline.py
include scripts/internal/purge_installation.py
include scripts/internal/test_python2_setup_py.py
include scripts/internal/winmake.py
include scripts/iotop.py
include scripts/killall.py
Expand Down
21 changes: 5 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
PYTHON = python3
ARGS =

# "python3 setup.py build" can be parallelized on Python >= 3.6.
SETUP_BUILD_EXT_ARGS = `$(PYTHON) -c \
"import sys, os; \
py36 = sys.version_info[:2] >= (3, 6); \
cpus = os.cpu_count() or 1 if py36 else 1; \
print('--parallel %s' % cpus if cpus > 1 else '')"`

# In not in a virtualenv, add --user options for install commands.
SETUP_INSTALL_ARGS = `$(PYTHON) -c \
"import sys; print('' if hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix else '--user')"`
Expand Down Expand Up @@ -55,14 +48,15 @@ clean: ## Remove all build files.
dist/ \
docs/_build/ \
htmlcov/ \
pytest-cache* \
wheelhouse

.PHONY: build
build: ## Compile (in parallel) without installing.
@# "build_ext -i" copies compiled *.so files in ./psutil directory in order
@# to allow "import psutil" when using the interactive interpreter from
@# within this directory.
$(PYTHON_ENV_VARS) $(PYTHON) setup.py build_ext -i $(SETUP_BUILD_EXT_ARGS)
$(PYTHON_ENV_VARS) $(PYTHON) setup.py build_ext -i --parallel 4
$(PYTHON_ENV_VARS) $(PYTHON) -c "import psutil" # make sure it actually worked

install: ## Install this package as current user in "edit" mode.
Expand Down Expand Up @@ -224,12 +218,8 @@ sdist: ## Create tar.gz source distribution.
${MAKE} generate-manifest
$(PYTHON_ENV_VARS) $(PYTHON) setup.py sdist

download-wheels-github: ## Download latest wheels hosted on github.
$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/download_wheels_github.py --tokenfile=~/.github.token
${MAKE} print-dist

download-wheels-appveyor: ## Download latest wheels hosted on appveyor.
$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/download_wheels_appveyor.py
download-wheels: ## Download latest wheels hosted on github.
$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/download_wheels.py --tokenfile=~/.github.token
${MAKE} print-dist

create-wheels: ## Create .whl files
Expand Down Expand Up @@ -265,8 +255,7 @@ pre-release: ## Check if we're ready to produce a new release.
assert ver in doc, '%r not found in docs/index.rst' % ver; \
assert ver in history, '%r not found in HISTORY.rst' % ver; \
assert 'XXXX' not in history, 'XXXX found in HISTORY.rst';"
${MAKE} download-wheels-github
${MAKE} download-wheels-appveyor
${MAKE} download-wheels
${MAKE} check-wheels
${MAKE} print-hashes
${MAKE} print-dist
Expand Down
11 changes: 4 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| |downloads| |stars| |forks| |contributors| |coverage|
| |version| |py-versions| |packages| |license|
| |github-actions-wheels| |github-actions-bsd| |appveyor| |doc| |twitter| |tidelift|
| |github-actions-wheels| |github-actions-bsd| |doc| |twitter| |tidelift|

.. |downloads| image:: https://img.shields.io/pypi/dm/psutil.svg
:target: https://pepy.tech/project/psutil
Expand All @@ -26,10 +26,6 @@
:target: https://github.com/giampaolo/psutil/actions?query=workflow%3Absd-tests
:alt: FreeBSD, NetBSD, OpenBSD

.. |appveyor| image:: https://img.shields.io/appveyor/build/giampaolo/psutil/master.svg?maxAge=3600&label=Windows%20(py2)
:target: https://ci.appveyor.com/project/giampaolo/psutil
:alt: Windows (Appveyor)

.. |coverage| image:: https://coveralls.io/repos/github/giampaolo/psutil/badge.svg?branch=master
:target: https://coveralls.io/github/giampaolo/psutil?branch=master
:alt: Test coverage (coverall.io)
Expand Down Expand Up @@ -98,8 +94,9 @@ psutil currently supports the following platforms:
- **Sun Solaris**
- **AIX**

Supported Python versions are **2.7**, **3.6+** and
`PyPy <http://pypy.org/>`__.
Supported Python versions are cPython 3.6+ and `PyPy <https://pypy.org/>`__.
Latest psutil version supporting Python 2.7 is
`psutil 6.1.1 <https://pypi.org/project/psutil/6.1.1/>`__.

Funding
=======
Expand Down
83 changes: 0 additions & 83 deletions appveyor.yml

This file was deleted.

2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
18 changes: 15 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ CPU

.. function:: cpu_count(logical=True)

Return the number of logical CPUs in the system (same as `os.cpu_count`_
in Python 3.4) or ``None`` if undetermined.
Return the number of logical CPUs in the system (same as `os.cpu_count`_)
or ``None`` if undetermined.
"logical CPUs" means the number of physical cores multiplied by the number
of threads that can run on each core (this is known as Hyper Threading).
If *logical* is ``False`` return the number of physical cores only, or
Expand Down Expand Up @@ -1203,7 +1203,7 @@ Process class

>>> import psutil
>>> psutil.Process().exe()
'/usr/bin/python2.7'
'/usr/bin/python3'

.. method:: cmdline()

Expand Down Expand Up @@ -2637,6 +2637,18 @@ On Windows:
set PSUTIL_DEBUG=1 python.exe script.py
psutil-debug [psutil/arch/windows/proc.c:90]> NtWow64ReadVirtualMemory64(pbi64.PebBaseAddress) -> 998 (Unknown error) (ignored)

Python 2.7
==========

Latest version spporting Python 2.7 is `psutil 6.1.1 <https://pypi.org/project/psutil/6.1.1/>`__.
The 6.1.X serie may receive critical bug-fixes but no new features. It will
be maintained in the dedicated
`python2 <https://github.com/giampaolo/psutil/tree/python2>`__ branch.
To install it:

::

$ python2 -m pip install psutil==6.1.*

Security
========
Expand Down
Loading
Loading