Skip to content

Commit

Permalink
package: add class for pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim authored and max-moser committed Feb 20, 2025
1 parent 1d16a60 commit fd3f119
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
=======

Version <next>

- Add ``PNPMPackage``

Version 0.2.0 (released 2023-11-27)

- Added ``shell`` argument.
Expand Down
5 changes: 3 additions & 2 deletions pynpm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of PyNPM
# Copyright (C) 2017 CERN.
# Copyright (C) 2025 Graz University of Technology.
#
# PyNPM is free software; you can redistribute it and/or modify
# it under the terms of the Revised BSD License; see LICENSE file for
Expand All @@ -11,8 +12,8 @@

from __future__ import absolute_import, print_function

from .package import NPMPackage, YarnPackage
from .package import NPMPackage, PNPMPackage, YarnPackage

__version__ = "0.2.0"

__all__ = ("__version__", "NPMPackage", "YarnPackage")
__all__ = ("__version__", "NPMPackage", "PNPMPackage", "YarnPackage")
27 changes: 27 additions & 0 deletions pynpm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is part of PyNPM
# Copyright (C) 2017 CERN.
# Copyright (C) 2023 Rambaud Pierrick.
# Copyright (C) 2025 Graz University of Technology.
#
# PyNPM is free software; you can redistribute it and/or modify
# it under the terms of the Revised BSD License; see LICENSE file for
Expand Down Expand Up @@ -96,3 +97,29 @@ def __init__(self, filepath, yarn_bin="yarn", commands=None, shell=False):
super(YarnPackage, self).__init__(
filepath, npm_bin=yarn_bin, commands=commands or ["install"], shell=shell
)


class PNPMPackage(NPMPackage):
"""API to a PNPM ``package.json.``"""

def __init__(self, filepath, npm_bin="pnpm", commands=None, shell=False):
"""Construct."""
super().__init__(
filepath=filepath, npm_bin=npm_bin, commands=commands, shell=shell
)

def _run_npm(self, command, *args, **kwargs):
"""Run a PNPM command.
By default the call is blocking until PNPM is finished and output
is directed to stdout. If ``wait=False`` is passed to the method,
you get a handle to the process (return value of ``subprocess.Popen``).
:param command: PNPM command to run.
:param args: List of arguments.
:param wait: Wait for PNPM command to finish.
"""
if command == "install":
args = ["--shamefully-hoist"]

return super()._run_npm(command, *args, **kwargs)

0 comments on commit fd3f119

Please sign in to comment.