From 7e1e2e84d3006e49f354222090e0bfe8d7f1e8da Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Fri, 4 Oct 2024 11:25:33 +0200 Subject: [PATCH] update project (#82) * update * prune * ruff * fixed * <2.4 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/CODEOWNERS | 23 ---------------- .github/dependabot.yml | 39 --------------------------- .github/workflows/ci_install-pkg.yml | 4 +-- .github/workflows/ci_testing.yml | 14 +++++----- .github/workflows/release-pypi.yml | 40 ---------------------------- .pre-commit-config.yaml | 32 +++++----------------- quick_start/components.py | 12 +++------ quick_start/setup_tools.py | 12 +++------ requirements.txt | 2 +- setup.py | 8 ++---- train_script.py | 16 +++-------- 11 files changed, 28 insertions(+), 174 deletions(-) delete mode 100644 .github/CODEOWNERS delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/release-pypi.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index c3dc457..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,23 +0,0 @@ -# This is a comment. -# Each line is a file pattern followed by one or more owners. - -# These owners will be the default owners for everything in -# the repo. Unless a later match takes precedence, -# @global-owner1 and @global-owner2 will be requested for -# review when someone opens a pull request. -* @tchaton @manskx - -# Packages -/quick_start/* @tchaton @manskx - - - -# End 2 End Cloud CI -.github/* @tchaton @manskx -tests/* @tchaton @manskx - - - -/README.md @tchaton @manskx -/setup.py @tchaton @manskx -/quick_start/__about__.py @tchaton @manskx diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 4e84b89..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,39 +0,0 @@ -# Basic dependabot.yml file with -# minimum configuration for two package managers - -version: 2 -updates: - # Enable version updates for python - - package-ecosystem: "pip" - # Look for a `requirements` in the `root` directory - directory: "/" - # Check for updates once a week - schedule: - interval: "monthly" - # Labels on pull requests for version updates only - labels: ["enhancement"] - pull-request-branch-name: - # Separate sections of the branch name with a hyphen - # for example, `dependabot-npm_and_yarn-next_js-acorn-6.4.1` - separator: "-" - # Allow up to 5 open pull requests for pip dependencies - open-pull-requests-limit: 5 - reviewers: - - "Lightning-Universe/engs" - - # Enable version updates for GitHub Actions - - package-ecosystem: "github-actions" - directory: "/" - # Check for updates once a week - schedule: - interval: "monthly" - # Labels on pull requests for version updates only - labels: ["enhancement"] - pull-request-branch-name: - # Separate sections of the branch name with a hyphen - # for example, `dependabot-npm_and_yarn-next_js-acorn-6.4.1` - separator: "-" - # Allow up to 5 open pull requests for GitHub Actions - open-pull-requests-limit: 5 - reviewers: - - "Lightning-Universe/engs" diff --git a/.github/workflows/ci_install-pkg.yml b/.github/workflows/ci_install-pkg.yml index 8b092f2..f9d33f3 100644 --- a/.github/workflows/ci_install-pkg.yml +++ b/.github/workflows/ci_install-pkg.yml @@ -16,6 +16,6 @@ jobs: import-name: "quick_start" testing-matrix: | { - "os": ["ubuntu-20.04", "macos-11", "windows-2022"], - "python-version": ["3.8"] + "os": ["ubuntu-22.04", "macos-13", "windows-2022"], + "python-version": ["3.10"] } diff --git a/.github/workflows/ci_testing.yml b/.github/workflows/ci_testing.yml index 7aec41a..e7d1622 100644 --- a/.github/workflows/ci_testing.yml +++ b/.github/workflows/ci_testing.yml @@ -11,14 +11,14 @@ concurrency: jobs: pytest: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 timeout-minutes: 10 steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v5 with: - python-version: "3.8" + python-version: "3.10" - uses: actions/cache@v4 with: @@ -27,13 +27,11 @@ jobs: restore-keys: | ${{ runner.os }}-pip- - - name: Install Lightning + - name: Install packages run: | - pip install -U lightning -r requirements.txt -r tests/requirements.txt \ + pip install -U -r requirements.txt -r tests/requirements.txt \ -f https://download.pytorch.org/whl/cpu/torch_stable.html pip list - lightning --version - name: Tests - run: | - python -m pytest tests + run: python -m pytest tests diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml deleted file mode 100644 index 6720941..0000000 --- a/.github/workflows/release-pypi.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: PyPI Release - -# https://help.github.com/en/actions/reference/events-that-trigger-workflows -on: # Trigger the workflow on push to master branch with changes in __about__.py - push: - branches: - - "main" - paths: - - "quick_start/__about__.py" - -# based on https://github.com/pypa/gh-action-pypi-publish -jobs: - build: - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@master - - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - - name: Install dependencies - run: >- - python -m pip install --user --upgrade setuptools wheel - - - name: Install Lightning - run: | - pip install -r requirements.txt --quiet - pip install . --quiet - - - name: Build - run: python setup.py sdist bdist_wheel - - - name: Publish to Custom PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: ${{ secrets.LIGHTNING_PYPI_USER }} - password: ${{ secrets.LIGHTNING_PYPI_PASSWORD }} - # if you are changing this to another server, change the image builder in the cloud to fetch from new URL - repository_url: https://us-central1-python.pkg.dev/grid-backend-266721/xpi/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5057a4f..131e7aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.8 + python: python3 ci: autofix_prs: true @@ -21,19 +21,6 @@ repos: - id: check-docstring-first - id: detect-private-key - - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 - hooks: - - id: pyupgrade - args: [--py38-plus] - name: Upgrade code - - - repo: https://github.com/psf/black - rev: 24.4.2 - hooks: - - id: black - name: Black code - - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 hooks: @@ -43,15 +30,10 @@ repos: - mdformat-black - mdformat_frontmatter - - repo: https://github.com/asottile/yesqa - rev: v1.5.0 - hooks: - - id: yesqa - - - repo: https://github.com/PyCQA/flake8 - rev: 7.1.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.5.5 hooks: - - id: flake8 - args: - - "--max-line-length=120" - - "--ignore=E266" + - id: ruff + args: ["--fix", "--line-length=120", "--target-version=py39"] + - id: ruff-format + args: ["--line-length=120"] diff --git a/quick_start/components.py b/quick_start/components.py index e2033cb..872033a 100644 --- a/quick_start/components.py +++ b/quick_start/components.py @@ -58,9 +58,7 @@ def trainer_pre_fn(self, *args, work=None, **kwargs): return {}, args, kwargs # 5. Patch the `__init__` method of the Trainer to inject our callback with a reference to the work. - tracer.add_traced( - Trainer, "__init__", pre_fn=partial(trainer_pre_fn, work=self) - ) + tracer.add_traced(Trainer, "__init__", pre_fn=partial(trainer_pre_fn, work=self)) return tracer def run(self, *args, **kwargs): @@ -96,9 +94,7 @@ def on_after_run(self, script_globals): lightning_module = script_globals["cli"].trainer.lightning_module # 2. From the checkpoint_callback, we are accessing the best model weights - checkpoint = torch.load( - script_globals["cli"].trainer.checkpoint_callback.best_model_path - ) + checkpoint = torch.load(script_globals["cli"].trainer.checkpoint_callback.best_model_path) # 3. Load the best weights and torchscript the model. lightning_module.load_state_dict(checkpoint["state_dict"]) @@ -110,9 +106,7 @@ def on_after_run(self, script_globals): self.best_model_path = Path("model_weight.pt") # 5. Keep track of the metrics. - self.best_model_score = float( - script_globals["cli"].trainer.checkpoint_callback.best_model_score - ) + self.best_model_score = float(script_globals["cli"].trainer.checkpoint_callback.best_model_score) class ImageServeGradio(ServeGradio): diff --git a/quick_start/setup_tools.py b/quick_start/setup_tools.py index e939475..6c469de 100644 --- a/quick_start/setup_tools.py +++ b/quick_start/setup_tools.py @@ -19,9 +19,7 @@ _PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__)) -def _load_requirements( - path_dir: str, file_name: str = "requirements.txt", comment_char: str = "#" -) -> List[str]: +def _load_requirements(path_dir: str, file_name: str = "requirements.txt", comment_char: str = "#") -> List[str]: """Load requirements from a file. >>> _load_requirements(_PROJECT_ROOT) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE @@ -62,13 +60,9 @@ def _load_readme_description(path_dir: str, homepage: str, ver: str) -> str: # readthedocs badge text = text.replace("badge/?version=stable", f"badge/?version={ver}") - text = text.replace( - "lightning.readthedocs.io/en/stable/", f"lightning.readthedocs.io/en/{ver}" - ) + text = text.replace("lightning.readthedocs.io/en/stable/", f"lightning.readthedocs.io/en/{ver}") # codecov badge - text = text.replace( - "/branch/master/graph/badge.svg", f"/release/{ver}/graph/badge.svg" - ) + text = text.replace("/branch/master/graph/badge.svg", f"/release/{ver}/graph/badge.svg") # replace github badges for release ones text = text.replace("badge.svg?branch=master&event=push", f"badge.svg?tag={ver}") diff --git a/requirements.txt b/requirements.txt index 97661e8..9750e03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ gradio <=3.45.2 pyyaml <=6.0.1 protobuf >4.21, <5.28.0 # 4.21 breaks with wandb, tensorboard, or pytorch-lightning: https://github.com/protocolbuffers/protobuf/issues/10048 websockets -lightning[app] >=2.1.0 +lightning[app] >=2.1.0, <2.4.0 tensorboard diff --git a/setup.py b/setup.py index 56eae0e..53b3706 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,7 @@ def _load_py_module(fname, pkg=PACKAGE_NAME): - spec = spec_from_file_location( - os.path.join(pkg, fname), os.path.join(_PATH_ROOT, pkg, fname) - ) + spec = spec_from_file_location(os.path.join(pkg, fname), os.path.join(_PATH_ROOT, pkg, fname)) py = module_from_spec(spec) spec.loader.exec_module(py) return py @@ -20,9 +18,7 @@ def _load_py_module(fname, pkg=PACKAGE_NAME): about = _load_py_module("__about__.py") setup_tools = _load_py_module("setup_tools.py") -long_description = setup_tools._load_readme_description( - _PATH_ROOT, homepage=about.__homepage__, ver=about.__version__ -) +long_description = setup_tools._load_readme_description(_PATH_ROOT, homepage=about.__homepage__, ver=about.__version__) # https://packaging.python.org/discussions/install-requires-vs-requirements / # keep the meta-data here for simplicity in reading this file... it's not obvious diff --git a/train_script.py b/train_script.py index 018388c..6df7f67 100644 --- a/train_script.py +++ b/train_script.py @@ -82,20 +82,12 @@ def prepare_data(self) -> None: MNIST("./data", download=True) def train_dataloader(self): - train_dataset = MNIST( - "./data", train=True, download=False, transform=self.transform - ) - return torch.utils.data.DataLoader( - train_dataset, batch_size=self.hparams.batch_size - ) + train_dataset = MNIST("./data", train=True, download=False, transform=self.transform) + return torch.utils.data.DataLoader(train_dataset, batch_size=self.hparams.batch_size) def val_dataloader(self): - val_dataset = MNIST( - "./data", train=False, download=False, transform=self.transform - ) - return torch.utils.data.DataLoader( - val_dataset, batch_size=self.hparams.batch_size - ) + val_dataset = MNIST("./data", train=False, download=False, transform=self.transform) + return torch.utils.data.DataLoader(val_dataset, batch_size=self.hparams.batch_size) if __name__ == "__main__":