Skip to content

Commit

Permalink
Build babelized projects with meson (#90)
Browse files Browse the repository at this point in the history
* Move zest.releaser config to pyproject.toml

* Set up Meson build for a single Fortran component

This is WIP, but the project files are in the right place.

* Remove setuptools config from pyproject.toml

* Set version, but not readme, in dynamic metadata

It looks like meson doesn't allow readme in dynamic metadata.

Be sure to install _version.py.

* Read package dependencies from babel.toml file

I got help on this from https://stackoverflow.com/a/30517735.

* Filter dependencies on default empty string

* Update bmi-example-fortran

* Get the name of the first component to babelize

This is a temporary fix until I can handle multiple components
in the `meson.build` file.

* Set --no-build-isolation for editable installs

This is a *meson-python* behavior. See https://meson-python.readthedocs.io/en/stable/how-to-guides/editable-installs.html

* Include package requirements for example

* use conda; install bmiheatf in _inst; create bmiheatf.pc

* add bmiheatf as a dependency

* remove requirements from babel.toml

* install build tools on a per language basis

* add bmi-tester as a testing dependency

* install language-specific build tools

* create a pkg-config file for heatf; back to using conda

* add c and cpp to builds

* update setup-miniconda

* install pkg-config in test environment

* fix heatf pkg-config file and bmic, bmicxx pkg-config names

* update c, cxx submodules

* back to lowercase for pkg-config names

* use setuptools for pure-python projects

* build multiple extension; remove bmiheat dependency

* remove setup.py, setup_utils.py

* bump versions of setup-miniconda, checkout

* remove meson.build for python projects

* remove setup.py setup_utils.py from prettification

* Update bmi-example-fortran to tip of mdpiper/use-pkgconfig branch

* Remove hardcoded pkg-config files

* Clean lint

* Add a news fragment

* Update bmi-example-fortran to v2.1.3

* Remove Makefile; trim .gitignore

* Include brief instructions for installing from source

---------

Co-authored-by: mcflugen <mcflugen@gmail.com>
  • Loading branch information
mdpiper and mcflugen authored Mar 15, 2024
1 parent 330625e commit 1599243
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 382 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-langs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ jobs:
with:
submodules: true

- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge
channel-priority: true

- name: Install dependencies
run: python -m pip install nox tomli

- name: Install compilers
run: mamba install c-compiler cxx-compiler fortran-compiler
if: matrix.language != 'python'
run: conda install ${{ matrix.language }}-compiler cmake make

- name: Run the language tests
run: nox -s "test-langs-${{ matrix.python-version }}(lang='${{ matrix.language }}')" --python ${{ matrix.python-version }} --verbose
Expand Down
4 changes: 4 additions & 0 deletions babelizer/data/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def write_api_yaml(folderpath, **kwds):
if "Not open source" == "{{ cookiecutter.open_source_license }}":
remove_file("LICENSE")

{%- if cookiecutter.language == 'python' %}
remove_file("meson.build")
{%- endif %}

datadir = Path("meta")
package_datadir = Path("{{ cookiecutter.package_name }}") / "data"
if not package_datadir.exists():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
python-version: [{{ cookiecutter.ci.python_version | join(", ") }}]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ '{{' }} matrix.python-version {{ '}}' }}
Expand All @@ -39,16 +39,15 @@ jobs:
- name: Install requirements
run: |
conda install mamba
mamba install --file=requirements-build.txt --file=requirements-library.txt
mamba list
conda install --file=requirements-build.txt --file=requirements-library.txt
conda list
- name: Build and install package
run: |
pip install -e .
- name: Install testing dependencies
run: mamba install --file=requirements-testing.txt
run: conda install --file=requirements-testing.txt

- name: Test
run: |
Expand Down
105 changes: 8 additions & 97 deletions babelizer/data/{{cookiecutter.package_name}}/.gitignore
Original file line number Diff line number Diff line change
@@ -1,114 +1,25 @@
# Byte-compiled / optimized / DLL files
.DS_Store
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
.ipynb_checkpoints
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
# lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
docs/_generated/
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# nox virtual envs
.nox/
*.so
*.o
*.mod
*.smod

{% if cookiecutter.language == 'fortran' -%}
{%- if cookiecutter.language != 'python' -%}
{%- for babelized_class in cookiecutter.components %}
# Fortran files generated by the babelizer
{{cookiecutter.package_name}}/lib/bmi_interoperability.mod
{{cookiecutter.package_name}}/lib/bmi_interoperability.smod
{{cookiecutter.package_name}}/lib/bmi_interoperability.o
{{cookiecutter.package_name}}/lib/{{ babelized_class|lower }}.c
{%- endfor %}
{%- endif %}
94 changes: 0 additions & 94 deletions babelizer/data/{{cookiecutter.package_name}}/Makefile

This file was deleted.

44 changes: 34 additions & 10 deletions babelizer/data/{{cookiecutter.package_name}}/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,44 @@ Quickstart

.. start-quickstart
To get started you will need to install the *{{ cookiecutter.package_name }}* package, which is currently distributed
on *conda-forge*. The easiest way to install *{{ cookiecutter.package_name }}* into your current environment using either *mamba* or *conda*.
To get started you will need to install the *{{ cookiecutter.package_name }}* package.
Here are two ways to do so.

.. tab:: mamba
Install from conda-forge
------------------------

.. code:: bash
If the *{{ cookiecutter.package_name }}* package is distributed on *conda-forge*, install it into your current environment with *conda*.

mamba install {{ cookiecutter.package_name }}
.. code:: bash
.. tab:: conda
conda install -c conda-forge {{ cookiecutter.package_name }}
.. code:: bash
Install from source
-------------------

You can build and install the *{{ cookiecutter.package_name }}* package from source using *conda* and *pip*.

First, from the source directory, install package dependencies into your current environment with *conda*.

.. code:: bash
conda install -c conda-forge --file requirements.txt --file requirements-build.txt --file requirements-library.txt
Then install the package itself with *pip*.
{%- if cookiecutter.language == 'python' %}

conda install {{ cookiecutter.package_name }}
.. code:: bash
pip install -e .
{%- else %}

.. code:: bash
pip install --no-build-isolation --editable .
Note that for an editable install, the ``--no-build-isolation`` flag must be set.
{%- endif %}

.. end-quickstart
Expand All @@ -87,8 +111,8 @@ Usage

.. start-usage
There are two ways to use the data components provided by this package: directly through it's Basic
Model Interface, or as a PyMT plugin.
There are two ways to use the components provided by this package: directly through its Basic
Model Interface (BMI), or as a PyMT plugin.

A BMI is provided by each component in this package:
{%- for babelized_class, component in cookiecutter.components|dictsort -%}
Expand Down
Loading

0 comments on commit 1599243

Please sign in to comment.