ソースを参照

copytree implementation for py37 compatibility (#162)

* copytree implementation for py37 compatibility

* Running tests for python3.7

* Increment version

* Python3.7 notions
Alexey Bukhtiyarov 4 年 前
コミット
e58eb430b1
6 ファイル変更38 行追加5 行削除
  1. 20 0
      .circleci/config.yml
  2. 1 1
      README.md
  3. 1 1
      docs/user/quickstart.md
  4. 1 1
      hivemind/__init__.py
  5. 14 2
      hivemind/server/checkpoints.py
  6. 1 0
      setup.py

+ 20 - 0
.circleci/config.yml

@@ -1,6 +1,26 @@
 version: 2.1
 
 jobs:
+  build-and-test-py37:
+    docker:
+      - image: circleci/python:3.7.10
+    steps:
+      - checkout
+      - restore_cache:
+          keys:
+            - v1-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}
+      - run: pip install -r requirements.txt
+      - run: pip install -r requirements-dev.txt
+      - save_cache:
+          key: v1-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}
+          paths:
+            - '~/.cache/pip'
+      - run:
+          command: pip install -e .
+          name: setup
+      - run:
+          command: pytest ./tests
+          name: tests
   build-and-test-py38:
     docker:
       - image: circleci/python:3.8.1

+ 1 - 1
README.md

@@ -24,7 +24,7 @@ the [NeurIPS 2020 paper](https://arxiv.org/abs/2002.04013).
 
 ## Installation
 
-Before installing hivemind, make sure that your environment has Python 3.8+
+Before installing hivemind, make sure that your environment has Python 3.7+
 and [PyTorch](https://pytorch.org/get-started/locally/#start-locally) with a version at least as new as 1.6.0.
 
 To start using this library, you can either use the pip package manager or build it from source. Since currently the

+ 1 - 1
docs/user/quickstart.md

@@ -16,7 +16,7 @@ pip install .
 
 You can also install it in the editable mode with `pip install -e .`.
 
-* __Dependencies:__ Hivemind requires Python 3.8+.
+* __Dependencies:__ Hivemind requires Python 3.7+.
   The [requirements](https://github.com/learning-at-home/hivemind/blob/master/requirements.txt) are installed
   automatically.
 * __OS support:__ Linux and macOS should just work. We do not officially support Windows, but you are welcome to

+ 1 - 1
hivemind/__init__.py

@@ -3,4 +3,4 @@ from hivemind.dht import *
 from hivemind.server import *
 from hivemind.utils import *
 
-__version__ = '0.9.0'
+__version__ = '0.9.1'

+ 14 - 2
hivemind/server/checkpoints.py

@@ -1,7 +1,7 @@
 import threading
 from datetime import datetime
 from pathlib import Path
-from shutil import copytree
+from shutil import copy2
 from tempfile import TemporaryDirectory
 from typing import Dict
 import os
@@ -18,6 +18,18 @@ def dir_is_correct(directory: Path):
     return True
 
 
+def copy_tree(src: str, dst: str):
+    if not os.path.exists(dst):
+        os.makedirs(dst)
+    for item in os.listdir(src):
+        src_entry = os.path.join(src, item)
+        dst_entry = os.path.join(dst, item)
+        if os.path.isdir(src_entry):
+            copy_tree(src_entry, dst_entry)
+        else:
+            copy2(src_entry, dst_entry)
+
+
 class CheckpointSaver(threading.Thread):
     def __init__(self, expert_backends: Dict[str, ExpertBackend], checkpoint_dir: Path, update_period: int):
         super().__init__()
@@ -45,7 +57,7 @@ def store_experts(experts: Dict[str, ExpertBackend], checkpoint_dir: Path):
             checkpoint_name = expert_dir / f'checkpoint_{timestamp}.pt'
             torch.save(expert_backend.state_dict(), checkpoint_name)
             os.symlink(checkpoint_name, expert_dir / 'checkpoint_last.pt')
-        copytree(tmpdirname, str(checkpoint_dir), dirs_exist_ok=True)
+        copy_tree(tmpdirname, str(checkpoint_dir))
 
 
 def load_weights(experts: Dict[str, ExpertBackend], checkpoint_dir: Path):

+ 1 - 0
setup.py

@@ -83,6 +83,7 @@ setup(
         'Intended Audience :: Science/Research',
         'License :: OSI Approved :: MIT License',
         'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
         'Topic :: Scientific/Engineering',