Code Monkey home page Code Monkey logo

sync_with_pdm's Introduction

Sync with PDM

CI codecov pre-commit.ci status pre-commit Code style: black pdm-managed

A .pre-commit hook for keeping in sync the repos rev in .pre-commit-config.yaml with the packages version locked into pdm.lock. Check out pre-commit.com for more about the main framework.

Do you rely on Poetry? See this equivalent sync repo: sync_with_poetry.

What problem does this hook help us solve?

PDM is a modern Python package and dependency manager supporting the latest PEP standards. Sometimes, you might want to install dev dependencies locally (e.g., black, flake8, isort, mypy, ...) to make your IDE (e.g., VS Code) play nicely with dev packages. This approach usually turns on a live feedback as you code (e.g., suggestions, linting, formatting, errors highlighting). PDM pins dev packages in pdm.lock.

This hook updates the rev of each repo in .pre-commit-config.yaml with the corresponding package version stored in pdm.lock.

E.g., starting from the following files:

# pdm.lock
[[package]]
name = "black"
version = "21.12b0"
# ...
# .pre-commit-config.yaml
repos:
  # black - formatting
  - repo: https://github.com/psf/black
    rev: 21.11b1
    hooks:
      - id: black

this hook will bump black in .pre-commit-config.yaml as follows:

# .pre-commit-config.yaml
repos:
  # black - formatting
  - repo: https://github.com/psf/black
    rev: 21.12b0
    hooks:
      - id: black

Usage

Excerpt from a .pre-commit-config.yaml using an example of this hook:

- repo: https://github.com/floatingpurr/sync_with_pdm
  rev: "" # the revision or tag to clone at
  hooks:
    - id: sync_with_pdm
      args: [] # optional args

Args

  --all              Scan all dependencies in pdm.lock (main, optional and dev)
  --skip [SKIP ...]  Packages to skip
  --config CONFIG    Path to a custom .pre-commit-config.yaml file
  --db PACKAGE_LIST  Path to a custom package list (json)

Usually this hook uses only dev packages to sync the hooks. Pass --all, if you want to scan also the main project packages.

Pass --skip <package_1> <package_2> ... to disable the automatic synchronization of the repos such packages correspond to.

Pass --config <config_file> to point to an alternative config file (it defaults to .pre-commit-config.yaml).

Pass --db <package_list_file> to point to an alternative package list (json). Such a file overrides the mapping in db.py.

Supported packages

Supported packages out-of-the-box are listed in db.py:

  • autopep8
  • bandit
  • black
  • commitizen
  • flake8
  • flakeheaven
  • isort
  • mypy
  • pyupgrade

From version 0.4.0, you can create your very own package list, passing a custom json file with the arg --db. Such a file specifies how to map a package to the corresponding repo, following this pattern:

{
  "<package_name_in_PyPI>": {
    "repo": "<repo_url_for_the_package>",
    "rev": "<revision_template>"
  }
}

Sometimes the template of the version number of a package in PyPI differs from the one used in the repo rev. For example, version 0.910 of mypy in PyPI (no pun intended) maps to repo rev: v0.910. To make this hook aware of the leading v, you need to specify "v${rev}" as a "<revision_template>". Use "${rev}" if both the package version and the repo rev follow the same pattern.

PRs extending db.py are welcome.

Contributing

See CONTRIBUTING.md.

Credits

This hook is inspired by pre-commit autoupdate.

sync_with_pdm's People

Contributors

floatingpurr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gabdug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.