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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
def set_up_adventure_pack():
def digits(self: int, radix: int = 10):
from typing import Generator


def set_up_adventure_pack() -> None:
def digits(self: int, radix: int = 10) -> Generator[int, None, None]:
if self < 0:
raise ValueError("Must invoke on a non-negative integer.")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import os

with open(os.path.join(os.path.dirname(__file__), "__init__.py"), "r") as f:
module_code = f.read()
exec(module_code)


def test_base_10():
def test_base_10() -> None:
assert list((123).digits(10)) == [3, 2, 1]
assert list((1337).digits(10)) == [7, 3, 3, 1]
assert list((42).digits(10)) == [2, 4]
Expand All @@ -29,7 +22,7 @@ def test_base_10():
assert list((5).digits(10)) == [5]


def test_base_2():
def test_base_2() -> None:
assert list((12).digits(2)) == [0, 0, 1, 1]
assert list((2**10 - 1).digits(2)) == [1] * 10
assert list((2**30).digits(2)) == ([0] * 30 + [1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,13 +867,16 @@ fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
/////////////////////////// END ADVENTURE PACK CODE ////////////////////////////"
`;

exports[`App can equip single goody: Python 3 int.digits 1`] = `
exports[`App can equip single goody: Python 3 int_digits 1`] = `
"########################## BEGIN ADVENTURE PACK CODE ###########################
# Adventure Pack commit fake-commit-hash
# Running at: https://example.com/

def set_up_adventure_pack():
def digits(self: int, radix: int = 10):
from typing import Generator


def set_up_adventure_pack() -> None:
def digits(self: int, radix: int = 10) -> Generator[int, None, None]:
if self < 0:
raise ValueError("Must invoke on a non-negative integer.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,12 @@ import gcd_int_int.gcd
fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b"
`;

exports[`App can render goody: Python 3 int.digits 1`] = `
"def set_up_adventure_pack():
def digits(self: int, radix: int = 10):
exports[`App can render goody: Python 3 int_digits 1`] = `
"from typing import Generator


def set_up_adventure_pack() -> None:
def digits(self: int, radix: int = 10) -> Generator[int, None, None]:
if self < 0:
raise ValueError("Must invoke on a non-negative integer.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import { WritableDeep } from "type-fest";

import type { Python3Goody } from "../../../app/parsers/python3GoodyParser";

export const GOODIES_DIRECTORY = path.join("goodies", "python3");
export const GOODIES_DIRECTORY = path.join("goodies", "python3", "src");

export type Python3GoodyBase = Omit<WritableDeep<Python3Goody>, "importedBy">;

export async function readBaseGoody(name: string): Promise<Python3GoodyBase> {
export async function readBaseGoody(
moduleName: string,
): Promise<Python3GoodyBase> {
const code = await fsPromises.readFile(
path.join(GOODIES_DIRECTORY, name, "__init__.py"),
path.join(GOODIES_DIRECTORY, moduleName, "__init__.py"),
"utf8",
);

return {
code,
imports: [],
name,
language: "python3",
name: moduleName,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ export async function readGoodies(): Promise<Record<string, Python3Goody>> {
const baseGoodiesByName: Record<string, Python3GoodyBase> = {};

for (const entry of fileEntries) {
if (!entry.isDirectory() || entry.name.startsWith(".")) {
continue;
}
const moduleName = entry.name;
invariant(
entry.isDirectory(),
`Found non-module ${JSON.stringify(moduleName)} in Python 3 goodies directory!`,
);

// eslint-disable-next-line no-await-in-loop
const baseGoody = await readBaseGoody(entry.name);
const baseGoody = await readBaseGoody(moduleName);
invariant(baseGoody.name === entry.name, "Mismatched goody name!");
setIfNotHasOwnOrThrow(baseGoodiesByName, baseGoody.name, baseGoody);
}
Expand Down