From 269199ad3dc2128440fbbf97f78cb41c44613775 Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Thu, 5 Aug 2021 14:19:06 +0200 Subject: [PATCH] [flake8] ignore E203 as that is incompatible with black --- .flake8 | 5 +- .gitlab-ci.yml | 4 ++ bob/devtools/scripts/ci.py | 60 ++++++++++++------- bob/devtools/scripts/new.py | 19 ++++-- bob/devtools/templates/.flake8 | 5 +- bob/devtools/templates/.isort.cfg | 4 -- .../templates/.pre-commit-config.yaml | 31 +++------- bob/devtools/templates/pyproject.toml | 13 +++- conda/meta.yaml | 1 - pyproject.toml | 13 +++- 10 files changed, 88 insertions(+), 67 deletions(-) delete mode 100644 bob/devtools/templates/.isort.cfg diff --git a/.flake8 b/.flake8 index 994815d8..2534a45e 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,3 @@ [flake8] -max-line-length = 88 -select = B,C,E,F,W,T4,B9,B950 -ignore = E501, W503, E203 +max-line-length = 80 +ignore = E501,W503,E302,E402,E203 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3d9d3e21..966d7cb2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,6 +37,8 @@ build_linux: - python3 ./bob/devtools/bootstrap.py -vv build - source ${CONDA_ROOT}/etc/profile.d/conda.sh - conda activate base + - pip install pre-commit + - pre-commit run --all-files --show-diff-on-failure - python3 ./bob/devtools/build.py -vv --twine-check artifacts: paths: @@ -59,6 +61,8 @@ build_macos_intel: - python3 ./bob/devtools/bootstrap.py -vv build - source ${CONDA_ROOT}/etc/profile.d/conda.sh - conda activate base + - pip install pre-commit + - pre-commit run --all-files --show-diff-on-failure - python3 ./bob/devtools/build.py -vv artifacts: paths: diff --git a/bob/devtools/scripts/ci.py b/bob/devtools/scripts/ci.py index 9792274e..d4288805 100644 --- a/bob/devtools/scripts/ci.py +++ b/bob/devtools/scripts/ci.py @@ -255,7 +255,9 @@ def readme(package): failed = check([k]) if failed: - raise RuntimeError("twine check (a.k.a. readme check) %s: FAILED" % k) + raise RuntimeError( + "twine check (a.k.a. readme check) %s: FAILED" % k + ) else: logger.info("twine check (a.k.a. readme check) %s: OK", k) @@ -395,7 +397,9 @@ def base_build(order, group, dry_run): condarc_options = yaml.load(BASE_CONDARC, Loader=yaml.FullLoader) # dump packages at conda_root - condarc_options["croot"] = os.path.join(os.environ["CONDA_ROOT"], "conda-bld") + condarc_options["croot"] = os.path.join( + os.environ["CONDA_ROOT"], "conda-bld" + ) recipes = load_order_file(order) @@ -493,7 +497,8 @@ def test(ctx, dry_run): ctx.invoke( test, - package=glob.glob(base_path + "*.conda") + glob.glob(base_path + "*.tar.bz2"), + package=glob.glob(base_path + "*.conda") + + glob.glob(base_path + "*.tar.bz2"), condarc=condarc, config=variants_file, append_file=append_file, @@ -673,12 +678,16 @@ def nightlies(ctx, order, dry_run): for n, (package, branch) in enumerate(packages): echo_normal("\n" + (80 * "=")) - echo_normal("Building %s@%s (%d/%d)" % (package, branch, n + 1, len(packages))) + echo_normal( + "Building %s@%s (%d/%d)" % (package, branch, n + 1, len(packages)) + ) echo_normal((80 * "=") + "\n") group, name = package.split("/", 1) - clone_to = os.path.join(os.environ["CI_PROJECT_DIR"], "src", group, name) + clone_to = os.path.join( + os.environ["CI_PROJECT_DIR"], "src", group, name + ) dirname = os.path.dirname(clone_to) if not os.path.exists(dirname): os.makedirs(dirname) @@ -767,7 +776,8 @@ def nightlies(ctx, order, dry_run): local_docs = os.path.join(os.environ["CI_PROJECT_DIR"], "sphinx") if os.path.exists(local_docs): logger.debug( - "Sphinx output was generated during test/rebuild " "of %s - Erasing...", + "Sphinx output was generated during test/rebuild " + "of %s - Erasing...", package, ) shutil.rmtree(local_docs) @@ -869,7 +879,8 @@ def docs(ctx, requirement, dry_run): clone_to, ) git.Repo.clone_from( - "https://gitlab-ci-token:%s@gitlab.idiap.ch/%s" % (token, package), + "https://gitlab-ci-token:%s@gitlab.idiap.ch/%s" + % (token, package), clone_to, branch=branch, depth=1, @@ -895,7 +906,9 @@ def docs(ctx, requirement, dry_run): with open(requirements_path) as f: extra_intersphinx += comment_cleanup(f.readlines()) - nitpick_path = os.path.join(clone_to, "doc", "nitpick-exceptions.txt") + nitpick_path = os.path.join( + clone_to, "doc", "nitpick-exceptions.txt" + ) if os.path.exists(nitpick_path): with open(nitpick_path) as f: nitpick += comment_cleanup(f.readlines()) @@ -994,26 +1007,20 @@ Example: bdt ci check -vv """ ) -@click.option( - "-d", - "--dir", - "root", - default=os.path.realpath(os.curdir), - help="Path to the root folder of the package.", -) @verbosity_option() @bdt.raise_on_error -def check(root): +def check(): # checks if a pyproject.toml file exists - path = os.path.join(root, "pyproject.toml") + path = "pyproject.toml" if not os.path.isfile(path): raise RuntimeError( - "pyproject.toml file not found at the root folder of the package. " - "See https://gitlab.idiap.ch/bob/bob/-/wikis/ci-checks#pyprojecttoml" + f"{path} file not found at the root folder of the package." + f"See https://gitlab.idiap.ch/bob/bob/-/wikis/ci-checks#" + f"pyprojecttoml" ) # if there is a pre-commit configuration file, run the tests - path = os.path.join(root, ".pre-commit-config.yaml") + path = ".pre-commit-config.yaml" if os.path.isfile(path): from shutil import which @@ -1025,9 +1032,16 @@ def check(root): env = os.environ.copy() env["SKIP"] = "sphinx-build,sphinx-doctest" run_cmdline( - [which("pre-commit"), "run", "--all-files", "--show-diff-on-failure"], + [ + which("pre-commit"), + "run", + "--all-files", + "--show-diff-on-failure", + ], env=env, - cwd=root, ) else: - logger.info(f"Cannot find file {path}. Skipping pre-commit checks...") + logger.info( + f"Cannot find file {path} at the root folder of the package. " + f"Skipping pre-commit checks..." + ) diff --git a/bob/devtools/scripts/new.py b/bob/devtools/scripts/new.py index 76c4a04b..a0e26271 100644 --- a/bob/devtools/scripts/new.py +++ b/bob/devtools/scripts/new.py @@ -111,7 +111,11 @@ def new(package, author, email, title, license, output_dir): # Title # ======= rst_title = ( - ("=" * (2 + len(title))) + "\n " + title + "\n" + ("=" * (2 + len(title))) + ("=" * (2 + len(title))) + + "\n " + + title + + "\n" + + ("=" * (2 + len(title))) ) # the jinja context defines the substitutions to be performed @@ -132,7 +136,9 @@ def new(package, author, email, title, license, output_dir): # copy the whole template structure and de-templatize the needed files if output_dir is None: output_dir = os.path.join(os.path.realpath(os.curdir), name) - logger.info("Creating structure for %s at directory %s", package, output_dir) + logger.info( + "Creating structure for %s at directory %s", package, output_dir + ) if os.path.exists(output_dir): raise IOError( @@ -154,7 +160,6 @@ def new(package, author, email, title, license, output_dir): ".flake8", ".gitignore", ".gitlab-ci.yml", - ".isort.cfg", ".pre-commit-config.yaml", "buildout.cfg", "doc/conf.py", @@ -180,7 +185,9 @@ def new(package, author, email, title, license, output_dir): __name__, os.path.join("..", "templates") ) logger.info("Creating base %s python module", group) - shutil.copytree(os.path.join(template_dir, "pkg"), os.path.join(output_dir, group)) + shutil.copytree( + os.path.join(template_dir, "pkg"), os.path.join(output_dir, group) + ) # copies specific images to the right spot copy_file(os.path.join("doc", "img", "%s-favicon.ico" % group), output_dir) @@ -199,4 +206,6 @@ def new(package, author, email, title, license, output_dir): comment_start_string="(#", comment_end_string="#)", ) - render_template(conda_env, os.path.join("conda", "meta.yaml"), context, output_dir) + render_template( + conda_env, os.path.join("conda", "meta.yaml"), context, output_dir + ) diff --git a/bob/devtools/templates/.flake8 b/bob/devtools/templates/.flake8 index 994815d8..2534a45e 100644 --- a/bob/devtools/templates/.flake8 +++ b/bob/devtools/templates/.flake8 @@ -1,4 +1,3 @@ [flake8] -max-line-length = 88 -select = B,C,E,F,W,T4,B9,B950 -ignore = E501, W503, E203 +max-line-length = 80 +ignore = E501,W503,E302,E402,E203 diff --git a/bob/devtools/templates/.isort.cfg b/bob/devtools/templates/.isort.cfg deleted file mode 100644 index 7c64f804..00000000 --- a/bob/devtools/templates/.isort.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[settings] -profile=black -order_by_type=true -lines_between_types=1 diff --git a/bob/devtools/templates/.pre-commit-config.yaml b/bob/devtools/templates/.pre-commit-config.yaml index 0de60f36..c201ab09 100644 --- a/bob/devtools/templates/.pre-commit-config.yaml +++ b/bob/devtools/templates/.pre-commit-config.yaml @@ -2,20 +2,19 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/timothycrosley/isort - rev: 5.8.0 + rev: 5.9.3 hooks: - - id: isort - args: [--profile, "black"] + - id: isort - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 21.7b0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.0 + rev: 3.9.2 hooks: - id: flake8 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.0.1 hooks: - id: check-ast - id: check-case-conflict @@ -23,21 +22,5 @@ repos: - id: end-of-file-fixer - id: debug-statements - id: check-added-large-files - - repo: local - hooks: - - id: sphinx-build - name: sphinx build - entry: python -m sphinx.cmd.build - args: [-a, -E, -W, doc, sphinx] - language: system - files: ^doc/ - types: [file] - pass_filenames: false - - id: sphinx-doctest - name: sphinx doctest - entry: python -m sphinx.cmd.build - args: [-a, -E, -b, doctest, doc, sphinx] - language: system - files: ^doc/ - types: [file] - pass_filenames: false + - id: check-yaml + exclude: .*/meta.yaml diff --git a/bob/devtools/templates/pyproject.toml b/bob/devtools/templates/pyproject.toml index bb5e83cb..b738dc84 100644 --- a/bob/devtools/templates/pyproject.toml +++ b/bob/devtools/templates/pyproject.toml @@ -1,3 +1,12 @@ [build-system] -requires = ["setuptools", "wheel", "bob.extension"] -build-backend = "setuptools.build_meta" + requires = ["setuptools", "wheel", "bob.extension"] + build-backend = "setuptools.build_meta" + +[tool.isort] + profile = "black" + line_length = 80 + order_by_type = true + lines_between_types = 1 + +[tool.black] + line-length = 80 diff --git a/conda/meta.yaml b/conda/meta.yaml index 62f12a82..6f2df955 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -101,7 +101,6 @@ test: - bdt ci docs --help - bdt ci clean-betas --help - bdt ci check --help - - bdt ci check -vv --dir {{ environ.get('RECIPE_DIR') + '/..' }} - bdt dav --help - bdt dav list --help - bdt dav makedirs --help diff --git a/pyproject.toml b/pyproject.toml index 9787c3bd..d69b43c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,12 @@ [build-system] -requires = ["setuptools", "wheel"] -build-backend = "setuptools.build_meta" + requires = ["setuptools", "wheel"] + build-backend = "setuptools.build_meta" + +[tool.isort] + profile = "black" + line_length = 80 + order_by_type = true + lines_between_types = 1 + +[tool.black] + line-length = 80 -- GitLab