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

Adopt black formatting style #2349

Merged
merged 46 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
55ac25f
fix style
giampaolo Jan 3, 2024
88e067b
add black
giampaolo Jan 3, 2024
aa3d2aa
add fmt exclusion
giampaolo Jan 3, 2024
4f274a9
add fmt exclusion
giampaolo Jan 3, 2024
dde3872
add fmt exclusion
giampaolo Jan 3, 2024
26bd8a9
add fmt exclusion
giampaolo Jan 3, 2024
84fe71c
add fmt exclusion
giampaolo Jan 3, 2024
5c281ed
add fmt exclusion
giampaolo Jan 3, 2024
63e579f
add more ruff rules
giampaolo Jan 4, 2024
176c037
fix py 2.7 compat
giampaolo Jan 4, 2024
68f6978
update branch
giampaolo Jan 4, 2024
252b0cb
add fmt exception
giampaolo Jan 4, 2024
db0bcbe
add fmt exception
giampaolo Jan 4, 2024
dd2189d
add fmt exception
giampaolo Jan 4, 2024
1a9843e
port psutil/__init__.py
giampaolo Jan 4, 2024
0b5cb03
add fmt exception
giampaolo Jan 4, 2024
74de546
add fmt exception
giampaolo Jan 4, 2024
63eb273
port psutil/_pslinux.py
giampaolo Jan 4, 2024
cd16e23
port psutil/_psbsd.py
giampaolo Jan 4, 2024
b0281d4
add fmt exception
giampaolo Jan 4, 2024
a9bbe85
port psutil/_pswindows.py
giampaolo Jan 4, 2024
120892f
port psutil/_psosx.py
giampaolo Jan 4, 2024
d09b7c9
port psutil/_psaix.py
giampaolo Jan 4, 2024
8917008
port psutil/_pssunos.py
giampaolo Jan 4, 2024
b54f10b
port psutil/_psposix.py
giampaolo Jan 4, 2024
1696ee9
progress
giampaolo Jan 4, 2024
5c4fc59
add fmt exception
giampaolo Jan 4, 2024
8c5cd93
port psutil/_common.py
giampaolo Jan 4, 2024
e9f7c52
port psutil/_compat.py
giampaolo Jan 4, 2024
a8b2212
progress
giampaolo Jan 4, 2024
e89b973
port all scripts/
giampaolo Jan 4, 2024
bb9080a
port psutil/tests/__init__.py
giampaolo Jan 4, 2024
78fa793
merge from master
giampaolo Jan 4, 2024
7daaad0
port psutil/tests/test_process.py
giampaolo Jan 4, 2024
81a0bd6
port psutil/tests/test_system.py
giampaolo Jan 4, 2024
5689b81
port all tests
giampaolo Jan 4, 2024
584b7dd
last port
giampaolo Jan 4, 2024
426bdd2
update Makefile
giampaolo Jan 4, 2024
0fef4a9
update deps
giampaolo Jan 4, 2024
ae67214
fix py 2.7 compat
giampaolo Jan 4, 2024
55d3c4a
fix TypeError
giampaolo Jan 4, 2024
81f5884
make lint happy
giampaolo Jan 4, 2024
24402e9
update HISTORY
giampaolo Jan 4, 2024
a505691
satisfy deps
giampaolo Jan 4, 2024
63c3f8b
run black from git pre-commit script
giampaolo Jan 4, 2024
be38045
fix syntax err on win
giampaolo Jan 4, 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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
1 change: 1 addition & 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 Down
14 changes: 12 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 @@ -193,7 +195,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 +213,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 +223,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 +237,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
39 changes: 19 additions & 20 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,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 @@ -271,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 @@ -289,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 @@ -330,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 @@ -345,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 @@ -373,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