Skip to content

Commit 09a42e4

Browse files
authored
fix: python project detection and project detection (#774)
1 parent 1c108b8 commit 09a42e4

38 files changed

+1406
-729
lines changed

.github/workflows/check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
env:
9191
TEST_USER_TOKEN: ${{ secrets.APIFY_TEST_USER_API_TOKEN }}
9292
APIFY_CLI_DISABLE_TELEMETRY: 1
93+
NO_SILENT_TESTS: 1
9394
run: yarn test-python
9495

9596
docs:

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,15 @@
8181
"cors": "~2.8.5",
8282
"detect-indent": "~7.0.1",
8383
"escape-string-regexp": "~5.0.0",
84+
"execa": "^9.5.2",
8485
"express": "~4.21.0",
85-
"fs-extra": "^11.2.0",
8686
"globby": "~14.1.0",
8787
"handlebars": "~4.7.8",
8888
"inquirer": "~12.5.0",
8989
"is-ci": "~4.1.0",
9090
"is-online": "~11.0.0",
9191
"istextorbinary": "~9.5.0",
9292
"jju": "~1.4.0",
93-
"load-json-file": "~7.0.1",
9493
"lodash.clonedeep": "^4.5.0",
9594
"mime": "~4.0.4",
9695
"mixpanel": "~0.18.0",
@@ -99,8 +98,7 @@
9998
"rimraf": "~6.0.1",
10099
"semver": "~7.7.0",
101100
"tiged": "~2.12.7",
102-
"underscore": "~1.13.7",
103-
"write-json-file": "~6.0.0"
101+
"which": "^5.0.0"
104102
},
105103
"devDependencies": {
106104
"@apify/eslint-config": "^0.4.0",
@@ -110,11 +108,12 @@
110108
"@crawlee/types": "^3.11.1",
111109
"@cucumber/cucumber": "^11.0.0",
112110
"@oclif/test": "^4.0.8",
113-
"@sapphire/result": "^2.6.6",
111+
"@sapphire/result": "^2.7.2",
114112
"@types/adm-zip": "^0.5.5",
115113
"@types/archiver": "^6.0.2",
116114
"@types/chai": "^4.3.17",
117115
"@types/cors": "^2.8.17",
116+
"@types/execa": "^2.0.2",
118117
"@types/express": "^4.17.21",
119118
"@types/fs-extra": "^11",
120119
"@types/inquirer": "^9.0.7",
@@ -124,7 +123,7 @@
124123
"@types/mime": "^4.0.0",
125124
"@types/node": "^22.0.0",
126125
"@types/semver": "^7.5.8",
127-
"@types/underscore": "^1.11.15",
126+
"@types/which": "^3.0.4",
128127
"@typescript-eslint/eslint-plugin": "^7.0.2",
129128
"@typescript-eslint/parser": "^7.0.2",
130129
"@yarnpkg/core": "^4.1.2",
@@ -133,7 +132,6 @@
133132
"cross-env": "^7.0.3",
134133
"eslint": "^8.57.0",
135134
"eslint-config-prettier": "^10.0.0",
136-
"execa": "^9.5.2",
137135
"lint-staged": "^15.2.8",
138136
"mdast-util-from-markdown": "^2.0.2",
139137
"mock-stdin": "^1.0.0",

src/commands/actors/pull.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import tiged from 'tiged';
1111

1212
import { ApifyCommand } from '../../lib/apify_command.js';
1313
import { CommandExitCodes, LOCAL_CONFIG_PATH } from '../../lib/consts.js';
14+
import { useActorConfig } from '../../lib/hooks/useActorConfig.js';
1415
import { error, success } from '../../lib/outputs.js';
15-
import { getLocalConfigOrThrow, getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js';
16+
import { getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js';
1617

1718
const extractGitHubZip = async (url: string, directoryPath: string) => {
1819
const { data } = await axios.get(url, { responseType: 'arraybuffer' });
@@ -51,19 +52,16 @@ export class ActorsPullCommand extends ApifyCommand<typeof ActorsPullCommand> {
5152
async run() {
5253
const cwd = process.cwd();
5354

54-
let localConfig: Record<string, unknown>;
55+
const actorConfigResult = await useActorConfig({ cwd });
5556

56-
try {
57-
localConfig = (await getLocalConfigOrThrow(cwd))!;
58-
} catch (_error) {
59-
const casted = _error as Error;
60-
const cause = casted.cause as Error;
61-
62-
error({ message: `${casted.message}\n ${cause.message}` });
57+
if (actorConfigResult.isErr()) {
58+
error({ message: actorConfigResult.unwrapErr().message });
6359
process.exitCode = CommandExitCodes.InvalidActorJson;
6460
return;
6561
}
6662

63+
const { config: actorConfig } = actorConfigResult.unwrap();
64+
6765
const userInfo = await getLocalUserInfo();
6866
const apifyClient = await getLoggedClientOrThrow();
6967

@@ -72,8 +70,8 @@ export class ActorsPullCommand extends ApifyCommand<typeof ActorsPullCommand> {
7270

7371
const actorId =
7472
this.args?.actorId ||
75-
(localConfig?.id as string | undefined) ||
76-
(localConfig?.name ? `${usernameOrId}/${localConfig.name}` : undefined);
73+
(actorConfig?.id as string | undefined) ||
74+
(actorConfig?.name ? `${usernameOrId}/${actorConfig.name}` : undefined);
7775

7876
if (!actorId) throw new Error('Cannot find Actor in this directory.');
7977

src/commands/actors/push.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import open from 'open';
1313
import { ApifyCommand } from '../../lib/apify_command.js';
1414
import { CommandExitCodes, DEPRECATED_LOCAL_CONFIG_NAME, LOCAL_CONFIG_PATH } from '../../lib/consts.js';
1515
import { sumFilesSizeInBytes } from '../../lib/files.js';
16+
import { useActorConfig } from '../../lib/hooks/useActorConfig.js';
1617
import { error, info, link, run, success, warning } from '../../lib/outputs.js';
1718
import { transformEnvToEnvVars } from '../../lib/secrets.js';
1819
import {
1920
createActZip,
2021
createSourceFiles,
2122
getActorLocalFilePaths,
22-
getLocalConfigOrThrow,
2323
getLocalUserInfo,
2424
getLoggedClientOrThrow,
2525
outputJobLog,
@@ -131,19 +131,16 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
131131

132132
const apifyClient = await getLoggedClientOrThrow();
133133

134-
let localConfig: Record<string, unknown>;
134+
const actorConfigResult = await useActorConfig({ cwd });
135135

136-
try {
137-
localConfig = (await getLocalConfigOrThrow(cwd))!;
138-
} catch (_error) {
139-
const casted = _error as Error;
140-
const cause = casted.cause as Error;
141-
142-
error({ message: `${casted.message}\n ${cause.message}` });
136+
if (actorConfigResult.isErr()) {
137+
error({ message: actorConfigResult.unwrapErr().message });
143138
process.exitCode = CommandExitCodes.InvalidActorJson;
144139
return;
145140
}
146141

142+
const { config: actorConfig } = actorConfigResult.unwrap();
143+
147144
const userInfo = await getLocalUserInfo();
148145
const isOrganizationLoggedIn = !!userInfo.organizationOwnerUserId;
149146
const redirectUrlPart = isOrganizationLoggedIn ? `/organization/${userInfo.id}` : '';
@@ -154,9 +151,9 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
154151

155152
// User can override Actor version and build tag, attributes in localConfig will remain same.
156153
const version =
157-
this.flags.version || (localConfig?.version as string | undefined) || DEFAULT_ACTOR_VERSION_NUMBER;
154+
this.flags.version || (actorConfig?.version as string | undefined) || DEFAULT_ACTOR_VERSION_NUMBER;
158155

159-
let buildTag = this.flags.buildTag || (localConfig!.buildTag as string | undefined);
156+
let buildTag = this.flags.buildTag || (actorConfig?.buildTag as string | undefined);
160157

161158
// We can't add the default build tag to everything. If a user creates a new
162159
// version, e.g. for testing, but forgets to add a tag, it would use the default
@@ -180,16 +177,16 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
180177
actorId = actor.id;
181178
} else {
182179
const usernameOrId = userInfo.username || userInfo.id;
183-
actor = (await apifyClient.actor(`${usernameOrId}/${localConfig!.name}`).get())!;
180+
actor = (await apifyClient.actor(`${usernameOrId}/${actorConfig!.name}`).get())!;
184181
if (actor) {
185182
actorId = actor.id;
186183
} else {
187184
const { templates } = await fetchManifest();
188-
const actorTemplate = templates.find((t) => t.name === localConfig!.template);
185+
const actorTemplate = templates.find((t) => t.name === actorConfig!.template);
189186
const defaultRunOptions = (actorTemplate?.defaultRunOptions ||
190187
DEFAULT_RUN_OPTIONS) as ActorDefaultRunOptions;
191188
const newActor: ActorCollectionCreateOptions = {
192-
name: localConfig!.name as string,
189+
name: actorConfig!.name as string,
193190
defaultRunOptions,
194191
versions: [
195192
{
@@ -204,11 +201,11 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
204201
actor = await apifyClient.actors().create(newActor);
205202
actorId = actor.id;
206203
isActorCreatedNow = true;
207-
info({ message: `Created Actor with name ${localConfig!.name} on Apify.` });
204+
info({ message: `Created Actor with name ${actorConfig!.name} on Apify.` });
208205
}
209206
}
210207

211-
info({ message: `Deploying Actor '${localConfig!.name}' to Apify.` });
208+
info({ message: `Deploying Actor '${actorConfig!.name}' to Apify.` });
212209

213210
const filesSize = await sumFilesSizeInBytes(filePathsToPush, cwd);
214211
const actorClient = apifyClient.actor(actorId);
@@ -235,10 +232,10 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
235232
!this.flags.force &&
236233
actorModifiedMs &&
237234
mostRecentModifiedFileMs < actorModifiedMs &&
238-
(localConfig?.name || forceActorId)
235+
(actorConfig?.name || forceActorId)
239236
) {
240237
throw new Error(
241-
`Actor with identifier "${localConfig?.name || forceActorId}" is already on the platform and was modified there since modified locally.
238+
`Actor with identifier "${actorConfig?.name || forceActorId}" is already on the platform and was modified there since modified locally.
242239
Skipping push. Use --force to override.`,
243240
);
244241
}
@@ -268,8 +265,8 @@ Skipping push. Use --force to override.`,
268265

269266
// Update Actor version
270267
const actorCurrentVersion = await actorClient.version(version).get();
271-
const envVars = localConfig!.environmentVariables
272-
? transformEnvToEnvVars(localConfig!.environmentVariables as Record<string, string>)
268+
const envVars = actorConfig!.environmentVariables
269+
? transformEnvToEnvVars(actorConfig!.environmentVariables as Record<string, string>)
273270
: undefined;
274271

275272
if (actorCurrentVersion) {

src/commands/actors/rm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Args } from '@oclif/core';
22
import type { ApifyApiError } from 'apify-client';
33

44
import { ApifyCommand } from '../../lib/apify_command.js';
5-
import { confirmAction } from '../../lib/commands/confirm.js';
65
import { error, info, success } from '../../lib/outputs.js';
6+
import { confirmAction } from '../../lib/utils/confirm.js';
77
import { getLoggedClientOrThrow } from '../../lib/utils.js';
88

99
export class ActorRmCommand extends ApifyCommand<typeof ActorRmCommand> {

src/commands/builds/rm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Args } from '@oclif/core';
22
import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';
33

44
import { ApifyCommand } from '../../lib/apify_command.js';
5-
import { confirmAction } from '../../lib/commands/confirm.js';
65
import { error, info, success } from '../../lib/outputs.js';
6+
import { confirmAction } from '../../lib/utils/confirm.js';
77
import { getLoggedClientOrThrow } from '../../lib/utils.js';
88

99
export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {

0 commit comments

Comments
 (0)