"docs/source/ko/using-diffusers/shap-e.md" did not exist on "30e5e81d58eb9c3979c07e6626bae89c1df8c0e1"
Unverified Commit efd0e40e authored by liuzhe-lz's avatar liuzhe-lz Committed by GitHub
Browse files

[pipeline] More aggressive cache (#4495)

parent e8e83146
pylint coverage
cython
flake8 flake8
ipython
jupyterlab
nbsphinx
pylint
pytest
pytest-azurepipelines
pytest-cov
sphinx sphinx
sphinx-argparse sphinx-argparse
sphinx-rtd-theme sphinx-rtd-theme
sphinxcontrib-websupport sphinxcontrib-websupport
nbsphinx
pytest
pytest-cov
pytest-azurepipelines
coverage
ipython
jupyterlab
...@@ -4,7 +4,7 @@ torchvision == 0.8.2+cpu ...@@ -4,7 +4,7 @@ torchvision == 0.8.2+cpu
# It will install pytorch-lightning 0.8.x and unit tests won't work. # It will install pytorch-lightning 0.8.x and unit tests won't work.
# Latest version has conflict with tensorboard and tensorflow 1.x. # Latest version has conflict with tensorboard and tensorflow 1.x.
#pytorch-lightning pytorch-lightning
torchmetrics torchmetrics
onnx onnx
......
...@@ -7,7 +7,7 @@ smac4nni ...@@ -7,7 +7,7 @@ smac4nni
# BOHB # BOHB
ConfigSpace>=0.4.17 ConfigSpace>=0.4.17
statsmodels==0.12.0 statsmodels>=0.12.0
# PPOTuner # PPOTuner
gym gym
......
trigger: none
pr: none
schedules:
- cron: "0 16 * * *"
branches:
include: [ master ]
always: true
jobs:
- job: ubuntu_latest
pool:
vmImage: ubuntu-latest
steps:
- template: templates/cache-dependencies-template.yml
parameters:
platform: ubuntu-latest
- job: ubuntu_legacy
pool:
vmImage: ubuntu-18.04
steps:
- template: templates/cache-dependencies-template.yml
parameters:
platform: ubuntu-legacy
- job: windows
pool:
vmImage: windows-latest
steps:
- template: templates/cache-dependencies-template.yml
parameters:
platform: windows
- job: macos
pool:
vmImage: macOS-latest
steps:
- template: templates/cache-dependencies-template.yml
parameters:
platform: macos
# To reduce debug cost, steps are sorted differently on each platform, trigger:
# so that a bug in any module will cause at least one platform to fail quickly. branches:
exclude: [ l10n_master ]
stages: stages:
- stage: lint - stage: lint
...@@ -7,42 +8,20 @@ stages: ...@@ -7,42 +8,20 @@ stages:
- job: docs - job: docs
pool: pool:
vmImage: ubuntu-latest vmImage: ubuntu-latest
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
steps: steps:
- task: UsePythonVersion@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 3.9 platform: ubuntu-latest
displayName: Configure Python version
- script: | - script: |
sudo apt-get install -y pandoc sudo apt-get install -y pandoc
sudo apt-get remove swig -y displayName: Install pandoc
sudo apt-get install swig3.0 -y
sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
displayName: Install apt packages
- task: Cache@2
inputs:
key: 'python | "$(Agent.OS)" | dependencies/*.txt'
restoreKeys: |
python | "$(Agent.OS)"
python
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- script: |
set -e
python -m pip install -U -r dependencies/setup.txt
python -m pip install -r dependencies/develop.txt
python -m pip install -r dependencies/required.txt
python -m pip install -r dependencies/recommended.txt
python -m pip install -r dependencies/required_extra.txt
displayName: Install requirements
- script: |
python test/vso_tools/interim_patch.py
displayName: Apply patch
- script: | - script: |
cd docs cd docs
python tools/chineselink.py check python tools/chineselink.py check
displayName: Translation up-to-date displayName: Translation up-to-date
- script: | - script: |
cd docs/en_US cd docs/en_US
sphinx-build -M html . _build -W --keep-going -T sphinx-build -M html . _build -W --keep-going -T
...@@ -51,37 +30,20 @@ stages: ...@@ -51,37 +30,20 @@ stages:
- job: python - job: python
pool: pool:
vmImage: ubuntu-latest vmImage: ubuntu-latest
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
steps: steps:
- task: UsePythonVersion@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 3.9 platform: ubuntu-latest
displayName: Configure Python version
- script: | - script: |
sudo apt-get remove swig -y # pylint requires newer typing extension. Override requirements in tensorflow
sudo apt-get install swig3.0 -y python -m pip install "typing-extensions>=3.10"
sudo ln -s /usr/bin/swig3.0 /usr/bin/swig displayName: Resolve dependency version
displayName: Install apt packages
- task: Cache@2
inputs:
key: 'python | "$(Agent.OS)" | dependencies/*.txt'
restoreKeys: |
python | "$(Agent.OS)"
python
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- script: | - script: |
set -e python -m pylint --rcfile pylintrc nni
python -m pip install -U -r dependencies/setup.txt
python -m pip install -r dependencies/develop.txt
python -m pip install -r dependencies/required.txt
python -m pip install -r dependencies/recommended.txt
python -m pip install -r dependencies/required_extra.txt
python -m pip install "typing-extensions>=3.10" # pylint requires newer typing extension. Override requirements in tensorflow
displayName: Install requirements
- script: python -m pylint --rcfile pylintrc nni
displayName: pylint displayName: pylint
- script: | - script: |
set -e set -e
python -m flake8 nni --count --select=E9,F63,F72,F82 --show-source --statistics python -m flake8 nni --count --select=E9,F63,F72,F82 --show-source --statistics
...@@ -92,103 +54,45 @@ stages: ...@@ -92,103 +54,45 @@ stages:
- job: typescript - job: typescript
pool: pool:
vmImage: ubuntu-latest vmImage: ubuntu-latest
variables:
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
steps: steps:
- task: NodeTool@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 16.3.0 platform: ubuntu-latest
displayName: Configure Node.js version
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | ts/**/yarn.lock, !**/node_modules/**'
restoreKeys: |
yarn | "$(Agent.OS)"
path: $(YARN_CACHE_FOLDER)
displayName: Cache yarn packages
- script: | - script: |
set -e set -e
cd ts/nni_manager yarn --cwd ts/nni_manager
yarn yarn --cwd ts/nni_manager eslint
yarn eslint
displayName: ESLint (NNI Manager) displayName: ESLint (NNI Manager)
- script: | - script: |
set -e set -e
cd ts/webui yarn --cwd ts/webui
yarn yarn --cwd ts/webui eslint
yarn eslint
displayName: ESLint (WebUI) displayName: ESLint (WebUI)
# To reduce debug cost, steps are sorted differently on each platform,
# so that a bug in any module will cause at least one platform to fail quickly.
- stage: test - stage: test
jobs: jobs:
- job: ubuntu_latest - job: ubuntu_latest
pool: pool:
vmImage: ubuntu-latest vmImage: ubuntu-latest
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
steps: steps:
- task: UsePythonVersion@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 3.9 platform: ubuntu-latest
displayName: Configure Python version
- task: NodeTool@0
inputs:
versionSpec: 16.3.0
displayName: Configure Node.js version
- script: |
sudo apt-get install -y pandoc
sudo apt-get remove swig -y
sudo apt-get install swig3.0 -y
sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
displayName: Install apt packages
- task: Cache@2
inputs:
key: 'python | "$(Agent.OS)" | latest | dependencies/*.txt'
restoreKeys: |
python | "$(Agent.OS)"
python
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | latest | ts/**/yarn.lock, !**/node_modules/**'
restoreKeys: |
yarn | "$(Agent.OS)"
path: $(YARN_CACHE_FOLDER)
displayName: Cache yarn packages
- script: |
set -e
python -m pip install -U -r dependencies/setup.txt
python -m pip install -r dependencies/develop.txt
echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: Install Python tools
- script: | - script: |
python setup.py develop python setup.py develop
mkdir -p coverage echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: Install NNI displayName: Install NNI
- script: | - script: |
set -e set -e
python -m pip install -r dependencies/recommended.txt mkdir -p coverage
python -m pip install -e .[PPOTuner,DNGO]
displayName: Install extra dependencies
# Need del later
- script: |
python test/vso_tools/interim_patch.py
displayName: Torch utils tensorboard interim patch
- script: |
set -e
cd test cd test
python -m pytest ut --cov-config=.coveragerc \ python -m pytest ut --cov-config=.coveragerc \
--ignore=ut/compression/v1/test_pruners.py \ --ignore=ut/compression/v1/test_pruners.py \
...@@ -203,10 +107,8 @@ stages: ...@@ -203,10 +107,8 @@ stages:
displayName: Python unit test displayName: Python unit test
- script: | - script: |
set -e yarn --cwd ts/nni_manager test
cd ts/nni_manager cp ts/nni_manager/coverage/cobertura-coverage.xml coverage/typescript.xml
yarn test
cp coverage/cobertura-coverage.xml ../../coverage/typescript.xml
displayName: TypeScript unit test displayName: TypeScript unit test
- task: PublishTestResults@2 - task: PublishTestResults@2
...@@ -230,71 +132,17 @@ stages: ...@@ -230,71 +132,17 @@ stages:
- job: ubuntu_legacy - job: ubuntu_legacy
pool: pool:
vmImage: ubuntu-18.04 vmImage: ubuntu-18.04
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
steps: steps:
- task: UsePythonVersion@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 3.7 platform: ubuntu-legacy
displayName: Configure Python version
- task: NodeTool@0
inputs:
versionSpec: 16.3.0
displayName: Configure Node.js version
- script: |
sudo apt-get install -y pandoc
sudo apt-get remove swig -y
sudo apt-get install swig3.0 -y
sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
displayName: Install apt packages
- task: Cache@2
inputs:
key: 'python | "$(Agent.OS)" | legacy | dependencies/*.txt'
restoreKeys: |
python | "$(Agent.OS)"
python
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | legacy | ts/**/yarn.lock, !**/node_modules/**'
restoreKeys: |
yarn | "$(Agent.OS)"
path: $(YARN_CACHE_FOLDER)
displayName: Cache yarn packages
- script: |
set -e
cd dependencies
python -m pip install -U -r setup.txt
# FIXME: Version resolving is a complete mess. Now it works magically.
python -m pip install numpy==1.21.5
python -m pip install -r develop.txt
python -m pip install -r required.txt
python -m pip install -r required_extra.txt
python -m pip install -r recommended_legacy.txt
python -m pip install numpy==1.21.5
python -m pip install pytorch-lightning==1.5.9
echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: Install Python dependencies
- script: | - script: |
python setup.py develop python setup.py develop
echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: Install NNI displayName: Install NNI
# Need del later
- script: |
set -e
python test/vso_tools/interim_patch.py
displayName: Torch utils tensorboard interim patch
- script: | - script: |
cd test cd test
python nni_test/nnitest/run_tests.py --config config/pr_tests.yml python nni_test/nnitest/run_tests.py --config config/pr_tests.yml
...@@ -308,165 +156,60 @@ stages: ...@@ -308,165 +156,60 @@ stages:
displayName: Python unit test displayName: Python unit test
- script: | - script: |
set -e yarn --cwd ts/nni_manager test
cd ts/nni_manager
yarn test
displayName: TypeScript unit test displayName: TypeScript unit test
- job: macos - job: windows
pool: pool:
vmImage: macOS-latest vmImage: windows-latest
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
timeoutInMinutes: 90 # macos test need extra time
steps: steps:
- task: UsePythonVersion@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 3.9 platform: windows
displayName: Configure Python version
- task: NodeTool@0
inputs:
versionSpec: 16.3.0
displayName: Configure Node.js version
- script: |
brew install swig@3
rm -f /usr/local/bin/swig
ln -s /usr/local/opt/swig\@3/bin/swig /usr/local/bin/swig
displayName: Install brew packages
- task: Cache@2
inputs:
key: 'python | "$(Agent.OS)" | dependencies/*.txt'
restoreKeys: |
python | "$(Agent.OS)"
python
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | ts/**/yarn.lock, !**/node_modules/**'
restoreKeys: |
yarn | "$(Agent.OS)"
path: $(YARN_CACHE_FOLDER)
displayName: Cache yarn packages
- script: |
set -e
python -m pip install -U -r dependencies/setup.txt
python -m pip install -r dependencies/develop.txt
echo "##vso[task.setvariable variable=PATH]${PATH}:${HOME}/.local/bin"
displayName: Install Python tools
- script: | - script: |
python setup.py develop python setup.py develop --no-user
displayName: Install NNI displayName: Install NNI
- script: |
set -e
export CI=true
(cd ts/nni_manager && yarn test --exclude test/core/nnimanager.test.ts)
displayName: TypeScript unit test
- script: |
set -e
python -m pip install -r dependencies/recommended.txt
python -m pip install -e .[SMAC,BOHB,PPOTuner,DNGO]
displayName: Install extra dependencies
# Need del later
- script: |
set -e
python test/vso_tools/interim_patch.py
displayName: Torch utils tensorboard interim patch
- script: | - script: |
cd test cd test
python -m pytest ut python -m pytest ut
displayName: Python unit test displayName: Python unit test
- script: |
yarn --cwd ts/nni_manager test
displayName: TypeScript unit test
- script: | - script: |
cd test cd test
python nni_test/nnitest/run_tests.py --config config/pr_tests.yml python nni_test/nnitest/run_tests.py --config config/pr_tests.yml
displayName: Simple integration test displayName: Simple integration test
- job: windows - job: macos
pool: pool:
vmImage: windows-latest vmImage: macOS-latest
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
timeoutInMinutes: 120 # windows test need extra time
steps: steps:
- task: UsePythonVersion@0 - template: templates/install-dependencies.yml
inputs: parameters:
versionSpec: 3.9 platform: macos
displayName: Configure Python version
- task: NodeTool@0
inputs:
versionSpec: 16.3.0
displayName: Configure Node.js version
- task: Cache@2
inputs:
key: 'python | "$(Agent.OS)" | dependencies/*.txt'
restoreKeys: |
python | "$(Agent.OS)"
python
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | ts/**/yarn.lock, !**/node_modules/**'
restoreKeys: |
yarn | "$(Agent.OS)"
path: $(YARN_CACHE_FOLDER)
displayName: Cache yarn packages
- script: |
set -e
python -m pip install -U -r dependencies/setup.txt
python -m pip install -r dependencies/develop.txt
displayName: Install Python tools
- script: | - script: |
python setup.py develop --no-user python setup.py develop
echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
displayName: Install NNI displayName: Install NNI
- script: | - script: |
python -m pip install -r dependencies/recommended.txt CI=true yarn --cwd ts/nni_manager test --exclude test/core/nnimanager.test.ts
python -m pip install -e .[DNGO] displayName: TypeScript unit test
displayName: Install extra dependencies
# Need del later
- script: |
set -e
python test/vso_tools/interim_patch.py
displayName: Torch utils tensorboard interim patch
- script: | - script: |
cd test cd test
python -m pytest ut python -m pytest ut
displayName: Python unit test displayName: Python unit test
- script: |
cd ts/nni_manager
yarn test
displayName: TypeScript unit test
- script: | - script: |
cd test cd test
python nni_test/nnitest/run_tests.py --config config/pr_tests.yml python nni_test/nnitest/run_tests.py --config config/pr_tests.yml
displayName: Simple integration test displayName: Simple integration test
trigger:
branches:
exclude: [ l10n_master ]
parameters:
- name: platform
type: string
steps:
- template: config-version.yml
parameters:
platform: ${{ parameters.platform }}
- script: |
echo "##vso[task.setvariable variable=PLATFORM]${{ parameters.platform }}"
python test/vso_tools/pip_use_prefix.py python-packages
displayName: Prepare
- script: |
cp dependencies/recommended_legacy.txt dependencies/recommended.txt
displayName: (legacy) Activate legacy dependencies
condition: and(succeeded(), contains('${{ parameters.platform }}', 'legacy'))
- script: |
set -e
echo '===== develop ====='
./pip-install -r dependencies/develop.txt
echo '===== required ====='
./pip-install -r dependencies/required.txt
echo '===== required extra ====='
./pip-install -r dependencies/required_extra.txt
echo '===== recommended ====='
./pip-install -r dependencies/recommended.txt
echo '===== fix shebang ====='
python test/vso_tools/fix_shebang.py python-packages/bin
displayName: (POSIX) Install Python packages
condition: and(succeeded(), not(contains('${{ parameters.platform }}', 'windows')))
# FIXME: It does not stop on failure. Tried "ErrorActionPreference" with no luck.
- powershell: |
echo '===== develop ====='
./pip-install -r dependencies/develop.txt
echo '===== required ====='
./pip-install -r dependencies/required.txt
echo '===== required extra ====='
./pip-install -r dependencies/required_extra.txt
echo '===== recommended ====='
./pip-install -r dependencies/recommended.txt
displayName: (Windows) Install Python packages
condition: and(succeeded(), contains('${{ parameters.platform }}', 'windows'))
# FIXME:
# numpy version may change several times during installation, and it has an ABI change in recent versions.
# We must make sure ConfigSpaceNNI is built against correct numpy version, or it will fail on import.
- script: |
python -m pip uninstall -y ConfigSpaceNNI
./pip-install --no-cache-dir ConfigSpaceNNI
displayName: (Ubuntu) Rebuild ConfigSpaceNNI
condition: and(succeeded(), contains('${{ parameters.platform }}', 'ubuntu'))
- script: |
yarn --cwd ts/nni_manager install
displayName: Install NNI Manager dependencies
- script: |
yarn --cwd ts/webui install
displayName: Install Web UI dependencies
- script: |
python test/vso_tools/pack_dependencies.py $(Build.ArtifactStagingDirectory)
displayName: Create cache archive
- task: UniversalPackages@0
inputs:
command: publish
vstsFeedPublish: NNIOpenSource/dependencies
vstsFeedPackagePublish: dependencies-${{ parameters.platform }}
displayName: Upload cache archive
parameters:
- name: platform
type: string
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: 3.9
displayName: (latest) Configure Python version
condition: and(succeeded(), not(contains('${{ parameters.platform }}', 'legacy')))
- task: UsePythonVersion@0
inputs:
versionSpec: 3.7
displayName: (legacy) Configure Python version
condition: and(succeeded(), contains('${{ parameters.platform }}', 'legacy'))
- task: NodeTool@0
inputs:
versionSpec: 16.3.0
displayName: Configure Node.js version
- script: |
python -m pip install pip==21.3.1 setuptools==60.5.0 wheel==0.37.1
displayName: Install PyPA tools
parameters:
- name: platform
type: string
steps:
- template: config-version.yml
parameters:
platform: ${{ parameters.platform }}
- script: |
set -e
sudo apt-get install -y swig3.0
sudo rm /usr/bin/swig
sudo ln -s swig3.0 /usr/bin/swig
displayName: (Ubuntu) Downgrade swig
condition: and(succeeded(), contains('${{ parameters.platform }}', 'ubuntu'))
- script: |
set -e
brew install 'swig@3'
rm /usr/local/bin/swig
ln -s '/usr/local/opt/swig@3/bin/swig' /usr/local/bin/swig
displayName: (macOS) Downgrade swig
condition: and(succeeded(), contains('${{ parameters.platform }}', 'macos'))
- task: UniversalPackages@0
inputs:
vstsFeed: NNIOpenSource/dependencies
vstsFeedPackage: dependencies-${{ parameters.platform }}
vstsPackageVersion: "*"
displayName: Download cache
- script: |
python test/vso_tools/unpack_dependencies.py
displayName: Unpack cache
- script: |
mv dependencies/recommended_legacy.txt dependencies/recommended.txt
displayName: (legacy) Activate legacy dependencies
condition: and(succeeded(), contains('${{ parameters.platform }}', 'legacy'))
- script: |
echo '===== develop ====='
python -m pip install -r dependencies/develop.txt
echo '===== required ====='
python -m pip install -r dependencies/required.txt
echo '===== required extra ====='
python -m pip install -r dependencies/required_extra.txt
echo '===== recommended ====='
python -m pip install -r dependencies/recommended.txt
displayName: Install Python dependencies
# TODO: Delete this after upgrading to PyTorch 1.11.
- script: |
python test/vso_tools/interim_patch.py
displayName: Torch utils tensorboard interim patch
"""
Change "#!" line to "#!/usr/bin/env python" for all files in directory sys.argv[1].
"""
from pathlib import Path
import sys
if sys.platform == 'win32':
exit()
for file in Path(sys.argv[1]).iterdir():
try:
text = file.read_text()
assert text.startswith('#!'), 'no shebang'
shebang, content = text.split('\n', 1)
assert 'python' in shebang, 'not python script'
file.write_text('#!/usr/bin/env python\n' + content)
except Exception as e:
print(f'Skip {file}: {repr(e)}')
"""
Create an archive in sys.argv[1], containing python-packages and node_modules.
Use unpack_dependencies.py to extract the archive.
"""
import json
import os
from pathlib import Path
import shutil
import site
import sys
from zipfile import ZIP_DEFLATED, ZipFile
def main() -> None:
cache = Path('cache')
cache.mkdir()
shutil.move('python-packages', 'cache/python-dependencies')
shutil.move('ts/nni_manager/node_modules', 'cache/nni-manager-dependencies')
shutil.move('ts/webui/node_modules', 'cache/webui-dependencies')
archive = ZipFile('cache.zip', 'w', ZIP_DEFLATED, compresslevel=9)
symlinks = {}
empty_dirs = set()
for file in sorted(cache.rglob('*')):
if file.parent.parent == cache or file.parent.name == 'site-packages':
print('Compress', file, flush=True)
if file.is_symlink():
symlinks[str(file)] = os.readlink(file) # file.readlink() was added in Python 3.9
continue
if file.is_dir():
empty_dirs.add(str(file))
else:
archive.write(file)
empty_dirs.discard(str(file.parent))
archive.writestr('symlinks.json', json.dumps(symlinks, indent=4))
archive.writestr('directories.json', json.dumps(list(empty_dirs), indent=4))
archive.close()
assert Path(sys.argv[1]).is_dir()
shutil.move('cache.zip', sys.argv[1])
if __name__ == '__main__':
main()
"""
0. Create a directory whose name is sys.argv[1].
1. Create a "pip-install" script that uses this directory as prefix.
2. Set PYTHONPATH to use this prefix, via VSO variable.
"""
import os
from pathlib import Path
import sys
import typing
prefix = Path(sys.argv[1])
prefix.mkdir(parents=True, exist_ok=True)
prefix = prefix.resolve()
if sys.platform == 'win32':
# Do not use CMD script. It will magically stop pipeline step.
script = f'python -m pip install --prefix {prefix} --no-compile --prefer-binary $args'
Path('pip-install.ps1').write_text(script + '\n')
else:
script = f'python -m pip install --prefix {prefix} --no-compile --prefer-binary "$@"'
Path('pip-install').write_text('#!/bin/bash\n' + script + '\n')
os.chmod('pip-install', 0o775)
if sys.platform == 'win32':
site_path = prefix / 'Lib/site-packages'
else:
version = f'{sys.version_info.major}.{sys.version_info.minor}'
site_path = prefix / f'lib/python{version}/site-packages'
paths = [
Path(typing.__file__).parent, # With PYTHONPATH, the backport version of typing will mask stdlib version.
site_path,
os.getenv('PYTHONPATH'),
]
path = os.pathsep.join(str(p) for p in paths if p)
print('PYTHONPATH:', path)
print('##vso[task.setvariable variable=PYTHONPATH]' + path)
"""
Extract an archive created by pack_dependencies.py.
"""
from __future__ import annotations
import json
import os
from pathlib import Path
import shutil
import site
import sys
from zipfile import ZipFile
def main() -> None:
if sys.platform == 'win32':
# Strangely user site is not enabled on Windows.
prefix = Path(sys.prefix)
else:
prefix = Path(site.getuserbase())
print('Extract Python packages to', prefix)
print('All Python paths:')
print('\n'.join(sys.path), flush=True)
extract_all(ZipFile('cache.zip'))
empty_dirs = json.loads(Path('directories.json').read_text())
symlinks = json.loads(Path('symlinks.json').read_text())
for dir_ in empty_dirs:
Path(dir_).mkdir(parents=True, exist_ok=True)
for link, target in symlinks.items():
Path(link).symlink_to(target) # hopefully nobody uses symlink on windows
move_or_merge(Path('cache/python-dependencies'), prefix)
shutil.move('cache/nni-manager-dependencies', 'ts/nni_manager/node_modules')
shutil.move('cache/webui-dependencies', 'ts/webui/node_modules')
def extract_all(zf: ZipFile) -> None:
# fix a bug in ZipFile.extractall()
# see https://stackoverflow.com/questions/39296101
for info in zf.infolist():
path = zf.extract(info)
if info.external_attr > 0xffff:
os.chmod(path, info.external_attr >> 16)
def move_or_merge(src: Path | str, dst: Path | str) -> None:
if not dst.exists():
shutil.move(src, dst)
elif dst.is_dir():
for file in src.iterdir():
move_or_merge(file, dst / file.name)
else:
print('Skip', dst)
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment