Skip to content

Commit 2dc4d3d

Browse files
authored
style: Switches to ruff for code quality (#85)
* chore: Switches to ruff * docs: Updates makefile * ci: Updates CI * docs: Updates README * docs: Updates CONTRIBUTING * style: Fixes lint & format issues * style: Fixed typing * chore: Updates conda recipe
1 parent f4e4e42 commit 2dc4d3d

33 files changed

+498
-538
lines changed

.conda/meta.yaml

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
1-
# https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#loading-data-from-other-files
2-
# https://github.com/conda/conda-build/pull/4480
3-
# for conda-build > 3.21.9
4-
# {% set pyproject = load_file_data('../pyproject.toml', from_recipe_dir=True) %}
5-
# {% set project = pyproject.get('project') %}
6-
# {% set urls = pyproject.get('project', {}).get('urls') %}
1+
{% set pyproject = load_file_data('../pyproject.toml', from_recipe_dir=True) %}
2+
{% set project = pyproject.get('project') %}
3+
{% set urls = pyproject.get('project', {}).get('urls') %}
4+
{% set version = environ.get('BUILD_VERSION', '0.2.0.dev0') %}
75
package:
8-
name: torchscan
9-
version: "{{ environ.get('BUILD_VERSION') }}"
6+
name: {{ project.get('name') }}
7+
version: {{ version }}
108

119
source:
12-
fn: torchscan-{{ environ.get('BUILD_VERSION') }}.tar.gz
13-
url: ../dist/torchscan-{{ environ.get('BUILD_VERSION') }}.tar.gz
10+
fn: {{ project.get('name') }}-{{ version }}}.tar.gz
11+
url: ../dist/{{ project.get('name') }}-{{ version }}.tar.gz
1412

1513
build:
16-
number: 0
1714
noarch: python
1815
script: python setup.py install --single-version-externally-managed --record=record.txt
1916

2017
requirements:
2118
host:
22-
- python>=3.6, <4.0
19+
- python>=3.8, <4.0
2320
- setuptools
2421

2522
run:
26-
- python>=3.6, <4.0
27-
- pytorch >=1.5.0, <2.0.0
23+
- pytorch >=2.0.0, <3.0.0
2824

2925
test:
3026
# Python imports
@@ -33,13 +29,15 @@ test:
3329
- torchscan.modules
3430
- torchscan.process
3531
- torchscan.utils
32+
requires:
33+
- python
3634

3735
about:
38-
home: https://github.com/frgfm/torch-scan
36+
home: {{ urls.get('repository') }}
3937
license: Apache 2.0
40-
license_file: LICENSE
41-
summary: 'Useful information about your Pytorch module'
38+
license_file: {{ project.get('license', {}).get('file') }}
39+
summary: {{ project.get('description') }}
4240
# description: |
4341
# {{ data['long_description'] | replace("\n", "\n ") | replace("#", '\#')}}
44-
doc_url: https://frgfm.github.io/torch-scan/
45-
dev_url: https://github.com/frgfm/torch-scan
42+
doc_url: {{ urls.get('documentation') }}
43+
dev_url: {{ urls.get('repository') }}

.flake8

-5
This file was deleted.

.github/collect_env.py

+23-29
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
import locale
1515
import os
1616
import re
17-
import subprocess
17+
import subprocess # noqa S404
1818
import sys
19-
from collections import namedtuple
19+
from pathlib import Path
20+
from typing import NamedTuple
2021

2122
try:
2223
import torchscan
@@ -36,20 +37,16 @@
3637

3738

3839
# System Environment Information
39-
SystemEnv = namedtuple(
40-
"SystemEnv",
41-
[
42-
"torchscan_version",
43-
"torch_version",
44-
"os",
45-
"python_version",
46-
"is_cuda_available",
47-
"cuda_runtime_version",
48-
"nvidia_driver_version",
49-
"nvidia_gpu_models",
50-
"cudnn_version",
51-
],
52-
)
40+
class SystemEnv(NamedTuple):
41+
torchscan_version: str
42+
torch_version: str
43+
os: str
44+
python_version: str
45+
is_cuda_available: bool
46+
cuda_runtime_version: str
47+
nvidia_driver_version: str
48+
nvidia_gpu_models: str
49+
cudnn_version: str
5350

5451

5552
def run(command):
@@ -125,18 +122,18 @@ def get_cudnn_version(run_lambda):
125122
# find will return 1 if there are permission errors or if not found
126123
if len(out) == 0 or rc not in (1, 0):
127124
lib = os.environ.get("CUDNN_LIBRARY")
128-
if lib is not None and os.path.isfile(lib):
125+
if lib is not None and Path(lib).is_file():
129126
return os.path.realpath(lib)
130127
return None
131128
files = set()
132129
for fn in out.split("\n"):
133130
fn = os.path.realpath(fn) # eliminate symbolic links
134-
if os.path.isfile(fn):
131+
if Path(fn).is_file():
135132
files.add(fn)
136133
if not files:
137134
return None
138135
# Alphabetize the result because the order is non-deterministic otherwise
139-
files = list(sorted(files))
136+
files = sorted(files)
140137
if len(files) == 1:
141138
return files[0]
142139
result = "\n".join(files)
@@ -149,11 +146,11 @@ def get_nvidia_smi():
149146
if get_platform() == "win32":
150147
system_root = os.environ.get("SYSTEMROOT", "C:\\Windows")
151148
program_files_root = os.environ.get("PROGRAMFILES", "C:\\Program Files")
152-
legacy_path = os.path.join(program_files_root, "NVIDIA Corporation", "NVSMI", smi)
153-
new_path = os.path.join(system_root, "System32", smi)
149+
legacy_path = Path(program_files_root) / "NVIDIA Corporation" / "NVSMI" / smi
150+
new_path = Path(system_root) / "System32" / smi
154151
smis = [new_path, legacy_path]
155152
for candidate_smi in smis:
156-
if os.path.exists(candidate_smi):
153+
if Path(candidate_smi).exists():
157154
smi = '"{}"'.format(candidate_smi)
158155
break
159156
return smi
@@ -220,10 +217,7 @@ def get_os(run_lambda):
220217
def get_env_info():
221218
run_lambda = run
222219

223-
if TORCHSCAN_AVAILABLE:
224-
torchscan_str = torchscan.__version__
225-
else:
226-
torchscan_str = "N/A"
220+
torchscan_str = torchscan.__version__ if TORCHSCAN_AVAILABLE else "N/A"
227221

228222
if TORCH_AVAILABLE:
229223
torch_str = torch.__version__
@@ -261,14 +255,14 @@ def get_env_info():
261255

262256
def pretty_str(envinfo):
263257
def replace_nones(dct, replacement="Could not collect"):
264-
for key in dct.keys():
258+
for key in dct:
265259
if dct[key] is not None:
266260
continue
267261
dct[key] = replacement
268262
return dct
269263

270264
def replace_bools(dct, true="Yes", false="No"):
271-
for key in dct.keys():
265+
for key in dct:
272266
if dct[key] is True:
273267
dct[key] = true
274268
elif dct[key] is False:
@@ -292,7 +286,7 @@ def maybe_start_on_next_line(string):
292286
"nvidia_gpu_models",
293287
"nvidia_driver_version",
294288
]
295-
all_cuda_fields = dynamic_cuda_fields + ["cudnn_version"]
289+
all_cuda_fields = [*dynamic_cuda_fields, "cudnn_version"]
296290
all_dynamic_cuda_fields_missing = all(mutable_dict[field] is None for field in dynamic_cuda_fields)
297291
if TORCH_AVAILABLE and not torch.cuda.is_available() and all_dynamic_cuda_fields_missing:
298292
for field in all_cuda_fields:

.github/verify_labels.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545

4646

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

5153

.github/workflows/builds.yml

+45-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python: [3.7, 3.8]
16+
python: [3.8, 3.9, '3.10', 3.11]
1717
steps:
1818
- uses: actions/checkout@v2
19-
- name: Set up Python
20-
uses: actions/setup-python@v1
19+
- uses: actions/setup-python@v4
2120
with:
2221
python-version: ${{ matrix.python }}
2322
architecture: x64
@@ -29,6 +28,48 @@ jobs:
2928
- name: Install package
3029
run: |
3130
python -m pip install --upgrade pip
32-
pip install -e . --upgrade
31+
pip install -e .
3332
- name: Import package
3433
run: python -c "import torchscan; print(torchscan.__version__)"
34+
35+
pypi:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
- name: Set up Python
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: 3.9
43+
architecture: x64
44+
- name: Cache python modules
45+
uses: actions/cache@v2
46+
with:
47+
path: ~/.cache/pip
48+
key: ${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }}-build
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
pip install setuptools wheel twine --upgrade
53+
- run: |
54+
python setup.py sdist bdist_wheel
55+
twine check dist/*
56+
57+
conda:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v2
61+
- uses: conda-incubator/setup-miniconda@v2
62+
with:
63+
auto-update-conda: true
64+
python-version: "3.9"
65+
- name: Install dependencies
66+
shell: bash -el {0}
67+
run: conda install -y conda-build conda-verify
68+
- name: Build conda
69+
shell: bash -el {0}
70+
run: |
71+
python setup.py sdist
72+
mkdir conda-dist
73+
conda env list
74+
conda build .conda/ -c pytorch --output-folder conda-dist
75+
ls -l conda-dist/noarch/*tar.bz2

.github/workflows/doc-status.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ jobs:
66
see-page-build-payload:
77
runs-on: ubuntu-latest
88
steps:
9-
- name: Set up Python 3.7
10-
uses: actions/setup-python@v1
9+
- uses: actions/setup-python@v4
1110
with:
12-
python-version: 3.7
11+
python-version: 3.9
1312
architecture: x64
1413
- name: check status
1514
run: |

.github/workflows/docs.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ubuntu-latest]
12-
python: [3.7]
12+
python: [3.9]
1313
steps:
1414
- uses: actions/checkout@v2
1515
with:
1616
persist-credentials: false
17-
- name: Set up Python
18-
uses: actions/setup-python@v1
17+
- uses: actions/setup-python@v4
1918
with:
2019
python-version: ${{ matrix.python }}
2120
architecture: x64

.github/workflows/pr-labels.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Checkout repository
1414
uses: actions/checkout@v2
1515
- name: Set up python
16-
uses: actions/setup-python@v2
16+
uses: actions/setup-python@v4
1717
- name: Install requests
1818
run: pip install requests
1919
- name: Process commit and find merger responsible for labeling

0 commit comments

Comments
 (0)