Skip to content

Commit 9eaf76c

Browse files
authored
fix: Non-"migrated" scrapy not working anymore (#800)
1 parent 4b09b94 commit 9eaf76c

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
185185
runType = RunType.Script;
186186
entrypoint = cwdEntrypoint.script;
187187
} else if (cwdEntrypoint?.path) {
188-
runType = type === ProjectLanguage.Python ? RunType.Module : RunType.DirectFile;
188+
runType = type !== ProjectLanguage.JavaScript ? RunType.Module : RunType.DirectFile;
189189
entrypoint = cwdEntrypoint.path;
190190
} else {
191191
error({

src/lib/hooks/useCwdProject.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ export async function useCwdProject({
7777
project.entrypoint = {
7878
path: scrapyProject.configuration.get('apify', 'mainpy_location')!,
7979
};
80+
} else {
81+
// Fallback for scrapy projects that use apify, but are not "migrated" (like our templates)
82+
const pythonFile = await checkPythonProject(cwd);
83+
84+
if (pythonFile) {
85+
project.entrypoint = {
86+
path: pythonFile,
87+
};
88+
}
8089
}
8190

8291
return;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { existsSync, readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
4+
import { getLocalDatasetPath } from '../../../../../src/lib/utils.js';
5+
import { safeLogin, useAuthSetup } from '../../../../__setup__/hooks/useAuthSetup.js';
6+
import { useTempPath } from '../../../../__setup__/hooks/useTempPath.js';
7+
8+
const actorName = 'python-scrapy-template-works';
9+
10+
const { beforeAllCalls, afterAllCalls, joinPath, toggleCwdBetweenFullAndParentPath } = useTempPath(actorName, {
11+
create: true,
12+
remove: true,
13+
cwd: true,
14+
cwdParent: true,
15+
});
16+
17+
useAuthSetup({ perTest: false });
18+
19+
const { CreateCommand } = await import('../../../../../src/commands/create.js');
20+
const { RunCommand } = await import('../../../../../src/commands/run.js');
21+
22+
describe('python-scrapy-template-works', () => {
23+
beforeAll(async () => {
24+
await beforeAllCalls();
25+
26+
await safeLogin();
27+
28+
await CreateCommand.run([actorName, '--template', 'python-scrapy'], import.meta.url);
29+
toggleCwdBetweenFullAndParentPath();
30+
});
31+
32+
afterAll(async () => {
33+
await afterAllCalls();
34+
});
35+
36+
it('should run the actor', async () => {
37+
await RunCommand.run([], import.meta.url);
38+
39+
const datasetDirectory = joinPath(getLocalDatasetPath('default'));
40+
const datasetMetadataFile = join(datasetDirectory, '__metadata__.json');
41+
expect(existsSync(datasetMetadataFile)).toBe(true);
42+
43+
const datasetMetadata = JSON.parse(readFileSync(datasetMetadataFile, 'utf8'));
44+
expect(datasetMetadata.item_count).toBeGreaterThanOrEqual(4);
45+
});
46+
});

0 commit comments

Comments
 (0)