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

feat(commands): added a --json option to info and run command #1854

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

noirbizarre
Copy link
Member

@noirbizarre noirbizarre commented Apr 25, 2023

Pull Request Checklist

  • A news fragment is added in news/ describing what is new.
  • Test cases added for changed code.

Describe what you have changed in this PR.

This PR adds a --json option (exclusive with other options) to info and run commands in order to dump those data as JSON.

On my current pdm workspace, it give those results

pdm run --json

{
  "complete": {
    "name": "complete",
    "kind": "call",
    "help": "Create autocomplete files for bash and fish",
    "args": "tasks.complete:main"
  },
  "doc": {
    "name": "doc",
    "kind": "shell",
    "help": "Start the dev server for doc preview",
    "args": "cd docs && mkdocs serve"
  },
  "lint": {
    "name": "lint",
    "kind": "cmd",
    "help": "pre-commit run --all-files",
    "args": "pre-commit run --all-files"
  },
  "pre_release": {
    "name": "pre_release",
    "kind": "cmd",
    "help": "python tasks/max_versions.py",
    "args": "python tasks/max_versions.py"
  },
  "release": {
    "name": "release",
    "kind": "cmd",
    "help": "python tasks/release.py",
    "args": "python tasks/release.py"
  },
  "test": {
    "name": "test",
    "kind": "cmd",
    "help": "pytest",
    "args": "pytest"
  },
  "tox": {
    "name": "tox",
    "kind": "cmd",
    "help": "tox",
    "args": "tox"
  }
}

pdm info --json

{
  "pdm": {
    "version": "2.5.4.dev5+g8d452e0d.d20230425.editable"
  },
  "python": {
    "interpreter": "/home/noirbizarre/Workspaces/_contribs/pdm/.venv/bin/python",
    "version": "3.11",
    "markers": {
      "implementation_name": "cpython",
      "implementation_version": "3.11.3",
      "os_name": "posix",
      "platform_machine": "x86_64",
      "platform_release": "6.2.12-arch1-1",
      "platform_system": "Linux",
      "platform_version": "#1 SMP PREEMPT_DYNAMIC Thu, 20 Apr 2023 16:11:55 +0000",
      "python_full_version": "3.11.3",
      "platform_python_implementation": "CPython",
      "python_version": "3.11",
      "sys_platform": "linux"
    }
  },
  "project": {
    "root": "/home/noirbizarre/Workspaces/_contribs/pdm",
    "pypackages": "/home/noirbizarre/Workspaces/_contribs/pdm/__pypackages__/3.11"
  }
}

Use cases

Here some possible use cases:

  • shell introspection using jq
  • Conditional steps in CI (if command is present, then ...)
  • automatic doc generation
  • cross projects inventory/analysis

@noirbizarre noirbizarre force-pushed the feature/json-metadata branch from 69945af to 8d452e0 Compare April 25, 2023 20:45
@frostming
Copy link
Collaborator

LGTM, only a small tweak, the environment markers should belong to python namespace

@noirbizarre noirbizarre force-pushed the feature/json-metadata branch from 8d452e0 to a37ea60 Compare April 26, 2023 00:56
@noirbizarre
Copy link
Member Author

Updated: the markers are now in the python object.
PR example is updated too 👆🏼

@noirbizarre noirbizarre force-pushed the feature/json-metadata branch 2 times, most recently from 3704e65 to a311faa Compare April 26, 2023 01:00
@frostming
Copy link
Collaborator

Sorry to miss one: pypackages should belong to project object.

@codecov-commenter
Copy link

codecov-commenter commented Apr 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.36%. Comparing base (0cf6578) to head (122b4a0).
Report is 649 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1854      +/-   ##
==========================================
+ Coverage   85.31%   85.36%   +0.04%     
==========================================
  Files          99       99              
  Lines        9037     9066      +29     
  Branches     1955     1960       +5     
==========================================
+ Hits         7710     7739      +29     
  Misses        896      896              
  Partials      431      431              
Flag Coverage Δ
unittests 85.17% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@noirbizarre noirbizarre force-pushed the feature/json-metadata branch from a311faa to d4254f0 Compare April 26, 2023 01:11
@noirbizarre
Copy link
Member Author

No prb, it is updated 👍🏼

@noirbizarre noirbizarre force-pushed the feature/json-metadata branch from d4254f0 to 122b4a0 Compare April 26, 2023 01:23
@frostming frostming merged commit 1d6d490 into pdm-project:main Apr 26, 2023
@noirbizarre noirbizarre deleted the feature/json-metadata branch April 26, 2023 01:40
@j178 j178 mentioned this pull request Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants