Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/giampaolo/psutil
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/giampaolo/psutil:
  refact some tests
  more tests refactoring
  improve tests reliability
  Fix cpu_freq for Apple silicon (giampaolo#2222)
  refactor tests + make them more robust
  Adopt black formatting style (giampaolo#2349)
  some tests refactoring
  add more ruff rules
  add SECURITY.md
  linux tests: refact mock_open_content()
  • Loading branch information
ddelange committed Jan 13, 2024
2 parents cc92838 + d4ae6a0 commit 4d26bd4
Show file tree
Hide file tree
Showing 74 changed files with 4,193 additions and 2,683 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
python-version: 3.x
- name: 'Run linters'
run: |
python3 -m pip install ruff rstcheck toml-sort sphinx
python3 -m pip install ruff black rstcheck toml-sort sphinx
make lint-all
# Check sanity of .tar.gz + wheel files
Expand Down
42 changes: 26 additions & 16 deletions .github/workflows/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@


ROOT_DIR = os.path.realpath(
os.path.join(os.path.dirname(__file__), '..', '..'))
os.path.join(os.path.dirname(__file__), '..', '..')
)
SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts')


# --- constants


# fmt: off
LABELS_MAP = {
# platforms
"linux": [
Expand Down Expand Up @@ -94,13 +95,15 @@
],
}

LABELS_MAP['scripts'].extend(
[x for x in os.listdir(SCRIPTS_DIR) if x.endswith('.py')])

OS_LABELS = [
"linux", "windows", "macos", "freebsd", "openbsd", "netbsd", "openbsd",
"bsd", "sunos", "unix", "wsl", "aix", "cygwin",
]
# fmt: on

LABELS_MAP['scripts'].extend(
[x for x in os.listdir(SCRIPTS_DIR) if x.endswith('.py')]
)

ILLOGICAL_PAIRS = [
('bug', 'enhancement'),
Expand Down Expand Up @@ -247,10 +250,12 @@ def add_labels_from_new_body(issue, text):
# add bug/enhancement label
log("search for 'Bug fix: y/n' line")
r = re.search(r"\* Bug fix:.*?\n", text)
if is_pr(issue) and \
r is not None and \
not has_label(issue, "bug") and \
not has_label(issue, "enhancement"):
if (
is_pr(issue)
and r is not None
and not has_label(issue, "bug")
and not has_label(issue, "enhancement")
):
log("found")
s = r.group(0).lower()
if 'yes' in s:
Expand Down Expand Up @@ -289,20 +294,25 @@ def add_labels_from_new_body(issue, text):

def on_new_issue(issue):
def has_text(text):
return text in issue.title.lower() or \
(issue.body and text in issue.body.lower())
return text in issue.title.lower() or (
issue.body and text in issue.body.lower()
)

def body_mentions_python_h():
if not issue.body:
return False
body = issue.body.replace(' ', '')
return "#include<Python.h>\n^~~~" in body or \
"#include<Python.h>\r\n^~~~" in body
return (
"#include<Python.h>\n^~~~" in body
or "#include<Python.h>\r\n^~~~" in body
)

log("searching for missing Python.h")
if has_text("missing python.h") or \
has_text("python.h: no such file or directory") or \
body_mentions_python_h():
if (
has_text("missing python.h")
or has_text("python.h: no such file or directory")
or body_mentions_python_h()
):
log("found mention of Python.h")
issue.create_comment(REPLY_MISSING_PYTHON_HEADERS)
issue.edit(state='closed')
Expand Down
4 changes: 4 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -813,3 +813,7 @@ I: 2156, 2345
N: Lawrence D'Anna
W: https://github.com/smoofra
I: 2010

N: Oliver Tomé
W: https://github.com/snom3ad
I: 2222
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
4 times faster. Before all connection types (TCP, UDP, UNIX) were retrieved
internally, even if only a portion was returned.
- 2342_, [NetBSD]: same as above (#2343) but for NetBSD.
- 2349_: adopted black formatting style.

**Bug fixes**

Expand All @@ -19,6 +20,8 @@
- 2340_, [NetBSD]: if process is terminated, `Process.cwd()`_ will return an
empty string instead of raising `NoSuchProcess`_.
- 2345_, [Linux]: fix compilation on older compiler missing DUPLEX_UNKNOWN
- 2222_, [macOS]: `cpu_freq()` now returns fixed values for `min` and `max`
frequencies in all Apple Silicon chips.

5.9.7
=====
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include LICENSE
include MANIFEST.in
include Makefile
include README.rst
include SECURITY.md
include docs/.readthedocs.yaml
include docs/DEVGUIDE.rst
include docs/DEVNOTES
Expand Down Expand Up @@ -163,6 +164,7 @@ include psutil/tests/test_misc.py
include psutil/tests/test_osx.py
include psutil/tests/test_posix.py
include psutil/tests/test_process.py
include psutil/tests/test_process_all.py
include psutil/tests/test_sunos.py
include psutil/tests/test_system.py
include psutil/tests/test_testutils.py
Expand Down
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TSCRIPT = psutil/tests/runner.py

# Internal.
PY3_DEPS = \
black \
check-manifest \
concurrencytest \
coverage \
Expand All @@ -18,6 +19,7 @@ PY3_DEPS = \
pypinfo \
requests \
rstcheck \
ruff \
setuptools \
sphinx_rtd_theme \
teyit \
Expand Down Expand Up @@ -138,6 +140,10 @@ test-process: ## Run process-related API tests.
${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_process.py

test-process-all: ## Run tests which iterate over all process PIDs.
${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_process_all.py

test-system: ## Run system-related API tests.
${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_system.py
Expand Down Expand Up @@ -193,7 +199,10 @@ test-coverage: ## Run test coverage.
# ===================================================================

ruff: ## Run ruff linter.
@git ls-files '*.py' | xargs $(PYTHON) -m ruff check --config=pyproject.toml --no-cache
@git ls-files '*.py' | xargs $(PYTHON) -m ruff check --no-cache

black: ## Python files linting (via black)
@git ls-files '*.py' | xargs $(PYTHON) -m black --check --safe

_pylint: ## Python pylint (not mandatory, just run it from time to time)
@git ls-files '*.py' | xargs $(PYTHON) -m pylint --rcfile=pyproject.toml --jobs=${NUM_WORKERS}
Expand All @@ -208,6 +217,7 @@ lint-toml: ## Linter for pyproject.toml
@git ls-files '*.toml' | xargs toml-sort --check

lint-all: ## Run all linters
${MAKE} black
${MAKE} ruff
${MAKE} lint-c
${MAKE} lint-rst
Expand All @@ -217,8 +227,11 @@ lint-all: ## Run all linters
# Fixers
# ===================================================================

fix-black:
git ls-files '*.py' | xargs $(PYTHON) -m black

fix-ruff:
@git ls-files '*.py' | xargs $(PYTHON) -m ruff --config=pyproject.toml --no-cache --fix
@git ls-files '*.py' | xargs $(PYTHON) -m ruff --no-cache --fix

fix-unittests: ## Fix unittest idioms.
@git ls-files '*test_*.py' | xargs $(PYTHON) -m teyit --show-stats
Expand All @@ -228,6 +241,7 @@ fix-toml: ## Fix pyproject.toml

fix-all: ## Run all code fixers.
${MAKE} fix-ruff
${MAKE} fix-black
${MAKE} fix-unittests
${MAKE} fix-toml

Expand Down
10 changes: 10 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Security Policy

If you have discovered a security vulnerability in this project, please report
it privately. **Do not disclose it as a public issue**. This gives me time to
fix the issue before public exposure, reducing the chance that an exploit will
be used before a patch is released.

To report a security vulnerability use the [Tidelift security
contact](https://tidelift.com/security). Tidelift will coordinate the fix and
the disclosure of the reported problem.
44 changes: 21 additions & 23 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def get_version():
for num in ret.split('.'):
assert num.isdigit(), ret
return ret
else:
msg = "couldn't find version string"
raise ValueError(msg)
msg = "couldn't find version string"
raise ValueError(msg)


VERSION = get_version()
Expand All @@ -57,11 +56,13 @@ def get_version():
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -272,15 +273,12 @@ def get_version():
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -290,8 +288,7 @@ def get_version():
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'psutil.tex', 'psutil Documentation',
AUTHOR, 'manual'),
(master_doc, 'psutil.tex', 'psutil Documentation', AUTHOR, 'manual')
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -331,10 +328,7 @@ def get_version():

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'psutil', 'psutil Documentation',
[author], 1)
]
man_pages = [(master_doc, 'psutil', 'psutil Documentation', [author], 1)]

# If true, show URL addresses after external links.
#
Expand All @@ -346,11 +340,15 @@ def get_version():
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'psutil', 'psutil Documentation',
author, 'psutil', 'One line description of project.',
'Miscellaneous'),
]
texinfo_documents = [(
master_doc,
'psutil',
'psutil Documentation',
author,
'psutil',
'One line description of project.',
'Miscellaneous',
)]

# Documents to append as an appendix to all manuals.
#
Expand All @@ -374,5 +372,5 @@ def get_version():
'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
'_static/css/custom.css',
],
]
}
Loading

0 comments on commit 4d26bd4

Please sign in to comment.