diff --git a/build/azure-pipeline.pre-release.yml b/build/azure-pipeline.pre-release.yml index e66b59dc3aab..56bed785588f 100644 --- a/build/azure-pipeline.pre-release.yml +++ b/build/azure-pipeline.pre-release.yml @@ -18,13 +18,6 @@ resources: ref: main endpoint: Monaco - - repository: python-environment-tools - type: github - name: microsoft/python-environment-tools - ref: main - endpoint: Monaco - - parameters: - name: publishExtension displayName: 🚀 Publish Extension @@ -38,11 +31,7 @@ extends: ghCreateTag: false standardizedVersioning: true l10nSourcePaths: ./src/client - sourceRepositoriesToScan: - include: - - repository: python-environment-tools - exclude: - - repository: translations + needsTools: true buildPlatforms: - name: Linux @@ -76,10 +65,6 @@ extends: vsceTarget: win32-x64 buildSteps: - - checkout: self - displayName: Checkout Python Extension - path: ./s - - task: NodeTool@0 inputs: versionSpec: '18.17.1' @@ -104,9 +89,6 @@ extends: - script: nox --session install_python_libs displayName: Install Jedi, get-pip, etc - # - script: python ./build/update_ext_version.py --for-publishing - # displayName: Update build number - - script: python ./build/update_package_file.py displayName: Update telemetry in package.json @@ -116,9 +98,12 @@ extends: - script: npx gulp prePublishBundle displayName: Build - - checkout: python-environment-tools + - script: nox --session azure_pet_checkout displayName: Checkout python-environment-tools - path: ./s/python-env-tools + env: + PYTHON_ENV_TOOLS_DEST: $(Build.SourcesDirectory) + PYTHON_ENV_TOOLS_REF: main + PYTHON_ENV_TOOLS_TEMP: $(Agent.TempDirectory) - script: nox --session azure_pet_build_before displayName: Enable cargo config for azure diff --git a/build/azure-pipeline.stable.yml b/build/azure-pipeline.stable.yml index 5feccd962d51..4cd0567ec8c1 100644 --- a/build/azure-pipeline.stable.yml +++ b/build/azure-pipeline.stable.yml @@ -14,12 +14,6 @@ resources: ref: main endpoint: Monaco - - repository: python-environment-tools - type: github - name: microsoft/python-environment-tools - ref: release/latest - endpoint: Monaco - parameters: - name: publishExtension displayName: 🚀 Publish Extension @@ -31,11 +25,7 @@ extends: parameters: publishExtension: ${{ parameters.publishExtension }} l10nSourcePaths: ./src/client - sourceRepositoriesToScan: - include: - - repository: python-environment-tools - exclude: - - repository: translations + needsTools: true buildPlatforms: - name: Linux @@ -69,10 +59,6 @@ extends: vsceTarget: win32-x64 buildSteps: - - checkout: self - displayName: Checkout Python Extension - path: ./s - - task: NodeTool@0 inputs: versionSpec: '18.17.1' @@ -106,9 +92,12 @@ extends: - script: npx gulp prePublishBundle displayName: Build - - checkout: python-environment-tools + - script: nox --session azure_pet_checkout displayName: Checkout python-environment-tools - path: ./s/python-env-tools + env: + PYTHON_ENV_TOOLS_DEST: $(Build.SourcesDirectory) + PYTHON_ENV_TOOLS_REF: release/2024.12 + PYTHON_ENV_TOOLS_TEMP: $(Agent.TempDirectory) - script: nox --session azure_pet_build_before displayName: Enable cargo config for azure diff --git a/noxfile.py b/noxfile.py index 8fe5842ee348..58ac6f1206aa 100644 --- a/noxfile.py +++ b/noxfile.py @@ -12,6 +12,21 @@ EXT_ROOT = pathlib.Path(__file__).parent +def delete_dir(path: pathlib.Path, ignore_errors=None): + attempt = 0 + known = [] + while attempt < 5: + try: + shutil.rmtree(os.fspath(path), ignore_errors=ignore_errors) + return + except PermissionError as pe: + if os.fspath(pe.filename) in known: + break + print(f"Changing permissions on {pe.filename}") + os.chmod(pe.filename, 0o666) + + shutil.rmtree(os.fspath(path)) + @nox.session() def install_python_libs(session: nox.Session): requirements = [ @@ -48,6 +63,45 @@ def install_python_libs(session: nox.Session): if pathlib.Path("./python_files/lib/temp").exists(): shutil.rmtree("./python_files/lib/temp") +@nox.session() +def azure_pet_checkout(session: nox.Session): + branch = os.getenv("PYTHON_ENV_TOOLS_REF", "main") + + # dest dir should be /python-env-tools + dest_dir = (pathlib.Path(os.getenv("PYTHON_ENV_TOOLS_DEST")) / "python-env-tools").resolve() + + # temp dir should be + temp_dir = (pathlib.Path(os.getenv("PYTHON_ENV_TOOLS_TEMP")) / "python-env-tools").resolve() + session.log(f"Cloning python-environment-tools to {temp_dir}") + temp_dir.mkdir(0o766, parents=True, exist_ok=True) + + try: + with session.cd(temp_dir): + session.run("git", "init", external=True) + session.run( + "git", + "remote", + "add", + "origin", + "https://github.com/microsoft/python-environment-tools", + external=True, + ) + session.run("git", "fetch", "origin", branch, external=True) + session.run( + "git", "checkout", "--force", "-B", branch, f"origin/{branch}", external=True + ) + delete_dir(temp_dir / ".git") + delete_dir(temp_dir / ".github") + delete_dir(temp_dir / ".vscode") + (temp_dir / "CODE_OF_CONDUCT.md").unlink() + shutil.move(os.fspath(temp_dir), os.fspath(dest_dir)) + except PermissionError as e: + print(f"Permission error: {e}") + if not dest_dir.exists(): + raise + finally: + delete_dir(temp_dir, ignore_errors=True) + @nox.session() def azure_pet_build_before(session: nox.Session): @@ -132,37 +186,19 @@ def native_build(session: nox.Session): vscode_ignore.write_text("\n".join(filtered_lines) + "\n", encoding="utf-8") -def delete_dir(path: pathlib.Path, ignore_errors=None): - attempt = 0 - known = [] - while attempt < 5: - try: - shutil.rmtree(os.fspath(path), ignore_errors=ignore_errors) - return - except PermissionError as pe: - if os.fspath(pe.filename) in known: - break - print(f"Changing permissions on {pe.filename}") - os.chmod(pe.filename, 0o666) - - shutil.rmtree(os.fspath(path)) - - @nox.session() def checkout_native(session: nox.Session): dest = (pathlib.Path.cwd() / "python-env-tools").resolve() if dest.exists(): shutil.rmtree(os.fspath(dest)) - tempdir = os.getenv("TEMP") or os.getenv("TMP") or "/tmp" - tempdir = pathlib.Path(tempdir) / str(uuid.uuid4()) / "python-env-tools" - tempdir.mkdir(0o666, parents=True) - - session.log(f"Temp dir: {tempdir}") + temp_dir = os.getenv("TEMP") or os.getenv("TMP") or "/tmp" + temp_dir = pathlib.Path(temp_dir) / str(uuid.uuid4()) / "python-env-tools" + temp_dir.mkdir(0o766, parents=True) - session.log(f"Cloning python-environment-tools to {tempdir}") + session.log(f"Cloning python-environment-tools to {temp_dir}") try: - with session.cd(tempdir): + with session.cd(temp_dir): session.run("git", "init", external=True) session.run( "git", @@ -176,17 +212,17 @@ def checkout_native(session: nox.Session): session.run( "git", "checkout", "--force", "-B", "main", "origin/main", external=True ) - delete_dir(tempdir / ".git") - delete_dir(tempdir / ".github") - delete_dir(tempdir / ".vscode") - (tempdir / "CODE_OF_CONDUCT.md").unlink() - shutil.move(os.fspath(tempdir), os.fspath(dest)) + delete_dir(temp_dir / ".git") + delete_dir(temp_dir / ".github") + delete_dir(temp_dir / ".vscode") + (temp_dir / "CODE_OF_CONDUCT.md").unlink() + shutil.move(os.fspath(temp_dir), os.fspath(dest)) except PermissionError as e: print(f"Permission error: {e}") if not dest.exists(): raise finally: - delete_dir(tempdir.parent, ignore_errors=True) + delete_dir(temp_dir.parent, ignore_errors=True) @nox.session()