Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions eng/emitters/pipelines/templates/jobs/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ parameters:
type: string
default: ""

- name: PythonVersion
type: string
default: "3.12"

jobs:
- job: Build_${{ parameters.Os }}_${{ split(parameters.NodeVersion, '.')[0] }}
${{ if eq(parameters.Os, 'linux') }}:
Expand All @@ -73,6 +77,7 @@ jobs:
LanguageShortName: ${{ parameters.LanguageShortName }}
PackagePath: ${{ parameters.PackagePath }}
NodeVersion: ${{ parameters.NodeVersion }}
PythonVersion: ${{ parameters.PythonVersion }}
${{ if parameters.EmitArtifacts }}:
templateContext:
outputs:
Expand Down
5 changes: 5 additions & 0 deletions eng/emitters/pipelines/templates/jobs/test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ parameters:
type: boolean
default: true

- name: PythonVersion
type: string
default: "3.12"

jobs:
- job: Test_${{ parameters.Os }}_${{ split(parameters.NodeVersion, '.')[0] }}
${{ if eq(parameters.Os, 'linux') }}:
Expand Down Expand Up @@ -78,6 +82,7 @@ jobs:
EmitArtifacts: ${{ parameters.EmitArtifacts }}
CadlRanchName: ${{ parameters.CadlRanchName }}
EnableCadlRanchReport: ${{ parameters.EnableCadlRanchReport }}
PythonVersion: ${{ parameters.PythonVersion }}
${{ if parameters.EmitArtifacts }}:
templateContext:
outputs:
Expand Down
14 changes: 14 additions & 0 deletions eng/emitters/pipelines/templates/stages/emitter-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ parameters:
type: boolean
default: true

- name: PythonVersion
type: string
default: "3.12"

stages:
# Build stage
# Responsible for building the autorest generator and typespec emitter packages
Expand Down Expand Up @@ -104,6 +108,7 @@ stages:
NodeVersion: 20.x
Os: linux
EmitArtifacts: true # Emit artifacts only for the first job
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/build-job.yml
parameters:
BuildPrereleaseVersion: ${{ parameters.BuildPrereleaseVersion }}
Expand All @@ -115,6 +120,7 @@ stages:
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: 22.x
Os: linux
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/build-job.yml
parameters:
BuildPrereleaseVersion: ${{ parameters.BuildPrereleaseVersion }}
Expand All @@ -126,6 +132,7 @@ stages:
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: 20.x
Os: windows
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/build-job.yml
parameters:
BuildPrereleaseVersion: ${{ parameters.BuildPrereleaseVersion }}
Expand All @@ -137,6 +144,7 @@ stages:
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: 22.x
Os: windows
PythonVersion: ${{ parameters.PythonVersion }}
- ${{ if eq(parameters.Publish, 'none') }}:
- template: /eng/emitters/pipelines/templates/jobs/detect-api-changes.yml
parameters:
Expand Down Expand Up @@ -175,6 +183,7 @@ stages:
EmitArtifacts: true # Emit artifacts only for the first job
CadlRanchName: ${{ parameters.CadlRanchName }} # only needed for first job
EnableCadlRanchReport: ${{ parameters.EnableCadlRanchReport }}
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Expand All @@ -184,6 +193,7 @@ stages:
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 22.x
Os: linux
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Expand All @@ -193,6 +203,7 @@ stages:
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 20.x
Os: windows
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Expand All @@ -202,6 +213,7 @@ stages:
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 22.x
Os: windows
PythonVersion: ${{ parameters.PythonVersion }}

# Regen Test stage
# Responsible for running any regen tests needed to validate no manual changes were done.
Expand All @@ -225,6 +237,7 @@ stages:
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
Os: windows
TestMatrix: ${{ parameters.TestMatrix }}
PythonVersion: ${{ parameters.PythonVersion }}
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Expand All @@ -233,6 +246,7 @@ stages:
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
Os: linux
TestMatrix: ${{ parameters.TestMatrix }}
PythonVersion: ${{ parameters.PythonVersion }}

# Publish stage
# Responsible for publishing the packages in `build_artifacts/packages` and producing `emitter-package-lock.json`
Expand Down
9 changes: 9 additions & 0 deletions eng/emitters/pipelines/templates/steps/build-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ parameters:
- name: LanguageShortName
type: string

- name: PythonVersion
type: string
default: "3.12"

steps:
- ${{ if notIn(parameters.Publish, 'none', 'internal', 'public') }}:
- script: |
Expand All @@ -61,6 +65,11 @@ steps:
inputs:
versionSpec: ${{ parameters.NodeVersion }}

- task: UsePythonVersion@0
displayName: "Use Python ${{ parameters.PythonVersion }}"
inputs:
versionSpec: ${{ parameters.PythonVersion }}

- ${{ parameters.AdditionalInitializeSteps }}

- task: PowerShell@2
Expand Down
9 changes: 9 additions & 0 deletions eng/emitters/pipelines/templates/steps/test-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ parameters:
type: boolean
default: true

- name: PythonVersion
type: string
default: "3.12"

steps:
- checkout: self

Expand All @@ -53,6 +57,11 @@ steps:
inputs:
versionSpec: ${{ parameters.NodeVersion }}

- task: UsePythonVersion@0
displayName: "Use Python ${{ parameters.PythonVersion }}"
inputs:
versionSpec: ${{ parameters.PythonVersion }}

- ${{ parameters.AdditionalInitializeSteps }}

- task: PowerShell@2
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/emitter/src/run-python3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { patchPythonPath } from "./system-requirements.js";

export async function runPython3(...args: string[]) {
const command = await patchPythonPath(["python", ...args], {
version: ">=3.8",
version: ">=3.9",
Copy link
Member

@lmazuel lmazuel Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, using 3.8+ to generate and generating 3.8+ are two different things. For instance, we could technically have a generator written in Python 2.7, that generates Python 3.12 code :). In other words, the fact that our generator is written in Python is an implementation detail.

That being said, it's fair to ask people to have 3.8+, because it allows us as well to write the generator with more recent syntax.

environmentVariable: "AUTOREST_PYTHON_EXE",
});
cp.execSync(command.join(" "), {
Expand Down
1 change: 1 addition & 0 deletions packages/http-client-python/eng/pipeline/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ extends:
LanguageShortName: "python"
CadlRanchName: "@typespec/http-client-python"
EnableCadlRanchReport: false
PythonVersion: "3.9"
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ stages:
Condition: ${{ parameters.Condition }}
DependsOn: ${{ parameters.DependsOn }}
LanguageShortName: "python"
PythonVersion: "3.9"
12 changes: 7 additions & 5 deletions packages/http-client-python/eng/scripts/Build-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@ New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null
Write-Host "Getting existing version"
$emitterVersion = node -p -e "require('$packageRoot/package.json').version"

# build the generator jar
# build the generator
Push-Location "$packageRoot/generator"

# build and pack the emitter with the generator jar
# build and pack the emitter with the generator
Push-Location "$packageRoot"
try {
Write-Host "Working in $PWD"

Invoke-LoggedCommand "npm run build" -GroupOutput

# after python 3.13 fix pylint issue, will reopen the check
# Write-Host "run lint check for pygen"
# Invoke-LoggedCommand "npm run lint:py" -GroupOutput
# Only run lint:py on Linux OS
if ($IsLinux) {
Write-Host "run lint check for pygen"
Invoke-LoggedCommand "npm run lint:py" -GroupOutput
}

# pack the emitter
Invoke-LoggedCommand "npm pack"
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/format.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { runCommand } from "./utils.js";

runCommand("black . --config ./eng/scripts/ci/pyproject.toml", "black");
runCommand("black", ["generator/", "eng/", "--config", "./eng/scripts/ci/pyproject.toml"]);
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# global configurations
[mypy]
python_version = 3.8
python_version = 3.9


# module level configurations
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MASTER]
py-version=3.8
py-version=3.9
ignore-patterns=test_*,conftest,setup
reports=no

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"reportUnnecessaryCast": "warning",
"reportTypeCommentUsage": true,
"reportMissingImports": false,
"pythonVersion": "3.8"
"pythonVersion": "3.9"
}
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _single_dir_pylint(mod):
"--load-plugins=pylint_guidelines_checker",
"--output-format=parseable",
"--recursive=y",
"--py-version=3.8",
"--py-version=3.9",
str(inner_class.absolute()),
]
)
Expand Down
8 changes: 5 additions & 3 deletions packages/http-client-python/eng/scripts/ci/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ const argv = parseArgs({
export async function executeCommand(command: string, args: string[]) {
const execFileAsync = promisify(execFile);
try {
await execFileAsync(command, args);
await execFileAsync(command, args, { shell: true });
console.log(chalk.green(`${command} passed`));
} catch (err) {
console.error(chalk.red(`Error executing ${command}: ${err}`));
} catch (err: any) {
console.error(chalk.red(`Error executing ${command}`));
if (err.stdout) console.error(chalk.yellow("STDOUT:"), err.stdout);
if (err.stderr) console.error(chalk.yellow("STDERR:"), err.stderr);
process.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# --------------------------------------------------------------------------
import sys

if not sys.version_info >= (3, 8, 0):
raise Exception("Autorest for Python extension requires Python 3.8 at least")
if not sys.version_info >= (3, 9, 0):
raise Exception("Autorest for Python extension requires Python 3.9 at least")

try:
import pip
except (ImportError, ModuleNotFoundError):
raise Exception("Your Python installation doesn't have pip available")


# Now we have pip and Py >= 3.8, go to work
# Now we have pip and Py >= 3.9, go to work

from pathlib import Path

Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-python/eng/scripts/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# --------------------------------------------------------------------------
import sys

if not sys.version_info >= (3, 8, 0):
if not sys.version_info >= (3, 9, 0):
raise Warning(
"Autorest for Python extension requires Python 3.8 at least. We will run your code with Pyodide since your Python version isn't adequate."
"Autorest for Python extension requires Python 3.9 at least. We will run your code with Pyodide since your Python version isn't adequate."
)

try:
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-python/eng/scripts/setup/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import os
import argparse

if not sys.version_info >= (3, 8, 0):
if not sys.version_info >= (3, 9, 0):
raise Warning(
"Autorest for Python extension requires Python 3.8 at least. We will run your code with Pyodide since your Python version isn't adequate."
"Autorest for Python extension requires Python 3.9 at least. We will run your code with Pyodide since your Python version isn't adequate."
)

from pathlib import Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def packaging_files_config(self) -> Optional[Dict[str, Any]]:
def package_version(self) -> Optional[str]:
return str(self.options.get("package-version", ""))


@property
def header_text(self) -> Optional[str]:
return self.options.get("header-text")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"MIT License\n"
"\n"
"Permission is hereby granted, free of charge, to any person obtaining a copy\n"
"of this software and associated documentation files (the \"Software\"), to deal\n"
'of this software and associated documentation files (the "Software"), to deal\n'
"in the Software without restriction, including without limitation the rights\n"
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
"copies of the Software, and to permit persons to whom the Software is\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,12 @@ def merge(self, file_import: "FileImport") -> None:
self.type_definitions.update(file_import.type_definitions)

def add_mutable_mapping_import(self) -> None:
self.add_import("sys", ImportType.STDLIB)
self.add_submodule_import(
"typing",
"MutableMapping",
ImportType.BY_VERSION,
TypingSection.REGULAR,
None,
(((3, 9), "collections.abc", None),),
)
self.add_submodule_import("collections.abc", "MutableMapping", ImportType.STDLIB)

def define_mutable_mapping_type(self) -> None:
"""Helper function for defining the mutable mapping type"""
self.add_mutable_mapping_import()
self.define_mypy_type(
"JSON",
"MutableMapping[str, Any] # pylint: disable=unsubscriptable-object",
)
self.define_mypy_type("JSON", "MutableMapping[str, Any]")
self.add_submodule_import("typing", "Any", ImportType.STDLIB)

def to_dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,7 @@ def _extract_data_callback(self, builder: PagingOperationType) -> List[str]: #
return retval

def _get_next_callback(self, builder: PagingOperationType) -> List[str]:
retval = [
f"{'async ' if self.async_mode else ''}def get_next({builder.next_variable_name}=None):" # pylint: disable=line-too-long
]
retval = [f"{'async ' if self.async_mode else ''}def get_next({builder.next_variable_name}=None):"]
retval.append(f" _request = prepare_request({builder.next_variable_name})")
retval.append("")
retval.extend([f" {l}" for l in self.make_pipeline_call(builder)])
Expand Down
Loading
Loading