Skip to content

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

Closed
@brenmous

Description

@brenmous

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions