Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pip_setup): Run pip setup extract in the correct directory #8320

Merged
merged 3 commits into from
Jan 18, 2021

Conversation

hisener
Copy link
Contributor

@hisener hisener commented Jan 16, 2021

Changes:

Changes pip setup extract script's working directory to "dirname" of setup.py.

Context:

Fixes #8319.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added unit tests, or
  • Unit tests + ran on a real repository

I run it against hisener/renovate-tests, see hisener/renovate-tests#32. The hosted app closes the PR because it fails to extract (See the issue for the error message).

Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it easier to simply change cwd and leave the rest as is?

@hisener
Copy link
Contributor Author

hisener commented Jan 16, 2021

Isn't it easier to simply change cwd and leave the rest as is?

Then, we need to use the absolute path of the extract.py. Is config.localDir always an absolute path?

I've just tried but it didn't create a PR. The script seems to run though. 🤔

DEBUG: Executing command (repository=hisener/renovate-tests)
       "command": "docker run --rm --name=renovate_pip --label=renovate_child -v \"/tmp/renovate/repos/github/hisener/renovate-tests\":\"/tmp/renovate/repos/github/hisener/renovate-tests\" -v \"/tmp/renovate/cache\":\"/tmp/renovate/cache\" -w \"/tmp/renovate/repos/github/hisener/renovate-tests/pip-setup-test\" docker.io/renovate/pip bash -l -c \"python \\\"/tmp/renovate/repos/github/hisener/renovate-tests/renovate-pip_setup-extract.py\\\" \\\"setup.py\\\"\""
DEBUG: exec completed (repository=hisener/renovate-tests)
       "cmd": "docker run --rm --name=renovate_pip --label=renovate_child -v \"/tmp/renovate/repos/github/hisener/renovate-tests\":\"/tmp/renovate/repos/github/hisener/renovate-tests\" -v \"/tmp/renovate/cache\":\"/tmp/renovate/cache\" -w \"/tmp/renovate/repos/github/hisener/renovate-tests/pip-setup-test\" docker.io/renovate/pip bash -l -c \"python \\\"/tmp/renovate/repos/github/hisener/renovate-tests/renovate-pip_setup-extract.py\\\" \\\"setup.py\\\"\"",
       "durationMs": 1062,
       "stdout": "",
       "stderr": ""
DEBUG: Found pipenv package files (repository=hisener/renovate-tests)
DEBUG: Found 1 package file(s) (repository=hisener/renovate-tests)

@hisener
Copy link
Contributor Author

hisener commented Jan 16, 2021

It's because it generates renovate-pip_setup-report.json in the current working directory so I need to either change extract.py or keep passing directory to parseReport function. 🤔 I think I prefer the current approach since there might be multiple directories with setup.py. WDYT?

@viceice
Copy link
Member

viceice commented Jan 16, 2021

🤔 I think we should move to cache aproach like in #8083 so we write our python file to the cache folder and the extracted json to the repo cache folder (which will be deleted after repo processing). The json files can have the same relative paths for easier referencing.

@hisener
Copy link
Contributor Author

hisener commented Jan 16, 2021

The extracted json is already in the repo cache. Added a commit to move extract.py to the cache folder, PTAL.

Comment on lines -36 to -37
# Inserting the parent directory of the target setup.py in Python import path:
sys.path.append(dirname(realpath(sys.argv[-1])))
Copy link
Contributor Author

@hisener hisener Jan 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary because we are already running the script in the setup.py's directory.

# This is setup.py which calls setuptools.setup
load_source('_target_setup_', sys.argv[-1])
load_source('_target_setup_', basename(sys.argv[-1]))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also do this in extract.ts#49.

@@ -105,7 +108,7 @@ describe(getName(__filename), () => {
expect(
await extractPackageFile(
'raise Exception()',
'/tmp/folders/foobar.py',
'folders/foobar.py',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent confusion; otherwise cwd would be /tmp/github/some/repo/tmp/folders.

Comment on lines +29 to +30
export async function parseReport(packageFile: string): Promise<PythonSetup> {
const data = await readLocalFile(join(dirname(packageFile), REPORT), 'utf8');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we assume the report json file is next to the package file.

@hisener hisener requested a review from viceice January 16, 2021 13:15
@rarkins
Copy link
Collaborator

rarkins commented Jan 18, 2021

@hisener can you also test it against a real repo with setup.py in the root directory?

@hisener
Copy link
Contributor Author

hisener commented Jan 18, 2021

Rebased and tested after adding a setup.py to the root directory.

@rarkins rarkins merged commit 6da2f1d into renovatebot:master Jan 18, 2021
@hisener hisener deleted the hsener/gh-8319 branch January 18, 2021 13:18
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 24.22.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run pip setup extract script in the correct directory
4 participants