Skip to content

Commit

Permalink
Merge branch 'main' into termsOfServiceUrlCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
skywing918 authored Sep 26, 2024
2 parents 2fe0c61 + 3fdc695 commit 8d3b21b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/pipeline/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extends:
parameters:
BuildPrereleaseVersion: true
UseTypeSpecNext: false
Publish: "internal"
Publish: "public"
PublishDependsOnTest: true
PackagePath: /packages/http-client-python
EmitterPackageJsonPath: packages/http-client-python/package.json
Expand Down
39 changes: 24 additions & 15 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@ import { dirname, join, relative, resolve } from "path";
import { fileURLToPath } from "url";
import { parseArgs, promisify } from "util";

// PARSE INPUT ARGUMENTS

const argv = parseArgs({
args: process.argv.slice(2),
options: {
flavor: { type: "string" },
name: { type: "string" },
debug: { type: "boolean" },
pluginDir: { type: "string" },
emitterName: { type: "string" },
generatedFolder: { type: "string" },
},
});

// Promisify the exec function
const exec = promisify(execCallback);

// Get the directory of the current file
const PLUGIN_DIR = resolve(fileURLToPath(import.meta.url), "../../../../");
const PLUGIN_DIR = argv.values.pluginDir
? resolve(argv.values.pluginDir)
: resolve(fileURLToPath(import.meta.url), "../../../../");
const CADL_RANCH_DIR = resolve(PLUGIN_DIR, "node_modules/@azure-tools/cadl-ranch-specs/http");
const GENERATED_FOLDER = argv.values.generatedFolder
? resolve(argv.values.generatedFolder)
: resolve(PLUGIN_DIR, "generator");

interface TspCommand {
outputDir: string;
command: string;
Expand Down Expand Up @@ -229,7 +249,7 @@ function addOptions(
if (options["emitter-output-dir"] === undefined) {
const packageName = options["package-name"] || defaultPackageName(spec);
options["emitter-output-dir"] = toPosix(
`${generatedFolder}/generator/test/${flags.flavor}/generated/${packageName}`,
`${generatedFolder}/test/${flags.flavor}/generated/${packageName}`,
);
}
if (flags.debug) {
Expand All @@ -240,7 +260,7 @@ function addOptions(
}
options["examples-dir"] = toPosix(join(dirname(spec), "examples"));
const configs = Object.entries(options).flatMap(([k, v]) => {
return `--option @typespec/http-client-python.${k}=${v}`;
return `--option ${argv.values.emitterName || "@typespec/http-client-python"}.${k}=${v}`;
});
emitterConfigs.push({
optionsStr: configs.join(" "),
Expand All @@ -250,7 +270,7 @@ function addOptions(
return emitterConfigs;
}
function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
return addOptions(spec, PLUGIN_DIR, flags).map((option) => {
return addOptions(spec, GENERATED_FOLDER, flags).map((option) => {
return {
outputDir: option.outputDir,
command: `tsp compile ${spec} --emit=${toPosix(PLUGIN_DIR)} ${option.optionsStr}`,
Expand All @@ -274,17 +294,6 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
}
}

// PARSE INPUT ARGUMENTS

const argv = parseArgs({
args: process.argv.slice(2),
options: {
flavor: { type: "string" },
name: { type: "string" },
debug: { type: "boolean" },
},
});

regenerate(argv.values)
.then(() => console.log("Regeneration successful"))
.catch((error) => console.error(`Regeneration failed: ${error.message}`));
8 changes: 5 additions & 3 deletions packages/http-client-python/eng/scripts/ci/run-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const argv = parseArgs({
flavor: { type: "string" },
command: { type: "string" },
name: { type: "string" },
testFolder: { type: "string" },
},
});

Expand All @@ -23,14 +24,15 @@ const foldersToProcess = argv.values.flavor
: argv.values.validFolders || ["azure", "unbranded"];

const commandToRun = argv.values.command || "ci";
const TEST_FOLDER = argv.values.testFolder || "generator/test";

function getCommand(command: string, flavor: string, name?: string): string {
let retval: string;
if (platform() === "win32") {
retval = `set FOLDER=${flavor} && ${venvPath} -m tox -c ./generator/test/${flavor}/tox.ini -e ${command}`;
retval = `set FOLDER=${flavor} && ${venvPath} -m tox -c ./${TEST_FOLDER}/${flavor}/tox.ini -e ${command}`;
} else {
// Linux and macOS
retval = `FOLDER=${flavor} ${venvPath} -m tox -c ./generator/test/${flavor}/tox.ini -e ${command}`;
retval = `FOLDER=${flavor} ${venvPath} -m tox -c ./${TEST_FOLDER}/${flavor}/tox.ini -e ${command}`;
}
if (name) {
return `${retval} -- -f ${name}`;
Expand All @@ -39,7 +41,7 @@ function getCommand(command: string, flavor: string, name?: string): string {
}

function sectionExistsInToxIni(command: string, flavor: string): boolean {
const toxIniPath = join(root, `generator/test/${flavor}/tox.ini`);
const toxIniPath = join(root, `${TEST_FOLDER}/${flavor}/tox.ini`);
const toxIniContent = readFileSync(toxIniPath, "utf-8");
return command
.split(",")
Expand Down
14 changes: 12 additions & 2 deletions packages/http-client-python/eng/scripts/ci/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
import chalk from "chalk";
import { exec } from "child_process";
import { existsSync } from "fs";
import { dirname, join } from "path";
import { dirname, join, resolve } from "path";
import process from "process";
import { fileURLToPath } from "url";
import { parseArgs } from "util";

const argv = parseArgs({
args: process.argv.slice(2),
options: {
pythonPath: { type: "string" },
},
});

// execute the command
export function executeCommand(command: string, prettyName: string) {
Expand All @@ -25,7 +33,9 @@ export function executeCommand(command: string, prettyName: string) {

// Function to run a command and log the output
export function runCommand(command: string, prettyName: string) {
let pythonPath = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "venv/");
let pythonPath = argv.values.pythonPath
? resolve(argv.values.pythonPath)
: join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "venv/");
if (existsSync(join(pythonPath, "bin"))) {
pythonPath = join(pythonPath, "bin", "python");
} else if (existsSync(join(pythonPath, "Scripts"))) {
Expand Down
11 changes: 4 additions & 7 deletions packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
"main": "dist/emitter/index.js",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
},
"./testing": {
"types": "./dist/src/testing/index.d.ts",
"default": "./dist/src/testing/index.js"
"types": "./dist/emitter/index.d.ts",
"default": "./dist/emitter/index.js"
}
},
"engines": {
Expand All @@ -51,7 +47,8 @@
"dist/**",
"!dist/test/**",
"generator/**",
"eng/scripts/**"
"eng/scripts/**",
"emitter"
],
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.46.0 <1.0.0",
Expand Down

0 comments on commit 8d3b21b

Please sign in to comment.