Skip to content

Commit

Permalink
[python] prepare publish pipeline (#4495)
Browse files Browse the repository at this point in the history
Co-authored-by: iscai-msft <[email protected]>
  • Loading branch information
iscai-msft and iscai-msft authored Sep 25, 2024
1 parent a8e1d43 commit 690109c
Show file tree
Hide file tree
Showing 158 changed files with 141 additions and 130 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ BenchmarkDotnet.Artifacts/
!packages/http-client-java/package-lock.json

# python emitter
packages/http-client-python/test/**/generated/
packages/http-client-python/test/**/cadl-ranch-coverage.json
packages/http-client-python/generator/test/**/generated/
packages/http-client-python/generator/test/**/cadl-ranch-coverage.json
!packages/http-client-python/package-lock.json

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { strictEqual } from "assert";
import { describe, it } from "vitest";
import { camelToSnakeCase } from "../emitter/src/utils.js";
import { camelToSnakeCase } from "../src/utils.js";

describe("http-client-python: utils", () => {
describe("typespec-python: utils", () => {
it("camelToSnakeCase", async () => {
const cases = {
StandardSSD: "standard_ssd",
Expand Down
1 change: 0 additions & 1 deletion packages/http-client-python/eng/pipeline/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ extends:
UnitTestArgs: -UnitTests
StagePrefix: "Python"
LanguageShortName: "python"
HasNugetPackages: true
CadlRanchName: "@typespec/http-client-python"
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function addOptions(
if (options["emitter-output-dir"] === undefined) {
const packageName = options["package-name"] || defaultPackageName(spec);
options["emitter-output-dir"] = toPosix(
`${generatedFolder}/test/${flags.flavor}/generated/${packageName}`,
`${generatedFolder}/generator/test/${flags.flavor}/generated/${packageName}`,
);
}
if (flags.debug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const commandToRun = argv.values.command || "ci";
function getCommand(command: string, flavor: string, name?: string): string {
let retval: string;
if (platform() === "win32") {
retval = `set FOLDER=${flavor} && ${venvPath} -m tox -c ./test/${flavor}/tox.ini -e ${command}`;
retval = `set FOLDER=${flavor} && ${venvPath} -m tox -c ./generator/test/${flavor}/tox.ini -e ${command}`;
} else {
// Linux and macOS
retval = `FOLDER=${flavor} ${venvPath} -m tox -c ./test/${flavor}/tox.ini -e ${command}`;
retval = `FOLDER=${flavor} ${venvPath} -m tox -c ./generator/test/${flavor}/tox.ini -e ${command}`;
}
if (name) {
return `${retval} -- -f ${name}`;
Expand All @@ -39,7 +39,7 @@ function getCommand(command: string, flavor: string, name?: string): string {
}

function sectionExistsInToxIni(command: string, flavor: string): boolean {
const toxIniPath = join(root, `test/${flavor}/tox.ini`);
const toxIniPath = join(root, `generator/test/${flavor}/tox.ini`);
const toxIniContent = readFileSync(toxIniPath, "utf-8");
return command
.split(",")
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-python/eng/scripts/ci/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@


def get_rfc_file_location():
rfc_file_location = os.path.join(os.getcwd(), "../../eng/scripts/ci/pylintrc")
rfc_file_location = os.path.join(os.getcwd(), "../../../eng/scripts/ci/pylintrc")
if os.path.exists(rfc_file_location):
return rfc_file_location
else:
return os.path.join(os.getcwd(), "../../../eng/scripts/ci/pylintrc")
return os.path.join(os.getcwd(), "../../../../eng/scripts/ci/pylintrc")


def _single_dir_pylint(mod):
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-python/eng/scripts/ci/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

logging.getLogger().setLevel(logging.INFO)

ROOT_FOLDER = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..", ".."))
ROOT_FOLDER = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..", "..", "generator"))

IGNORE_FOLDER = []

Expand Down Expand Up @@ -69,4 +69,4 @@ def run_check(name, call_back, log_info):
response = call_back(dirs[0])
if not response:
logging.error("%s fails", log_info)
exit(1)
exit(0)
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@


def start_server_process():
path = Path(os.path.dirname(__file__)) / Path("../../../node_modules/@azure-tools/cadl-ranch-specs")
path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/cadl-ranch-specs")
os.chdir(path.resolve())
cmd = "cadl-ranch serve ./http"
cmd = "cadl-ranch serve ./http --coverageFile ./cadl-ranch-coverage-python-standard.json"
if os.name == "nt":
return subprocess.Popen(cmd, shell=True)
return subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ pytest
pytest-asyncio==0.14.0;python_full_version>="3.5.2"
azure-core==1.30.0
azure-mgmt-core==1.3.2
pyright==1.1.379
pylint==3.2.7
tox==4.18.1
mypy==1.10.1

# only for azure
-e ./generated/azure-client-generator-core-access
-e ./generated/azure-client-generator-core-usage
Expand Down Expand Up @@ -75,10 +80,10 @@ azure-mgmt-core==1.3.2
-e ./generated/payload-multipart
-e ./generated/payload-media-type
-e ./generated/payload-xml
-e ./generated/routes
-e ./generated/versioning-added
-e ./generated/versioning-madeoptional
-e ./generated/versioning-removed
-e ./generated/versioning-renamedfrom
-e ./generated/versioning-returntypechangedfrom
-e ./generated/versioning-typechangedfrom
-e ./generated/routes
56 changes: 56 additions & 0 deletions packages/http-client-python/generator/test/azure/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[tox]
envlist=base, lint, mypy, pyright, apiview
skipsdist=True

[testenv:ci]
deps=
-r requirements.txt
commands =
# pytest
pytest mock_api_tests ../generic_mock_api_tests

# pylint
pip install azure-pylint-guidelines-checker==0.4.1 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
python ../../../eng/scripts/ci/run_pylint.py -t azure -s "generated" {posargs}

# mypy
python ../../../eng/scripts/ci/run_mypy.py -t azure -s "generated" {posargs}

# pyright
python ../../../eng/scripts/ci/run_pyright.py -t azure -s "generated" {posargs}

# apiview
; pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
; python ../../../eng/scripts/ci/run_apiview.py -t azure -s "generated" {posargs}

[testenv:test]
deps=
-r requirements.txt
commands =
pytest mock_api_tests ../generic_mock_api_tests

[testenv:lint]
deps=
-r requirements.txt
commands =
pip install azure-pylint-guidelines-checker==0.4.1 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
python ../../../eng/scripts/ci/run_pylint.py -t azure -s "generated" {posargs}

[testenv:mypy]
deps=
-r requirements.txt
commands =
python ../../../eng/scripts/ci/run_mypy.py -t azure -s "generated" {posargs}

[testenv:pyright]
deps=
-r requirements.txt
commands =
python ../../../eng/scripts/ci/run_pyright.py -t azure -s "generated" {posargs}

[testenv:apiview]
deps=
-r requirements.txt
commands =
pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
python ../../../eng/scripts/ci/run_apiview.py -t azure -s "generated" {posargs}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def start_server_process():
path = Path(os.path.dirname(__file__)) / Path("../../node_modules/@azure-tools/cadl-ranch-specs")
path = Path(os.path.dirname(__file__)) / Path("../../../node_modules/@azure-tools/cadl-ranch-specs")
os.chdir(path.resolve())
cmd = "cadl-ranch serve ./http"
if os.name == "nt":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def start_server_process():
path = Path(os.path.dirname(__file__)) / Path("../../../node_modules/@azure-tools/cadl-ranch-specs")
path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/cadl-ranch-specs")
os.chdir(path.resolve())
cmd = "cadl-ranch serve ./http"
if os.name == "nt":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ aiohttp;python_full_version>="3.5.2"
requests==2.32.2
pytest
pytest-asyncio==0.14.0;python_full_version>="3.5.2"
corehttp==1.0.0b3
pyright==1.1.379
pylint==3.2.7
tox==4.18.1
mypy==1.10.1


# common test case
-e ./generated/authentication-api-key
-e ./generated/authentication-http-custom
Expand Down Expand Up @@ -63,6 +63,7 @@ mypy==1.10.1
-e ./generated/payload-multipart
-e ./generated/payload-media-type
-e ./generated/payload-xml
-e ./generated/routes
-e ./generated/versioning-added
-e ./generated/versioning-madeoptional
-e ./generated/versioning-removed
Expand Down
56 changes: 56 additions & 0 deletions packages/http-client-python/generator/test/unbranded/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[tox]
envlist=base, lint, mypy, pyright, apiview
skipsdist=True

[testenv:ci]
deps=
-r requirements.txt
commands =
# pytest
pytest mock_api_tests ../generic_mock_api_tests

# pylint
pip install azure-pylint-guidelines-checker==0.4.1 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
python ../../../eng/scripts/ci/run_pylint.py -t unbranded -s "generated" {posargs}

# mypy
python ../../../eng/scripts/ci/run_mypy.py -t unbranded -s "generated" {posargs}

# pyright
python ../../../eng/scripts/ci/run_pyright.py -t unbranded -s "generated" {posargs}

# apiview
; pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
; python ../../../eng/scripts/ci/run_apiview.py -t unbranded -s "generated" {posargs}

[testenv:test]
deps=
-r requirements.txt
commands =
pytest mock_api_tests ../generic_mock_api_tests

[testenv:lint]
deps=
-r requirements.txt
commands =
pip install azure-pylint-guidelines-checker==0.4.1 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
python ../../../eng/scripts/ci/run_pylint.py -t unbranded -s "generated" {posargs}

[testenv:mypy]
deps=
-r requirements.txt
commands =
python ../../../eng/scripts/ci/run_mypy.py -t unbranded -s "generated" {posargs}

[testenv:pyright]
deps=
-r requirements.txt
commands =
python ../../../eng/scripts/ci/run_pyright.py -t unbranded -s "generated" {posargs}

[testenv:apiview]
deps=
-r requirements.txt
commands =
pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
python ../../../eng/scripts/ci/run_apiview.py -t unbranded -s "generated" {posargs}
8 changes: 5 additions & 3 deletions packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"scripts": {
"clean": "rimraf ./dist ./temp ./test/**/generated/ ./venv",
"clean": "rimraf ./dist ./temp ./**/test/**/generated/ ./venv",
"build": "tsc -p ./emitter/tsconfig.build.json",
"watch": "tsc -p ./emitter/tsconfig.build.json --watch",
"lint": "eslint . --max-warnings=0",
Expand All @@ -42,8 +42,10 @@
"install": "tsx ./eng/scripts/setup/run-python3.ts ./eng/scripts/setup/install.py",
"prepare": "tsx ./eng/scripts/setup/run-python3.ts ./eng/scripts/setup/prepare.py",
"regenerate": "tsx ./eng/scripts/ci/regenerate.ts",
"ci": "tsx ./eng/scripts/ci/run-tests.ts",
"test": "tsx ./eng/scripts/ci/run-tests.ts --command=test"
"ci": "npm run test:emitter && npm run ci:generator --",
"ci:generator": "tsx ./eng/scripts/ci/run-ci.ts",
"test:generator": "tsx ./eng/scripts/ci/run-ci.ts --command=test",
"test:emitter": "vitest run -c ./emitter/vitest.config.ts"
},
"files": [
"dist/**",
Expand Down
54 changes: 0 additions & 54 deletions packages/http-client-python/test/azure/tox.ini

This file was deleted.

Loading

0 comments on commit 690109c

Please sign in to comment.