From 2240ea64917f00957018a587cbb3199e1b233da0 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Tue, 28 Jun 2022 22:52:30 +0200 Subject: [PATCH] ci: Updates the Python version of the CI & file headers (#69) * ci: Updated default python version of the CI * docs: Updated headers * docs: Fixed headers of docs config --- .github/collect_env.py | 4 +-- .github/validate_headers.py | 57 ---------------------------------- .github/verify_labels.py | 5 +++ .github/workflows/tests.yml | 14 ++++----- docs/source/conf.py | 6 ++-- scripts/benchmark.py | 4 +-- setup.py | 4 +-- torchscan/crawler.py | 4 +-- torchscan/modules/flops.py | 4 +-- torchscan/modules/macs.py | 4 +-- torchscan/modules/memory.py | 4 +-- torchscan/modules/receptive.py | 4 +-- torchscan/process/memory.py | 4 +-- torchscan/utils.py | 4 +-- 14 files changed, 35 insertions(+), 87 deletions(-) delete mode 100644 .github/validate_headers.py diff --git a/.github/collect_env.py b/.github/collect_env.py index 5f994d8..d361193 100644 --- a/.github/collect_env.py +++ b/.github/collect_env.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. """ Based on https://github.com/pytorch/pytorch/blob/master/torch/utils/collect_env.py diff --git a/.github/validate_headers.py b/.github/validate_headers.py deleted file mode 100644 index 57bddda..0000000 --- a/.github/validate_headers.py +++ /dev/null @@ -1,57 +0,0 @@ -from datetime import datetime -from pathlib import Path - -shebang = ["#!usr/bin/python\n"] -blank_line = "\n" - -# Possible years -starting_year = 2020 -current_year = datetime.now().year - -year_options = [f"{current_year}"] + [f"{year}-{current_year}" for year in range(starting_year, current_year)] -copyright_notices = [[f"# Copyright (C) {year_str}, François-Guillaume Fernandez.\n"] for year_str in year_options] -license_notice = [ - "# This program is licensed under the Apache License version 2.\n", - "# See LICENSE or go to for full license details.\n", -] - -# Define all header options -HEADERS = [ - shebang + [blank_line] + copyright_notice + [blank_line] + license_notice for copyright_notice in copyright_notices -] + [copyright_notice + [blank_line] + license_notice for copyright_notice in copyright_notices] - - -IGNORED_FILES = ["version.py", "__init__.py"] -FOLDERS = ["torchscan", "scripts"] - - -def main(): - - invalid_files = [] - - # For every python file in the repository - for folder in FOLDERS: - for source_path in Path(__file__).parent.parent.joinpath(folder).rglob("**/*.py"): - if source_path.name not in IGNORED_FILES: - # Parse header - header_length = max(len(option) for option in HEADERS) - current_header = [] - with open(source_path) as f: - for idx, line in enumerate(f): - current_header.append(line) - if idx == header_length - 1: - break - # Validate it - if not any( - "".join(current_header[: min(len(option), len(current_header))]) == "".join(option) - for option in HEADERS - ): - invalid_files.append(source_path) - - if len(invalid_files) > 0: - invalid_str = "\n- " + "\n- ".join(map(str, invalid_files)) - raise AssertionError(f"Invalid header in the following files:{invalid_str}") - - -if __name__ == "__main__": - main() diff --git a/.github/verify_labels.py b/.github/verify_labels.py index 415ddf0..cc42537 100644 --- a/.github/verify_labels.py +++ b/.github/verify_labels.py @@ -1,3 +1,8 @@ +# Copyright (C) 2022, François-Guillaume Fernandez. + +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. + """ Borrowed & adapted from https://github.com/pytorch/vision/blob/main/.github/process_commit.py This script finds the merger responsible for labeling a PR by a commit SHA. It is used by the workflow in diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b25790a..5202ba4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -88,15 +88,15 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: [3.7] steps: - uses: actions/checkout@v2 with: persist-credentials: false - - name: Set up Python - uses: actions/setup-python@v1 + - name: Check the headers + uses: frgfm/validate-python-headers@main with: - python-version: ${{ matrix.python }} - architecture: x64 - - name: Run unittests - run: python .github/validate_headers.py + license: 'Apache-2.0' + owner: 'François-Guillaume Fernandez' + starting-year: 2020 + folders: 'torchscan,scripts,docs,.github' + ignores: 'version.py,__init__.py' diff --git a/docs/source/conf.py b/docs/source/conf.py index ee44817..afafb36 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,7 +1,7 @@ -# Copyright (C) 2020-2021, François-Guillaume Fernandez. +# Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. # Configuration file for the Sphinx documentation builder. # diff --git a/scripts/benchmark.py b/scripts/benchmark.py index f633f7e..314ce2a 100644 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. """ Torchvision benchmark diff --git a/setup.py b/setup.py index ac8f2fa..2ff3ada 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import os diff --git a/torchscan/crawler.py b/torchscan/crawler.py index 73b577d..dd7c85d 100644 --- a/torchscan/crawler.py +++ b/torchscan/crawler.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import os from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union diff --git a/torchscan/modules/flops.py b/torchscan/modules/flops.py index 61a0537..ce0e69d 100644 --- a/torchscan/modules/flops.py +++ b/torchscan/modules/flops.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import warnings from functools import reduce diff --git a/torchscan/modules/macs.py b/torchscan/modules/macs.py index 78b448b..1f4cf29 100644 --- a/torchscan/modules/macs.py +++ b/torchscan/modules/macs.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import warnings from functools import reduce diff --git a/torchscan/modules/memory.py b/torchscan/modules/memory.py index 6e96478..af99081 100644 --- a/torchscan/modules/memory.py +++ b/torchscan/modules/memory.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import warnings from functools import reduce diff --git a/torchscan/modules/receptive.py b/torchscan/modules/receptive.py index 046c6d2..8e7193b 100644 --- a/torchscan/modules/receptive.py +++ b/torchscan/modules/receptive.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import math import warnings diff --git a/torchscan/process/memory.py b/torchscan/process/memory.py index cfb6487..1754868 100644 --- a/torchscan/process/memory.py +++ b/torchscan/process/memory.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. import re import subprocess diff --git a/torchscan/utils.py b/torchscan/utils.py index 0670710..3e95c94 100644 --- a/torchscan/utils.py +++ b/torchscan/utils.py @@ -1,7 +1,7 @@ # Copyright (C) 2020-2022, François-Guillaume Fernandez. -# This program is licensed under the Apache License version 2. -# See LICENSE or go to for full license details. +# This program is licensed under the Apache License 2.0. +# See LICENSE or go to for full license details. from typing import Any, Dict, List, Optional, Tuple