Exploring the hatch-nodejs-version Package for Seamless Node.js Integration in Python Projects
Are you looking for a simple and efficient way to integrate Node.js into your Python projects? Look no further! The hatch-nodejs-version package provides a seamless solution for managing package versions and metadata using the Node.js package.json
file. In this article, we will explore the key features of this package, the installation process, and how it can enhance your Python development workflow.
Package Installation
To begin using hatch-nodejs-version, ensure that it is defined within the build-system.requires
field in your pyproject.toml
file. Here’s an example of how to add it to your project:
#toml
[build-system]
requires = ["hatchling", "hatch-nodejs-version"]
build-backend = "hatchling.build"
Version Source Plugin
The hatch-nodejs-version package provides a version source plugin that allows you to read and write package versions directly from the version
field in the Node.js package.json
file. You can configure this plugin in either your pyproject.toml
or hatch.toml
file. Simply add the following section to your chosen configuration file:
#toml
[tool.hatch.version]
source = "nodejs"
Semver Support
The version source plugin follows the Semver specification for versioning, which includes the major
, minor
, patch
, and pre-release
sections. It ensures semantic consistency between Node.js and Python projects. However, please note that normalization may differ depending on the choice of delimiters.
Version Source Options
The version source plugin also provides additional configuration options. You can specify a custom path to the package.json
file using the path
option.
| Option | Type | Default | Description |
|——–|——|———————|———————————————|
| path | str | “package.json” | Relative path to the package.json
file. |
Metadata Hook Plugin
In addition to the version source plugin, the hatch-nodejs-version package also includes a metadata hook plugin. This plugin allows you to extract PEP 621 metadata from the Node.js package.json
file. To configure the metadata hook plugin, add the following section to your pyproject.toml
or hatch.toml
file:
#toml
[tool.hatch.metadata.hooks.nodejs]
Metadata Hook Options
The metadata hook plugin provides various configuration options to customize its behaviour. You can specify a custom path to the package.json
file using the path
option. Additionally, you can choose which fields from the pyproject.toml
file should be populated from their counterparts in the package.json
file using the fields
option. The plugin also allows you to consider contributors as maintainers instead of authors, and customize the labels for bugs, homepage, and repository URLs.
| Option | Type | Default | Description |
|——————————-|—————–|——————|——————————————————————————————————————————————-|
| path | str | “package.json” | Relative path to the package.json
file. |
| fields | list of str | None | Optional list of pyproject.toml
fields to take from their counterparts in package.json
. If missing, take all of the available fields. |
| contributors-as-maintainers | bool | True | Whether contributors in package.json
should be considered maintainers (otherwise, treat them as authors). |
| bugs-label | str | “Bug Tracker” | The key in the URLs table of pyproject.toml
that is populated by the bugs
field in package.json
. |
| homepage-label | str | “Homepage” | The key in the URLs table of pyproject.toml
that is populated by the homepage
field in package.json
. |
| repository-label | str | “Repository” | The key in the URLs table of pyproject.toml
that is populated by the repository
field in package.json
. |
License
The hatch-nodejs-version package is distributed under the terms of the MIT license.
Summary
The hatch-nodejs-version package offers an easy way to integrate Node.js into Python projects, enabling seamless management of package versions and metadata. With its version source and metadata hook plugins, developers can read and write package versions from the Node.js package.json
file and extract PEP 621 metadata effortlessly. By leveraging this package, you can simplify your development workflow and enhance collaboration between Python and Node.js environments.
If you have any questions or would like to learn more about hatch-nodejs-version, feel free to explore the repository or reach out to the contributors.
Happy coding!
References
- hatch-nodejs-version Repository: GitHub
- Semver Specification: semver.org
- PEP 621: PEP 621 Specification
- Node.js Package.json Specification: docs.npmjs.com
(Note: This article is based on the information from the hatch-nodejs-version repository and its README documentation.)
Leave a Reply