From 589197ba724db8a31866f43409c57a17e60b121a Mon Sep 17 00:00:00 2001 From: Vladimir Domnich Date: Tue, 20 Sep 2022 19:46:45 +0400 Subject: [PATCH] Add black formatter and isort into a precommit hook Signed-off-by: Vladimir Domnich --- .pre-commit-config.yaml | 11 ++++++++ README.md | 50 +++++++++++++++++++++-------------- pyproject.toml | 8 ++++++ pytest_tests/requirements.txt | 4 ++- 4 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..ad9846a1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/psf/black + rev: 22.8.0 + hooks: + - id: black + language_version: python3.9 + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + name: isort (python) diff --git a/README.md b/README.md index 666b5ca6..999bd858 100644 --- a/README.md +++ b/README.md @@ -52,26 +52,34 @@ libssl-dev As we use neofs-dev-env, you'll also need to install [prerequisites](https://github.com/nspcc-dev/neofs-dev-env#prerequisites) of this repository. -### Run and get report +6. Prepare virtualenv -1. Prepare virtualenv - -``` +```shell $ make venv.local-pytest $ . venv.local-pytest/bin/activate ``` -2. Install Allure CLI +7. Setup pre-commit hooks to run code formatters on staged files before you run a `git commit` command: + +```shell +$ pre-commit install +``` + +Optionally you might want to integrate code formatters with your code editor to apply formatters to code files as you go: +* isort is supported by [PyCharm](https://plugins.jetbrains.com/plugin/15434-isortconnect), [VS Code](https://cereblanco.medium.com/setup-black-and-isort-in-vscode-514804590bf9). Plugins exist for other IDEs/editors as well. +* black can be integrated with multiple editors, please, instructions are available [here](https://black.readthedocs.io/en/stable/integrations/editors.html). + +8. Install Allure CLI Allure CLI installation is not an easy task, so a better option might be to run allure from -docker container (please, refer to p.4 of this section for instructions). +docker container (please, refer to p.2 of the next section for instructions). -To install Allure CLI you may select one of the following ways: +To install Allure CLI you may take one of the following ways: - Follow the [instruction](https://docs.qameta.io/allure/#_linux) from the official website - Consult [the thread](https://github.com/allure-framework/allure2/issues/989) - Download release from the Github -``` +```shell $ wget https://github.com/allure-framework/allure2/releases/download/2.18.1/allure_2.18.1-1_all.deb $ sudo apt install ./allure_2.18.1-1_all.deb ``` @@ -79,35 +87,37 @@ You also need the `default-jre` package installed. If none of the options worked for you, please complete the instruction with your approach. -3. Run tests +### Run and get report -In the activated virtualenv, execute the following command(s) to run a singular testsuite or all the suites in the directory -``` +1. Run tests + +Make sure that the virtualenv is activated, then execute the following command to run a singular test suite or all the suites in the directory +```shell $ pytest --alluredir my-allure-123 pytest_tests/testsuites/object/test_object_api.py $ pytest --alluredir my-allure-123 pytest_tests/testsuites/ ``` -4. Generate report +2. Generate report If you opted to install Allure CLI, you can generate a report using the command `allure generate`. The web representation of the report will be under `allure-report` directory: -``` +```shell $ allure generate my-allure-123 $ ls allure-report/ app.js data export favicon.ico history index.html plugins styles.css widgets ``` To inspect the report in a browser, run -``` +```shell $ allure serve my-allure-123 ``` If you prefer to run allure from Docker, you can use the following command: -``` -mkdir -p $PWD/allure-reports -docker run -p 5050:5050 -e CHECK_RESULTS_EVERY_SECONDS=30 -e KEEP_HISTORY=1 \ - -v $PWD/my-allure-123:/app/allure-results \ - -v $PWD/allure-reports:/app/default-reports \ - frankescobar/allure-docker-service +```shell +$ mkdir -p $PWD/allure-reports +$ docker run -p 5050:5050 -e CHECK_RESULTS_EVERY_SECONDS=30 -e KEEP_HISTORY=1 \ + -v $PWD/my-allure-123:/app/allure-results \ + -v $PWD/allure-reports:/app/default-reports \ + frankescobar/allure-docker-service ``` Then, you can check the allure report in your browser [by this link](http://localhost:5050/allure-docker-service/projects/default/reports/latest/index.html?redirect=false) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..bd0087bd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[tool.isort] +profile = "black" +src_paths = ["reporter", "shell", "tests"] +line_length = 100 + +[tool.black] +line-length = 100 +target-version = ["py39"] diff --git a/pytest_tests/requirements.txt b/pytest_tests/requirements.txt index 5b9fe10a..1aa9655b 100644 --- a/pytest_tests/requirements.txt +++ b/pytest_tests/requirements.txt @@ -8,6 +8,7 @@ asynctest==0.13.0 attrs==21.4.0 base58==2.1.0 bitarray==2.3.4 +black==22.8.0 boto3==1.16.33 botocore==1.19.33 certifi==2022.5.18 @@ -37,8 +38,10 @@ neo3vm-stubs==0.9.0 netaddr==0.8.0 orjson==3.6.8 packaging==21.3 +paramiko==2.10.3 pexpect==4.8.0 pluggy==1.0.0 +pre-commit==2.20.0 ptyprocess==0.7.0 py==1.11.0 pybiginteger==1.2.6 @@ -61,4 +64,3 @@ typing-extensions==4.2.0 urllib3==1.26.9 websocket-client==1.3.2 yarl==1.7.2 -paramiko==2.10.3