Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Switches to ruff for code quality #85

Merged
merged 9 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#loading-data-from-other-files
# https://github.com/conda/conda-build/pull/4480
# for conda-build > 3.21.9
# {% set pyproject = load_file_data('../pyproject.toml', from_recipe_dir=True) %}
# {% set project = pyproject.get('project') %}
# {% set urls = pyproject.get('project', {}).get('urls') %}
{% set pyproject = load_file_data('../pyproject.toml', from_recipe_dir=True) %}
{% set project = pyproject.get('project') %}
{% set urls = pyproject.get('project', {}).get('urls') %}
{% set version = environ.get('BUILD_VERSION', '0.2.0.dev0') %}
package:
name: torchscan
version: "{{ environ.get('BUILD_VERSION') }}"
name: {{ project.get('name') }}
version: {{ version }}

source:
fn: torchscan-{{ environ.get('BUILD_VERSION') }}.tar.gz
url: ../dist/torchscan-{{ environ.get('BUILD_VERSION') }}.tar.gz
fn: {{ project.get('name') }}-{{ version }}}.tar.gz
url: ../dist/{{ project.get('name') }}-{{ version }}.tar.gz

build:
number: 0
noarch: python
script: python setup.py install --single-version-externally-managed --record=record.txt

requirements:
host:
- python>=3.6, <4.0
- python>=3.8, <4.0
- setuptools

run:
- python>=3.6, <4.0
- pytorch >=1.5.0, <2.0.0
- pytorch >=2.0.0, <3.0.0

test:
# Python imports
Expand All @@ -33,13 +29,15 @@ test:
- torchscan.modules
- torchscan.process
- torchscan.utils
requires:
- python

about:
home: https://github.com/frgfm/torch-scan
home: {{ urls.get('repository') }}
license: Apache 2.0
license_file: LICENSE
summary: 'Useful information about your Pytorch module'
license_file: {{ project.get('license', {}).get('file') }}
summary: {{ project.get('description') }}
# description: |
# {{ data['long_description'] | replace("\n", "\n ") | replace("#", '\#')}}
doc_url: https://frgfm.github.io/torch-scan/
dev_url: https://github.com/frgfm/torch-scan
doc_url: {{ urls.get('documentation') }}
dev_url: {{ urls.get('repository') }}
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

52 changes: 23 additions & 29 deletions .github/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import locale
import os
import re
import subprocess
import subprocess # noqa S404
import sys
from collections import namedtuple
from pathlib import Path
from typing import NamedTuple

try:
import torchscan
Expand All @@ -36,20 +37,16 @@


# System Environment Information
SystemEnv = namedtuple(
"SystemEnv",
[
"torchscan_version",
"torch_version",
"os",
"python_version",
"is_cuda_available",
"cuda_runtime_version",
"nvidia_driver_version",
"nvidia_gpu_models",
"cudnn_version",
],
)
class SystemEnv(NamedTuple):
torchscan_version: str
torch_version: str
os: str
python_version: str
is_cuda_available: bool
cuda_runtime_version: str
nvidia_driver_version: str
nvidia_gpu_models: str
cudnn_version: str


def run(command):
Expand Down Expand Up @@ -125,18 +122,18 @@ def get_cudnn_version(run_lambda):
# find will return 1 if there are permission errors or if not found
if len(out) == 0 or rc not in (1, 0):
lib = os.environ.get("CUDNN_LIBRARY")
if lib is not None and os.path.isfile(lib):
if lib is not None and Path(lib).is_file():
return os.path.realpath(lib)
return None
files = set()
for fn in out.split("\n"):
fn = os.path.realpath(fn) # eliminate symbolic links
if os.path.isfile(fn):
if Path(fn).is_file():
files.add(fn)
if not files:
return None
# Alphabetize the result because the order is non-deterministic otherwise
files = list(sorted(files))
files = sorted(files)
if len(files) == 1:
return files[0]
result = "\n".join(files)
Expand All @@ -149,11 +146,11 @@ def get_nvidia_smi():
if get_platform() == "win32":
system_root = os.environ.get("SYSTEMROOT", "C:\\Windows")
program_files_root = os.environ.get("PROGRAMFILES", "C:\\Program Files")
legacy_path = os.path.join(program_files_root, "NVIDIA Corporation", "NVSMI", smi)
new_path = os.path.join(system_root, "System32", smi)
legacy_path = Path(program_files_root) / "NVIDIA Corporation" / "NVSMI" / smi
new_path = Path(system_root) / "System32" / smi
smis = [new_path, legacy_path]
for candidate_smi in smis:
if os.path.exists(candidate_smi):
if Path(candidate_smi).exists():
smi = '"{}"'.format(candidate_smi)
break
return smi
Expand Down Expand Up @@ -220,10 +217,7 @@ def get_os(run_lambda):
def get_env_info():
run_lambda = run

if TORCHSCAN_AVAILABLE:
torchscan_str = torchscan.__version__
else:
torchscan_str = "N/A"
torchscan_str = torchscan.__version__ if TORCHSCAN_AVAILABLE else "N/A"

if TORCH_AVAILABLE:
torch_str = torch.__version__
Expand Down Expand Up @@ -261,14 +255,14 @@ def get_env_info():

def pretty_str(envinfo):
def replace_nones(dct, replacement="Could not collect"):
for key in dct.keys():
for key in dct:
if dct[key] is not None:
continue
dct[key] = replacement
return dct

def replace_bools(dct, true="Yes", false="No"):
for key in dct.keys():
for key in dct:
if dct[key] is True:
dct[key] = true
elif dct[key] is False:
Expand All @@ -292,7 +286,7 @@ def maybe_start_on_next_line(string):
"nvidia_gpu_models",
"nvidia_driver_version",
]
all_cuda_fields = dynamic_cuda_fields + ["cudnn_version"]
all_cuda_fields = [*dynamic_cuda_fields, "cudnn_version"]
all_dynamic_cuda_fields_missing = all(mutable_dict[field] is None for field in dynamic_cuda_fields)
if TORCH_AVAILABLE and not torch.cuda.is_available() and all_dynamic_cuda_fields_missing:
for field in all_cuda_fields:
Expand Down
4 changes: 3 additions & 1 deletion .github/verify_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@


def query_repo(cmd: str, *, accept) -> Any:
response = requests.get(f"https://api.github.com/repos/{GH_ORG}/{GH_REPO}/{cmd}", headers=dict(Accept=accept))
response = requests.get(
f"https://api.github.com/repos/{GH_ORG}/{GH_REPO}/{cmd}", headers={"Accept": accept}, timeout=5
)
return response.json()


Expand Down
49 changes: 45 additions & 4 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.7, 3.8]
python: [3.8, 3.9, '3.10', 3.11]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
architecture: x64
Expand All @@ -29,6 +28,48 @@ jobs:
- name: Install package
run: |
python -m pip install --upgrade pip
pip install -e . --upgrade
pip install -e .
- name: Import package
run: python -c "import torchscan; print(torchscan.__version__)"

pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }}-build
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine --upgrade
- run: |
python setup.py sdist bdist_wheel
twine check dist/*

conda:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.9"
- name: Install dependencies
shell: bash -el {0}
run: conda install -y conda-build conda-verify
- name: Build conda
shell: bash -el {0}
run: |
python setup.py sdist
mkdir conda-dist
conda env list
conda build .conda/ -c pytorch --output-folder conda-dist
ls -l conda-dist/noarch/*tar.bz2
5 changes: 2 additions & 3 deletions .github/workflows/doc-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ jobs:
see-page-build-payload:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.9
architecture: x64
- name: check status
run: |
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.7]
python: [3.9]
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v1
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
architecture: x64
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
- name: Install requests
run: pip install requests
- name: Process commit and find merger responsible for labeling
Expand Down
Loading
Loading