Skip to content

Commit

Permalink
Merge pull request #2779 from nicolargo/ruff-cleanup
Browse files Browse the repository at this point in the history
chore: ruff cleanup
  • Loading branch information
nicolargo committed May 18, 2024
2 parents 3306fa0 + 4f38bf3 commit a99bf33
Show file tree
Hide file tree
Showing 133 changed files with 1,517 additions and 1,987 deletions.
2 changes: 0 additions & 2 deletions .bandit

This file was deleted.

8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

97 changes: 54 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ on:

jobs:

source-code-checks:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Check formatting with Ruff
uses: chartboost/ruff-action@v1
with:
args: 'format --check'

- name: Check linting with Ruff
uses: chartboost/ruff-action@v1
with:
args: 'check'

- name: Static type check
run: |
echo "Skipping static type check for the moment, too much error...";
# pip install pyright
# pyright glances
test-linux:

needs: source-code-checks
# https://github.com/actions/runner-images?tab=readme-ov-file#available-images
runs-on: ubuntu-22.04
strategy:
Expand All @@ -17,36 +41,22 @@ jobs:

steps:

- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.git,./docs,./glances/outputs/static
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=.git,./docs,./glances/outputs/static
- name: Static type check
run: |
echo "Skipping static type check for the moment, too much error...";
# pip install pyright
# pyright glances
- name: Unitary tests
run: |
python ./unittest-core.py
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Unitary tests
run: |
python ./unittest-core.py
# Error appear with h11, not related to Glances
# Should be tested if correction is done
Expand Down Expand Up @@ -84,6 +94,7 @@ jobs:

test-macos:

needs: source-code-checks
# https://github.com/actions/runner-images?tab=readme-ov-file#available-images
runs-on: macos-14
strategy:
Expand All @@ -92,22 +103,22 @@ jobs:

steps:

- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Unitary tests
run: |
python ./unittest-core.py
- name: Unitary tests
run: |
python ./unittest-core.py
# Error when trying to implement #2749
# pkg: No packages available to install matching 'py-pip' have been found in the repositories
Expand Down
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-docstring-first
- id: check-json
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: mixed-line-ending
- id: requirements-txt-fixer

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
9 changes: 3 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ the developers managing and developing this open source project. In return,
they should reciprocate that respect in addressing your issue or assessing
patches and features.


## Using the issue tracker

The [issue tracker](https://github.com/nicolargo/glances/issues) is
Expand All @@ -24,7 +23,6 @@ restrictions:
* Please **do not** derail or troll issues. Keep the discussion on topic and
respect the opinions of others.


## Bug reports

A bug is a _demonstrable problem_ that is caused by the code in the repository.
Expand Down Expand Up @@ -65,19 +63,17 @@ Example:
> causing the bug, and potential solutions (and your opinions on their
> merits).
>
> You can also run Glances in debug mode (-d) and paste/bin the glances.conf file (https://glances.readthedocs.io/en/latest/config.html).
> You can also run Glances in debug mode (-d) and paste/bin the glances.conf file (<https://glances.readthedocs.io/en/latest/config.html>).
>
> Glances 3.2.0 or higher have also a --issue option to run a simple test. Please use it and copy/paste the output.

## Feature requests

Feature requests are welcome. But take a moment to find out whether your idea
fits with the scope and aims of the project. It's up to *you* to make a strong
fits with the scope and aims of the project. It's up to _you* to make a strong
case to convince the project's developers of the merits of this feature. Please
provide as much detail and context as possible.


## Pull requests

Good pull requests—patches, improvements, new features—are a fantastic
Expand Down Expand Up @@ -133,6 +129,7 @@ included in the project:

5. Test you code using the Makefile:

* make format ==> Format your code thanks to the Ruff linter
* make run ==> Run Glances
* make run-webserver ==> Run a Glances Web Server
* make test ==> Run unit tests
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ venv-dev-python: ## Install Python 3 venv
venv-dev: venv-python ## Install Python 3 dev dependencies
./venv-dev/bin/pip install -r dev-requirements.txt
./venv-dev/bin/pip install -r doc-requirements.txt
./venv-dev/bin/pre-commit install --hook-type pre-commit

venv-dev-upgrade: ## Upgrade Python 3 dev dependencies
./venv-dev/bin/pip install --upgrade pip
Expand Down Expand Up @@ -86,15 +87,10 @@ test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in mi
# ===================================================================

format: ## Format the code
@git ls-files 'glances/*.py' | xargs ./venv-dev/bin/python -m autopep8 --in-place --jobs 0 --global-config=.flake8
@git ls-files 'glances/*.py' | xargs ./venv-dev/bin/python -m autoflake --in-place --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --exclude="compat.py,globals.py"
./venv-dev/bin/python -m black ./glances --exclude outputs/static
./venv-dev/bin/python -m ruff format .

flake8: ## Run flake8 linter.
@git ls-files 'glances/ *.py' | xargs ./venv-dev/bin/python -m flake8 --config=.flake8

ruff: ## Run Ruff (fastest) linter.
./venv-dev/bin/python -m ruff check . --config=./pyproject.toml
lint: ## Lint the code.
./venv-dev/bin/python -m ruff check . --fix

codespell: ## Run codespell to fix common misspellings in text files
./venv-dev/bin/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics
Expand Down
19 changes: 8 additions & 11 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
py-spy
codespell
fonttools>=4.43.0 # not directly required, pinned by Snyk to avoid a vulnerability
gprof2dot
black
matplotlib
memory-profiler
numpy>=1.22.2 # not directly required, pinned by Snyk to avoid a vulnerability
pillow>=10.0.1 # not directly required, pinned by Snyk to avoid a vulnerability
pre-commit
py-spy
pyright
requirements-parser
flake8
autopep8
autoflake
ruff
codespell
memory-profiler
matplotlib
semgrep
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
numpy>=1.22.2 # not directly required, pinned by Snyk to avoid a vulnerability
pillow>=10.0.1 # not directly required, pinned by Snyk to avoid a vulnerability
fonttools>=4.43.0 # not directly required, pinned by Snyk to avoid a vulnerability
4 changes: 2 additions & 2 deletions doc-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
reuse
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
sphinx
sphinx_rtd_theme
ujson
reuse
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
4 changes: 2 additions & 2 deletions docker-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
-r requirements.txt

docker>=6.1.1; python_version >= "3.7"
podman; python_version >= "3.6"
packaging; python_version >= "3.7"
podman; python_version >= "3.6"
python-dateutil
requests
six
urllib3
requests
39 changes: 14 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Glances documentation build configuration file, created by
# sphinx-quickstart on Tue Mar 1 10:53:59 2016.
Expand All @@ -12,8 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys
from datetime import datetime

# If extensions (or modules to document with autodoc) are in another directory,
Expand All @@ -27,7 +26,6 @@
# WARNING: Do not move this import before the sys.path.insert() call.
from glances import __version__


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -125,8 +123,7 @@
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
}
html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down Expand Up @@ -166,14 +163,7 @@
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'links.html',
'searchbox.html'
]
}
html_sidebars = {'**': ['about.html', 'navigation.html', 'links.html', 'searchbox.html']}

# Additional templates that should be rendered to pages, maps page names to
# template names.
Expand Down Expand Up @@ -227,13 +217,10 @@
latex_elements = {
# 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 @@ -242,8 +229,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Glances.tex', 'Glances Documentation',
'Nicolas Hennion', 'manual'),
(master_doc, 'Glances.tex', 'Glances Documentation', 'Nicolas Hennion', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -271,10 +257,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('glances', 'glances', 'An eye on your system',
'', 1)
]
man_pages = [('glances', 'glances', 'An eye on your system', '', 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -286,9 +269,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Glances', 'Glances Documentation',
author, 'Glances', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
'Glances',
'Glances Documentation',
author,
'Glances',
'One line description of project.',
'Miscellaneous',
),
]

# Documents to append as an appendix to all manuals.
Expand Down

0 comments on commit a99bf33

Please sign in to comment.