Skip to content

Commit 3be1e23

Browse files
authored
lint: Add s3_management to PYFMT (#6903)
Also applies all PYFMT patches to s3_management Signed-off-by: Eli Uriegas <[email protected]>
1 parent 3b952a3 commit 3be1e23

File tree

4 files changed

+432
-327
lines changed

4 files changed

+432
-327
lines changed

.lintrunner.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,6 @@ code = 'PYFMT'
295295
include_patterns = [
296296
'**/*.py',
297297
]
298-
exclude_patterns = [
299-
's3_management/**',
300-
]
301298
command = [
302299
'python3',
303300
'tools/linter/adapters/pyfmt_linter.py',

s3_management/backup_conda.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,37 @@
44
# Do not use unless you know what you are doing
55
# Usage: python backup_conda.py --version 1.6.0
66

7-
import boto3
7+
import argparse
8+
import hashlib
9+
import os
10+
import urllib
811
from typing import List, Optional
12+
13+
import boto3
914
import conda.api
10-
import urllib
11-
import os
12-
import hashlib
13-
import argparse
1415

15-
S3 = boto3.resource('s3')
16-
BUCKET = S3.Bucket('pytorch-backup')
16+
17+
S3 = boto3.resource("s3")
18+
BUCKET = S3.Bucket("pytorch-backup")
1719
_known_subdirs = ["linux-64", "osx-64", "osx-arm64", "win-64"]
1820

1921

20-
def compute_md5(path:str) -> str:
22+
def compute_md5(path: str) -> str:
2123
with open(path, "rb") as f:
2224
return hashlib.md5(f.read()).hexdigest()
2325

2426

25-
def download_conda_package(package:str, version:Optional[str] = None,
26-
depends:Optional[str] = None, channel:Optional[str] = None) -> List[str]:
27-
packages = conda.api.SubdirData.query_all(package,
28-
channels = [channel] if channel is not None else None,
29-
subdirs = _known_subdirs)
27+
def download_conda_package(
28+
package: str,
29+
version: Optional[str] = None,
30+
depends: Optional[str] = None,
31+
channel: Optional[str] = None,
32+
) -> List[str]:
33+
packages = conda.api.SubdirData.query_all(
34+
package,
35+
channels=[channel] if channel is not None else None,
36+
subdirs=_known_subdirs,
37+
)
3038
rc = []
3139

3240
for pkg in packages:
@@ -36,7 +44,7 @@ def download_conda_package(package:str, version:Optional[str] = None,
3644
continue
3745

3846
print(f"Downloading {pkg.url}...")
39-
os.makedirs(pkg.subdir, exist_ok = True)
47+
os.makedirs(pkg.subdir, exist_ok=True)
4048
fname = f"{pkg.subdir}/{pkg.fn}"
4149
if not os.path.exists(fname):
4250
with open(fname, "wb") as f, urllib.request.urlopen(pkg.url) as url:
@@ -48,26 +56,25 @@ def download_conda_package(package:str, version:Optional[str] = None,
4856

4957
return rc
5058

59+
5160
def upload_to_s3(prefix: str, fnames: List[str]) -> None:
5261
for fname in fnames:
5362
BUCKET.upload_file(fname, f"{prefix}/{fname}")
5463
print(fname)
5564

5665

57-
5866
if __name__ == "__main__":
5967
parser = argparse.ArgumentParser()
6068
parser.add_argument(
61-
"--version",
62-
help="PyTorch Version to backup",
63-
type=str,
64-
required = True
69+
"--version", help="PyTorch Version to backup", type=str, required=True
6570
)
6671
options = parser.parse_args()
67-
rc = download_conda_package("pytorch", channel = "pytorch", version = options.version)
72+
rc = download_conda_package("pytorch", channel="pytorch", version=options.version)
6873
upload_to_s3(f"v{options.version}/conda", rc)
6974

7075
for libname in ["torchvision", "torchaudio", "torchtext"]:
7176
print(f"processing {libname}")
72-
rc = download_conda_package(libname, channel = "pytorch", depends = f"pytorch {options.version}")
77+
rc = download_conda_package(
78+
libname, channel="pytorch", depends=f"pytorch {options.version}"
79+
)
7380
upload_to_s3(f"v{options.version}/conda", rc)

0 commit comments

Comments
 (0)