Skip to content

Python model for Fortran package manifests

License

Notifications You must be signed in to change notification settings

fortran-lang/fpm-metadata

Repository files navigation

Python model of the Fortran package manager

Latest release PyPI License CI status Codecov

This project provides a pydantic model of the fpm package manifest format used in the Fortran package manager.

Installation

Install this project with pip

pip install git+https://github.com/fortran-lang/fpm-metadata

Usage

You can read a package manifest with your TOML library of choice and construct a manifest object from it which allows to access all package entries directly in Python

>>> from fpm.metadata import Manifest
>>> from tomlkit import loads
>>> with open("fpm.toml") as fh:
...     package = Manifest(**loads(fh.read()))
...
>>> package.name
'fpm'
>>> package.version
'0.2.0'

Alternatively, you can use the load_manifest function to read a package manifest

>>> from pathlib import Path
>>> from fpm.metadata import load_manifest
>>> package = load_manifest(Path("fpm.toml"))
>>> package.name
'fpm'
>>> package.version
'0.2.0'

Finally, you can dump a package manifest to a TOML string using the dump_manifest function

>>> from pathlib import Path
>>> from fpm.metadata import dump_manifest, load_manifest
>>> package = load_manifest(Path("fpm.toml"))
>>> print(dump_manifest(package))
name = "fpm"
version = "0.2.0"
...

Development

This project is hosted on GitHub at fortran-lang/fpm-metadata. Obtain the source by cloning the repository with

git clone https://github.com/fortran-lang/fpm-metadata
cd fpm-metadata

We recommend using a conda environment to install the package. You can setup the environment manager using a mambaforge installer. Install the required dependencies from the conda-forge channel.

mamba env create -n devel -f environment.yml
mamba activate devel

Install this project with pip in the environment

pip install .

Add the option -e for installing in development mode.

The following dependencies are required

You can check your installation by running the test suite with

pytest tests/ --pyargs fpm.metadata --doctest-modules

For code formatting black is used:

black src/ tests/

Contributing

This is a volunteer open source projects and contributions are always welcome. Please, take a moment to read the contributing guidelines.

License

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “as is” basis, without warranties or conditions of any kind, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.