Skip to content

Commit

Permalink
Adopt black formatting style (#2349)
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 4, 2024
1 parent 3882a56 commit c458816
Show file tree
Hide file tree
Showing 68 changed files with 3,107 additions and 1,775 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
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
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
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
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
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',
],
]
}

0 comments on commit c458816

Please sign in to comment.