Skip to content

meta=none will cause post-hooks to run in working directory #696

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

Closed
brenmous opened this issue Nov 9, 2022 · 0 comments · Fixed by #697
Closed

meta=none will cause post-hooks to run in working directory #696

brenmous opened this issue Nov 9, 2022 · 0 comments · Fixed by #697
Labels
🐞bug Something isn't working

Comments

@brenmous
Copy link
Contributor

brenmous commented Nov 9, 2022

Describe the bug
When using openapi-python-client generate --meta=none, post-hooks are run in the current directory.
This is an issue if you run the command in e.g. your home directory, as hooks will then run recursively and operate on everything they can find.

The culprits appear to be here:

self.project_dir /= self.project_name

here:

cmd, cwd=self.project_dir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True

and here:

"autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports .",

To Reproduce
Steps to reproduce the behavior:

  1. Make a new directory
  2. Add a subdirectory, inside include some random python file with e.g. an unused import
  3. Go back to the parent directory
  4. Run openapi-python-client generate --meta=none [--path=...|--url=...]
  5. Your python file in the subdirectory will have been formatted, e.g. unused import removed

Expected behavior
I'd expect post-hooks to only ever be run in the directory generated for the client.

OpenAPI Spec File
Doesn't seem like this is required but I'll include it if you want.

Desktop (please complete the following information):

  • OS: EndeavourOS (6.0.7-arch1-1)
  • Python Version: 3.10.8
  • openapi-python-client version: 0.11.6

Additional context
Add any other context about the problem here.

@brenmous brenmous added the 🐞bug Something isn't working label Nov 9, 2022
@brenmous brenmous closed this as completed Nov 9, 2022
@brenmous brenmous reopened this Nov 9, 2022
@brenmous brenmous changed the title meta=None will cause post-hooks to run in working directory meta=none will cause post-hooks to run in working directory Nov 9, 2022
brenmous added a commit to brenmous/openapi-python-client that referenced this issue Nov 9, 2022
`project_dir` is set as the working directory if meta generation is
turned off. Commands cwd to `project_dir`, so hooks will be run in
whatever directory you're running the `generate` command in.
The default post-hooks will then run recursively in that directory
on any Python files it can find.

Set the directory to run commands in to `package_dir` if meta is none,
so post-hooks only touch the generated code.

fixes openapi-generators#696
dbanty added a commit that referenced this issue Jan 6, 2023
…ory if meta=none [#696, #697]. Thanks @brenmous and @wallagib!

Co-authored-by: Dylan Anthony <[email protected]>
Co-authored-by: Max Komarychev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant