Browse Source

[to #42322933]compatible with windows path on only core parts

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9855254
master
zhangzhicheng.zzc yingda.chen 3 years ago
parent
commit
5b0b54633b
6 changed files with 16 additions and 12 deletions
  1. +3
    -1
      modelscope/hub/constants.py
  2. +2
    -2
      modelscope/msdatasets/config.py
  3. +3
    -1
      modelscope/utils/ast_utils.py
  4. +2
    -3
      modelscope/utils/file_utils.py
  5. +2
    -1
      modelscope/utils/import_utils.py
  6. +4
    -4
      tests/utils/test_ast.py

+ 3
- 1
modelscope/hub/constants.py View File

@@ -1,3 +1,5 @@
from pathlib import Path

MODELSCOPE_URL_SCHEME = 'http://'
DEFAULT_MODELSCOPE_DOMAIN = 'www.modelscope.cn'
DEFAULT_MODELSCOPE_DATA_ENDPOINT = MODELSCOPE_URL_SCHEME + DEFAULT_MODELSCOPE_DOMAIN
@@ -6,7 +8,7 @@ DEFAULT_MODELSCOPE_GROUP = 'damo'
MODEL_ID_SEPARATOR = '/'
FILE_HASH = 'Sha256'
LOGGER_NAME = 'ModelScopeHub'
DEFAULT_CREDENTIALS_PATH = '~/.modelscope/credentials'
DEFAULT_CREDENTIALS_PATH = Path.home().joinpath('.modelscope', 'credentials')
API_RESPONSE_FIELD_DATA = 'Data'
API_RESPONSE_FIELD_GIT_ACCESS_TOKEN = 'AccessToken'
API_RESPONSE_FIELD_USERNAME = 'Username'


+ 2
- 2
modelscope/msdatasets/config.py View File

@@ -4,9 +4,9 @@ from pathlib import Path
# Cache location
from modelscope.hub.constants import DEFAULT_MODELSCOPE_DATA_ENDPOINT

DEFAULT_CACHE_HOME = '~/.cache'
DEFAULT_CACHE_HOME = Path.home().joinpath('.cache')
CACHE_HOME = os.getenv('CACHE_HOME', DEFAULT_CACHE_HOME)
DEFAULT_MS_CACHE_HOME = os.path.join(CACHE_HOME, 'modelscope/hub')
DEFAULT_MS_CACHE_HOME = os.path.join(CACHE_HOME, 'modelscope', 'hub')
MS_CACHE_HOME = os.path.expanduser(
os.getenv('MS_CACHE_HOME', DEFAULT_MS_CACHE_HOME))



+ 3
- 1
modelscope/utils/ast_utils.py View File

@@ -7,6 +7,7 @@ import os.path as osp
import time
import traceback
from functools import reduce
from pathlib import Path
from typing import Generator, Union

import gast
@@ -24,9 +25,10 @@ from modelscope.utils.registry import default_group

logger = get_logger()
storage = LocalStorage()
p = Path(__file__)

# get the path of package 'modelscope'
MODELSCOPE_PATH = '/'.join(os.path.dirname(__file__).split('/')[:-1])
MODELSCOPE_PATH = p.resolve().parents[1]
REGISTER_MODULE = 'register_module'
IGNORED_PACKAGES = ['modelscope', '.']
SCAN_SUB_FOLDERS = [


+ 2
- 3
modelscope/utils/file_utils.py View File

@@ -1,7 +1,7 @@
# Copyright (c) Alibaba, Inc. and its affiliates.

import inspect
import os
from pathlib import Path


# TODO: remove this api, unify to flattened args
@@ -33,6 +33,5 @@ def get_default_cache_dir():
"""
default base dir: '~/.cache/modelscope'
"""
default_cache_dir = os.path.expanduser(
os.path.join('~/.cache', 'modelscope'))
default_cache_dir = Path.home().joinpath('.cache', 'modelscope')
return default_cache_dir

+ 2
- 1
modelscope/utils/import_utils.py View File

@@ -10,6 +10,7 @@ from collections import OrderedDict
from functools import wraps
from importlib import import_module
from itertools import chain
from pathlib import Path
from types import ModuleType
from typing import Any

@@ -43,7 +44,7 @@ def import_modules_from_file(py_file: str):
"""
dirname, basefile = os.path.split(py_file)
if dirname == '':
dirname == './'
dirname = Path.cwd()
module_name = osp.splitext(basefile)[0]
sys.path.insert(0, dirname)
validate_py_syntax(py_file)


+ 4
- 4
tests/utils/test_ast.py View File

@@ -5,13 +5,13 @@ import shutil
import tempfile
import time
import unittest

import gast
from pathlib import Path

from modelscope.utils.ast_utils import AstScaning, FilesAstScaning, load_index

MODELSCOPE_PATH = '/'.join(
os.path.dirname(__file__).split('/')[:-2]) + '/modelscope'
p = Path(__file__)

MODELSCOPE_PATH = p.resolve().parents[2].joinpath('modelscope')


class AstScaningTest(unittest.TestCase):


Loading…
Cancel
Save