Skip to content

Commit 2ff8933

Browse files
committed
Seperate the command line commands into separate optional package
1 parent d9cf01d commit 2ff8933

File tree

7 files changed

+104
-11
lines changed

7 files changed

+104
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/dist
2+
nodejs-cmd/build
3+
nodejs-cmd/dist
4+
nodejs-cmd/*.egg-info
25
.DS_Store
36
env*/
47
__pycache__/

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ To install:
2323
pip install nodejs-bin
2424
```
2525

26+
By default the command line `node`, `npm` and `npx` commands are not installed to prevent collisions with already installed Node.js versions. To install them:
27+
28+
```shell
29+
pip install 'nodejs-bin[cmd]'
30+
```
31+
2632
You can specify the Node.js version to install with:
2733

2834
```shell
@@ -39,13 +45,22 @@ To run Node.js from the command line, use:
3945

4046
```shell
4147
python -m nodejs
42-
# or (see below)
43-
node
4448
```
4549

46-
`npm` and `npx` are also available as `python -m nodejs.npm` and `python -m nodejs.npx`.
50+
`npm` and `npx` are also available as `nodejs.npm` and `nodejs.npx`:
51+
52+
```shell
53+
python -m nodejs.npm
54+
python -m nodejs.npx
55+
```
56+
57+
If you installed the optional command line commands with `pip install 'nodejs-bin[cmd]'` (see above), you can use them directly from the command line as you would normally with Node.js:
4758

48-
Additionally, the standard `node`, `npm` and `npx` commands are also added to your Python environment's `bin` directory. This is usually on your `PATH` and so they should be available in your shell environment.
59+
```shell
60+
node
61+
npm
62+
npx
63+
```
4964

5065
Python API Usage
5166
----------------
@@ -113,6 +128,14 @@ Finally, there are a number of convenient attributes on the `nodejs` module:
113128
* `nodejs.path`: the path to the Node.js executable.
114129

115130

131+
Versions
132+
--------
133+
134+
nodejs-bin offers Node.js *Current* and *LTS* (long-term support) versions. See the [Node.js Documentation](https://nodejs.org/en/about/releases/) for more information.
135+
136+
The full list of versions is available on PyPI is here: <https://pypi.org/project/nodejs-bin/#history>
137+
138+
116139
License
117140
-------
118141

make_wheels.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# Suffix to append to the Wheel
1515
# For pre release versions this should be 'aN', e.g. 'a1'
1616
# For release versions this should be ''
17-
# If replacing a release version, this should be a build tag '-N', e.g. '-1'.
1817
# See https://peps.python.org/pep-0427/#file-name-convention for details.
1918
BUILD_SUFFIX = 'a2'
2019

@@ -87,12 +86,13 @@ def write_wheel(out_dir, *, name, version, tag, metadata, description, contents,
8786
name_snake = name.replace('-', '_')
8887
wheel_name = f'{name_snake}-{version}-{tag}.whl'
8988
dist_info = f'{name_snake}-{version}.dist-info'
90-
return write_wheel_file(os.path.join(out_dir, wheel_name), {
91-
**contents,
92-
f'{dist_info}/entry_points.txt': (cleandoc("""
89+
if entry_points:
90+
contents[f'{dist_info}/entry_points.txt'] = (cleandoc("""
9391
[console_scripts]
9492
{entry_points}
9593
""").format(entry_points='\n'.join([f'{k} = {v}' for k, v in entry_points.items()] if entry_points else []))).encode('ascii'),
94+
return write_wheel_file(os.path.join(out_dir, wheel_name), {
95+
**contents,
9696
f'{dist_info}/METADATA': make_message({
9797
'Metadata-Version': '2.1',
9898
'Name': name,
@@ -129,7 +129,7 @@ def write_nodejs_wheel(out_dir, *, node_version, version, platform, archive):
129129
contents[zip_info] = b''.join(entry.get_blocks())
130130

131131
if entry_name in NODE_BINS:
132-
entry_points['node'] = 'nodejs.node:main'
132+
# entry_points['node'] = 'nodejs.node:main'
133133
contents['nodejs/node.py'] = cleandoc(f"""
134134
import os, sys, subprocess
135135
@@ -166,7 +166,7 @@ def main():
166166
main()
167167
""").encode('ascii')
168168
elif entry_name in NODE_OTHER_BINS and NODE_OTHER_BINS[entry_name][1]:
169-
entry_points[NODE_OTHER_BINS[entry_name][0]] = f'nodejs.{NODE_OTHER_BINS[entry_name][0]}:main'
169+
# entry_points[NODE_OTHER_BINS[entry_name][0]] = f'nodejs.{NODE_OTHER_BINS[entry_name][0]}:main'
170170
script_name = '/'.join(os.path.normpath(os.path.join(os.path.dirname(entry.name), entry.linkpath)).split('/')[1:])
171171
contents[f'nodejs/{NODE_OTHER_BINS[entry_name][0]}.py'] = cleandoc(f"""
172172
import os, sys
@@ -197,7 +197,7 @@ def main():
197197
main()
198198
""").encode('ascii')
199199
elif entry_name in NODE_OTHER_BINS:
200-
entry_points[NODE_OTHER_BINS[entry_name][0]] = f'nodejs.{NODE_OTHER_BINS[entry_name][0]}:main'
200+
# entry_points[NODE_OTHER_BINS[entry_name][0]] = f'nodejs.{NODE_OTHER_BINS[entry_name][0]}:main'
201201
contents[f'nodejs/{NODE_OTHER_BINS[entry_name][0]}.py'] = cleandoc(f"""
202202
import os, sys, subprocess
203203
@@ -245,6 +245,8 @@ def main():
245245
'Node.js Homepage, https://nodejs.org',
246246
],
247247
'Requires-Python': '~=3.5',
248+
'Provides-Extra': 'cmd',
249+
'Requires-Dist': "nodejs-cmd; extra == 'cmd'",
248250
},
249251
description=description,
250252
contents=contents,

nodejs-cmd/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2022 Sam Willis
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

nodejs-cmd/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Additional Standard Command Line Commands For "nodejs-bin"
2+
3+
This package provides the `node`, `npm` and `npx` commands for the (nodejs-bin project)[https://pypi.org/project/nodejs-bin/].
4+
5+
It should not be installed directly, but rather as an option when installing the `nodejs-bin` package:
6+
7+
```shell
8+
pip install 'nodejs-bin[cmd]'
9+
```

nodejs-cmd/nodejs_cmd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from nodejs import node, npm, npx
2+
3+
def node_main():
4+
node.main()
5+
6+
def npm_main():
7+
npm.main()
8+
9+
def npx_main():
10+
npx.main()

nodejs-cmd/setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from setuptools import setup
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setup(
7+
name='nodejs-cmd',
8+
version='0.0.1a',
9+
author="Sam Willis",
10+
description="Additional Standard Command Line Commands For nodejs-bin",
11+
long_description=long_description,
12+
long_description_content_type="text/markdown",
13+
url="https://github.com/samwillis/nodejs-pypi",
14+
py_modules=['nodejs_cmd'],
15+
classifiers=[
16+
"License :: OSI Approved :: MIT License",
17+
"Operating System :: OS Independent",
18+
],
19+
python_requires='~=3.5',
20+
entry_points={
21+
'console_scripts': [
22+
'node = nodejs_cmd:node_main',
23+
'npm = nodejs_cmd:npm_main',
24+
'npx = nodejs_cmd:npx_main',
25+
],
26+
},
27+
)

0 commit comments

Comments
 (0)