run-in-subdirectory


Namerun-in-subdirectory JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/egormkn/run-in-subdirectory
SummaryA command-line utility for running commands in subdirectories (e.g. in a monorepo) with a set of pre-commit hooks
upload_time2024-03-06 08:02:28
maintainer
docs_urlNone
authorEgor Makarenko
requires_python>=3.8,<4.0
licenseMIT
keywords git hooks utilities pre-commit monorepo git-hooks pre-commit-hook pre-commit-hooks subdirectory
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build](https://img.shields.io/github/actions/workflow/status/egormkn/run-in-subdirectory/workflow.yml)](https://github.com/egormkn/run-in-subdirectory/actions/workflows/workflow.yml)
[![Coverage](https://img.shields.io/codecov/c/github/egormkn/run-in-subdirectory?token=4GI2X9GPTC)](https://codecov.io/gh/egormkn/run-in-subdirectory)
[![PyPI - Version](https://img.shields.io/pypi/v/run-in-subdirectory.svg)](https://pypi.org/project/run-in-subdirectory/)
[![PyPI - License](https://img.shields.io/pypi/l/run-in-subdirectory)](https://github.com/egormkn/run-in-subdirectory/blob/main/LICENSE)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/run-in-subdirectory)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://github.com/PyCQA/isort)
[![Linting: ruff](https://img.shields.io/badge/linting-ruff-261230)](https://github.com/astral-sh/ruff)

<div align="center">
  <img width="100" alt="run pre-commit in subdirectory" src="https://raw.githubusercontent.com/egormkn/run-in-subdirectory/main/assets/logo.png">

  # run-in-subdirectory

  A command-line utility for running commands in subdirectories (e.g. in a monorepo) with a set of pre-commit hooks

</div>


## Usage

### As a pre-commit hook

- Use [`run-in-subdirectory`](.pre-commit-hooks.yaml) hook to run command in a subdirectory passed as the first argument.
  
  In this example, pre-commit will run the command `npx --no -- prettier -w -u` in `client` subdirectory, and the command `poetry run black` in `server` subdirectory:

  ```yaml
  repos:
    - repo: https://github.com/egormkn/run-in-subdirectory
      rev: 1.0.1
      hooks:
        - id: run-in-subdirectory
          alias: prettier
          name: Format client code with Prettier
          args: ["client", "npx --no -- prettier -w -u"]
          types: [ text ]
          files: ^client/
        - id: run-in-subdirectory
          alias: black
          name: Format server code with Black
          args: ["server", "poetry run black"]
          types: [ python ]
          files: ^client/
  ```

- Use one of [`run-in-...-level-subdirectory`](.pre-commit-hooks.yaml) hooks to automatically extract `first`, `second` or `third`-level subdirectory from the last file path, that was passed to the hook by pre-commit.
  
  Note that you should set `files`, `types` and/or `exclude` properties so that the hook only runs for files in that subdirectory.

  ```yaml
  repos:
    - repo: https://github.com/egormkn/run-in-subdirectory
      rev: 1.0.1
      hooks:
        - id: run-in-first-level-subdirectory
          alias: prettier
          name: Format client code with Prettier
          args: ["npx --no -- prettier -w -u"]
          types: [ text ]
          files: ^client/
        - id: run-in-first-level-subdirectory
          alias: black
          name: Format server code with Black
          args: ["poetry run black"]
          types: [ python ]
          files: ^client/
  ```
  
- If the available hooks are not enough for your task, use a custom Python hook and execute `run-in-subdirectory` as a command-line utility). Also, please [open an issue](https://github.com/egormkn/run-in-subdirectory/issues) to report such cases.

  ```yaml
  repos:
    - repo: local
      hooks:
        - id: prettier
          name: Format client code with Prettier
          language: python
          additional_dependencies:
            - "run-in-subdirectory==1.0.1"
          entry: run-in-subdirectory -d client npx --no -- prettier -w -u
          types: [ text ]
          files: ^client/
  ```

### As a command-line utility

`run-in-subdirectory` can also be used as a command-line utility:

```bash
pip install run-in-subdirectory
```

```
usage: run-in-subdirectory [-h] [-v] (-l LEVEL | -d DIRECTORY) executable [args ...]

Runs the command in a subdirectory and fixes paths in arguments.

positional arguments:
  executable            Executable to run
  args                  Sequence of program arguments

options:
  -h, --help            show this help message and exit
  -v, --verbose         Print information about a command to be called
  -l LEVEL, --level LEVEL
                        Subdirectory level (0 for top-level directory)
  -d DIRECTORY, --directory DIRECTORY
                        Subdirectory within which the subprocess will be executed

example:
  When this program is executed with the following command:
    run-in-subdirectory -d client npx --no prettier client/src/index.ts
  Then the command will be executed:
    npx --no prettier src/index.ts
  with the current working directory set to `client`.
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/egormkn/run-in-subdirectory",
    "name": "run-in-subdirectory",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "git,hooks,utilities,pre-commit,monorepo,git-hooks,pre-commit-hook,pre-commit-hooks,subdirectory",
    "author": "Egor Makarenko",
    "author_email": "egormkn@yandex.ru",
    "download_url": "https://files.pythonhosted.org/packages/58/85/43f2a94180b2fde7e0670a8465ed06ca461e9bf3eac46009d3e2a0b5083d/run_in_subdirectory-1.0.1.tar.gz",
    "platform": null,
    "description": "[![Build](https://img.shields.io/github/actions/workflow/status/egormkn/run-in-subdirectory/workflow.yml)](https://github.com/egormkn/run-in-subdirectory/actions/workflows/workflow.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/egormkn/run-in-subdirectory?token=4GI2X9GPTC)](https://codecov.io/gh/egormkn/run-in-subdirectory)\n[![PyPI - Version](https://img.shields.io/pypi/v/run-in-subdirectory.svg)](https://pypi.org/project/run-in-subdirectory/)\n[![PyPI - License](https://img.shields.io/pypi/l/run-in-subdirectory)](https://github.com/egormkn/run-in-subdirectory/blob/main/LICENSE)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/run-in-subdirectory)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://github.com/PyCQA/isort)\n[![Linting: ruff](https://img.shields.io/badge/linting-ruff-261230)](https://github.com/astral-sh/ruff)\n\n<div align=\"center\">\n  <img width=\"100\" alt=\"run pre-commit in subdirectory\" src=\"https://raw.githubusercontent.com/egormkn/run-in-subdirectory/main/assets/logo.png\">\n\n  # run-in-subdirectory\n\n  A command-line utility for running commands in subdirectories (e.g. in a monorepo) with a set of pre-commit hooks\n\n</div>\n\n\n## Usage\n\n### As a pre-commit hook\n\n- Use [`run-in-subdirectory`](.pre-commit-hooks.yaml) hook to run command in a subdirectory passed as the first argument.\n  \n  In this example, pre-commit will run the command `npx --no -- prettier -w -u` in `client` subdirectory, and the command `poetry run black` in `server` subdirectory:\n\n  ```yaml\n  repos:\n    - repo: https://github.com/egormkn/run-in-subdirectory\n      rev: 1.0.1\n      hooks:\n        - id: run-in-subdirectory\n          alias: prettier\n          name: Format client code with Prettier\n          args: [\"client\", \"npx --no -- prettier -w -u\"]\n          types: [ text ]\n          files: ^client/\n        - id: run-in-subdirectory\n          alias: black\n          name: Format server code with Black\n          args: [\"server\", \"poetry run black\"]\n          types: [ python ]\n          files: ^client/\n  ```\n\n- Use one of [`run-in-...-level-subdirectory`](.pre-commit-hooks.yaml) hooks to automatically extract `first`, `second` or `third`-level subdirectory from the last file path, that was passed to the hook by pre-commit.\n  \n  Note that you should set `files`, `types` and/or `exclude` properties so that the hook only runs for files in that subdirectory.\n\n  ```yaml\n  repos:\n    - repo: https://github.com/egormkn/run-in-subdirectory\n      rev: 1.0.1\n      hooks:\n        - id: run-in-first-level-subdirectory\n          alias: prettier\n          name: Format client code with Prettier\n          args: [\"npx --no -- prettier -w -u\"]\n          types: [ text ]\n          files: ^client/\n        - id: run-in-first-level-subdirectory\n          alias: black\n          name: Format server code with Black\n          args: [\"poetry run black\"]\n          types: [ python ]\n          files: ^client/\n  ```\n  \n- If the available hooks are not enough for your task, use a custom Python hook and execute `run-in-subdirectory` as a command-line utility). Also, please [open an issue](https://github.com/egormkn/run-in-subdirectory/issues) to report such cases.\n\n  ```yaml\n  repos:\n    - repo: local\n      hooks:\n        - id: prettier\n          name: Format client code with Prettier\n          language: python\n          additional_dependencies:\n            - \"run-in-subdirectory==1.0.1\"\n          entry: run-in-subdirectory -d client npx --no -- prettier -w -u\n          types: [ text ]\n          files: ^client/\n  ```\n\n### As a command-line utility\n\n`run-in-subdirectory` can also be used as a command-line utility:\n\n```bash\npip install run-in-subdirectory\n```\n\n```\nusage: run-in-subdirectory [-h] [-v] (-l LEVEL | -d DIRECTORY) executable [args ...]\n\nRuns the command in a subdirectory and fixes paths in arguments.\n\npositional arguments:\n  executable            Executable to run\n  args                  Sequence of program arguments\n\noptions:\n  -h, --help            show this help message and exit\n  -v, --verbose         Print information about a command to be called\n  -l LEVEL, --level LEVEL\n                        Subdirectory level (0 for top-level directory)\n  -d DIRECTORY, --directory DIRECTORY\n                        Subdirectory within which the subprocess will be executed\n\nexample:\n  When this program is executed with the following command:\n    run-in-subdirectory -d client npx --no prettier client/src/index.ts\n  Then the command will be executed:\n    npx --no prettier src/index.ts\n  with the current working directory set to `client`.\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A command-line utility for running commands in subdirectories (e.g. in a monorepo) with a set of pre-commit hooks",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/egormkn/run-in-subdirectory",
        "Repository": "https://github.com/egormkn/run-in-subdirectory"
    },
    "split_keywords": [
        "git",
        "hooks",
        "utilities",
        "pre-commit",
        "monorepo",
        "git-hooks",
        "pre-commit-hook",
        "pre-commit-hooks",
        "subdirectory"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "834f104ded58c59efda58530bc41f654520eea66325e6d0872f6c6782022fada",
                "md5": "f2be39e82f88e644e42fd26c4581c9ee",
                "sha256": "cd8fd52a5754d539d6edede24e9383bd63e32df408f65351ccfb993e3a129fa7"
            },
            "downloads": -1,
            "filename": "run_in_subdirectory-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f2be39e82f88e644e42fd26c4581c9ee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 10376,
            "upload_time": "2024-03-06T08:02:26",
            "upload_time_iso_8601": "2024-03-06T08:02:26.295957Z",
            "url": "https://files.pythonhosted.org/packages/83/4f/104ded58c59efda58530bc41f654520eea66325e6d0872f6c6782022fada/run_in_subdirectory-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "588543f2a94180b2fde7e0670a8465ed06ca461e9bf3eac46009d3e2a0b5083d",
                "md5": "c255930a01bf52de2b3c58c24d95c3a7",
                "sha256": "3fb900d71e91a827e78e92169f551206def054a43918d25190b7bd8e46ed398d"
            },
            "downloads": -1,
            "filename": "run_in_subdirectory-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c255930a01bf52de2b3c58c24d95c3a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 8891,
            "upload_time": "2024-03-06T08:02:28",
            "upload_time_iso_8601": "2024-03-06T08:02:28.838726Z",
            "url": "https://files.pythonhosted.org/packages/58/85/43f2a94180b2fde7e0670a8465ed06ca461e9bf3eac46009d3e2a0b5083d/run_in_subdirectory-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-06 08:02:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "egormkn",
    "github_project": "run-in-subdirectory",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "run-in-subdirectory"
}
        
Elapsed time: 0.19542s