Skip to content

Repository files navigation

🐍 Python Project/Package Names

Extracts the Python project name and derives the Python package name.

python-project-name-action

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:

  1. pyproject.toml[project] name (PEP 621, preferred)
  2. setup.cfg[metadata] name (legacy pbr / setuptools projects)
  3. setup.pyname="…" literal (legacy setuptools)

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.

Usage Example

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

 Inputs

Variable Name Required Description
PATH_PREFIX False Path/directory to Python project code

Outputs

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)

The action also exports the same values as environment variables (lowercase names) for use in later steps within the same job.

About

Extracts Python project name and derives the package name

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors