Skip to content

Commit

Permalink
refactor: further updates
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbutt committed Feb 14, 2024
1 parent 93a5e81 commit b28443e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
15 changes: 2 additions & 13 deletions src/generators/PythonGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,28 @@ export class PythonGenerator implements GeneratorInterface {
}

private async runPipInstall(): Promise<void> {
const { name } = this.generator.options;

this.generator.log();
this.generator.log(
"Running pip to install the project dependencies for you...",
);

const pip = path.join(
this.generator.env.cwd,
name,
".venv",
"bin",
"pip",
);
const pip = path.join(this.generator.env.cwd, ".venv", "bin", "pip");

const requirements = path.join(
this.generator.env.cwd,
name,
"requirements.txt",
);

await this.generator.spawn(pip, ["install", "-r", requirements]);
}

private async setupVenv(): Promise<void> {
const { name } = this.generator.options;

this.generator.log();
this.generator.log("Creating a virtual environment...");
await this.generator.spawn("python3", [
"-m",
"venv",
`${path.join(this.generator.env.cwd, name, ".venv")}`,
`${path.join(this.generator.env.cwd, ".venv")}`,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/python/python-version.ejs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%- python.getEngine() %>
3.12.1
11 changes: 8 additions & 3 deletions tests/python.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { fileURLToPath } from "node:url";
import assert from "yeoman-assert";
import helpers, { RunResult } from "yeoman-test";
import { describe, beforeAll, afterAll, expect, it, vi } from "vitest";
// import Generator from "yeoman-generator";
import AppGenerator from "../src/app.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const generator = path.resolve(__dirname, "../dist/generators/app");

const spawn = vi.spyOn(AppGenerator.prototype, "spawn").getMockImplementation();
const spawn = vi
.spyOn(AppGenerator.prototype, "spawn")
.mockImplementation((command, args) =>
AppGenerator.prototype.spawn(command, [...args]),

Check failure on line 15 in tests/python.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

Type 'ExecaChildProcess' is not assignable to type 'ExecaChildProcess<Buffer> | Promise<ExecaChildProcess<Buffer>>'.

Check failure on line 15 in tests/python.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

Type 'readonly string[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.

Check failure on line 15 in tests/python.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Type 'ExecaChildProcess' is not assignable to type 'ExecaChildProcess<Buffer> | Promise<ExecaChildProcess<Buffer>>'.

Check failure on line 15 in tests/python.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Type 'readonly string[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
);

const files = [
".github/workflows/main.yml",
Expand Down Expand Up @@ -71,6 +76,7 @@ describe("generator-norgate-av:python", () => {

afterAll(() => {
result?.cleanup();
spawn.mockClear();
});

it("should assign the correct values", () => {
Expand Down Expand Up @@ -133,11 +139,10 @@ describe("generator-norgate-av:python", () => {
);

it("should spawn a command to create a virtual environment", () => {
console.log(spawn);
expect(spawn).toHaveBeenCalledWith("python3", [
"-m",
"venv",
`${path.join(process.cwd(), name, ".venv")}`,
`${path.join(process.cwd(), ".venv")}`,
]);
});

Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default defineConfig({
test: {
environment: "node",
testTimeout: 60000,
hookTimeout: 60000,
resolveSnapshotPath(path, extension) {
return path + extension;
},
Expand Down

0 comments on commit b28443e

Please sign in to comment.