Warning
Deprecated: this action gets no further development. The maintainers
will archive this repository; references to its existing tags and
commits keep working after that.
lfreleng-actions/build-metadata-action
replaces it: see
Migrating to build-metadata-action.
Extracts the Python project name and derives the Python package name.
The action probes the project for metadata in the following order, selecting the first source that yields a project name. The action skips a present source that carries no usable name and continues with the next one:
pyproject.toml—[project] name(PEP 621, preferred), or[tool.poetry] namewhen the file has no[project] namesetup.cfg—[metadata] name(legacy pbr / setuptools projects)setup.py— the literalnamekeyword passed tosetup()(legacy setuptools)
The action parses pyproject.toml with tomllib and reads setup.py
with the ast module, so any valid quoting or spacing works, and a
name in an unrelated TOML table (e.g. [[tool.uv.index]]) or an
identifier such as package_name does not count. For setup.py, the
action resolves imports and accepts a setup() call from a packaging
module (setuptools, distutils.core, numpy.distutils.core or
skbuild) under any alias; a call such as helper.setup(name="x")
does not count. A setup.py name that is not a string literal (e.g.
name=NAME) yields no name.
The action runs these parsers with a Python 3.11 or newer interpreter
it sets up itself through actions/setup-python, rather than whichever
python3 comes first on the caller's PATH, and leaves the caller's
PATH and environment unchanged. Where a parser cannot read the file
(e.g. a setup.py in Python 2 syntax), or the action cannot set up
that interpreter or run it in the job's container, a best-effort line
match stands in, never the caller's python3. That match reads the
same TOML tables for pyproject.toml, and takes the first quoted
whole-word name= in setup.py. For every source, the action
rejects any name holding characters other than letters, digits, .,
_ and -, and skips a file that holds a raw NUL byte, which none
of the three formats allows.
This tolerates a pyproject.toml that contains a [build-system]
table (PEP 517) but no [project] name — the common pbr / setuptools
layout — by falling through to setup.cfg and then setup.py rather
than aborting. If no source yields a name, the action fails rather
than emitting an empty value.
The setup.cfg and setup.py paths exist to support legacy projects
(e.g. those still using pbr) that have not migrated to PEP 621
metadata in pyproject.toml.
An example workflow step using this action:
steps:
# Code checkout performed in earlier step
- name: Fetch Python project/package name
uses: lfreleng-actions/python-project-name-action@main| Variable Name | Required | Description |
|---|---|---|
| path_prefix | False | Path/directory to Python project code |
| Output Variable | Mandatory | Value |
|---|---|---|
python_project_file |
Yes | File used to extract metadata: pyproject.toml/setup.cfg/setup.py |
python_project_name |
Yes | Extracted from pyproject.toml, setup.cfg or setup.py |
python_package_name |
Yes | Derived from the project name (dashes become underscores) |
source |
Yes | Source file used (pyproject.toml, setup.cfg or setup.py) |
Use lfreleng-actions/build-metadata-action v0.13.5 or later. Earlier
releases can take a setup.py name from the wrong identifier
(build-metadata-action#227).
Replace the step in the usage example above with:
- name: Fetch Python project/package name
id: metadata
uses: lfreleng-actions/build-metadata-action@0000000000000000000000000000000000000000 # REPLACE: vX.Y.Z
with:
project_type: 'python'
use_version_extract: 'false'
include_environment: 'false'
artifact_upload: 'false'
output_format: ''
python_offline_mode: 'true'Pin the action to the commit SHA of the release you choose, in place of
the placeholder. Setting project_type stops a package.json or
go.mod beside the Python files from naming another project. The other
five inputs keep the step as quiet as this action: no version lookup,
no probe of the runner, no uploaded artefact, no job summary and no
query for current Python releases. Add path_prefix where the project
does not sit at the repository root.
The step sets up Go and builds the action's binary on each run, so expect it to take longer than this action did.
| This action | build-metadata-action |
|---|---|
python_project_name |
project_name |
python_package_name |
python_package_name |
python_project_file |
python_metadata_source |
source |
python_metadata_source |
- The package name. This action derives
python_package_nameby replacing dashes in the project name with underscores. Inbuild-metadata-action,python_package_namekeeps the name as the project declares it:my-cool-pkgstaysmy-cool-pkg. - A project with no name. This action fails, while
build-metadata-actionsucceeds and leavesproject_nameempty. A caller that needs a name has to check for one. - Characters in the name. This action rejects a name holding any
character other than letters, digits,
.,_and-, then tries the next file or fails.build-metadata-actionreports the name as the project declares it:name = "bad name!"givesbad name!. A caller that relied on that check has to make it itself, and should pass the output to a script throughenv:, never by expanding it inside arun:block.