Skip to content

Commit

Permalink
Use Meson to build and install (#133)
Browse files Browse the repository at this point in the history
Copy fract4dc instead of linking else pylint fails on GitHub.
  • Loading branch information
cjmayo authored Mar 23, 2024
1 parent a94f8e7 commit 4feced8
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 297 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/test-gnofract4d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install macOS packages
if: ${{ runner.os == 'macOS' }}
run: brew install gtk4 pygobject3
run: brew install gtk4 ninja pygobject3
# Prevent delay caused by:
# `brew cleanup` has not been run in 30 days, running now...
env:
Expand All @@ -43,16 +43,18 @@ jobs:
# libxml2-utils provides xmllint for xml-stripblanks in gresource.xml
run: |
sudo apt update
sudo apt install dbus-x11 gir1.2-gtk-4.0 gvfs libgirepository1.0-dev libxml2-utils xvfb
sudo apt install dbus-x11 gir1.2-gtk-4.0 gvfs libgirepository1.0-dev libxml2-utils ninja-build xvfb
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Tox and any other PyPI packages
run: pip install tox
run: pip install meson pytest tox
- name: Build
run: python setup.py build
- name: Run Tox (macOS)
run: |
meson setup _build
meson compile -C _build
- name: Run Tox (MacOS)
if: ${{ runner.os == 'macOS' }}
run: tox -e ${{ matrix.toxenv }}
- name: Run Tox (Linux)
Expand All @@ -79,10 +81,12 @@ jobs:
# libglib2.0-dev-bin provides glib-compile-resources
run: |
sudo apt update
sudo apt install gir1.2-gtk-4.0 libglib2.0-dev-bin libxml2-utils python3-gi
- name: Install Tox
run: pip install tox
sudo apt install gir1.2-gtk-4.0 libglib2.0-dev-bin libxml2-utils ninja-build python3-gi
- name: Install Tox and any other PyPI packages
run: pip install meson pytest tox
- name: Build
run: python setup.py build
run: |
meson setup _build
meson compile -C _build
- name: Run ${{ matrix.toxenv }}
run: tox -e ${{ matrix.toxenv }}
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ Basic Installation

Run:

./setup.py build
meson setup --prefix ~/.local/ _build
meson compile -C _build

You can then run Gnofract 4D in the local directory:

./gnofract4d

Alternatively to build and install Gnofract 4D type:
Alternatively to install Gnofract 4D type:

pip3 install gnofract4d-4.3.tar.gz
meson install -C _build

You can then run it by clicking on the desktop icon or typing:

Expand All @@ -44,22 +45,22 @@ On Debian/Ubuntu, these can be installed with:

To build from source you also need:

- Meson and Ninja
- A C++ compiler
- headers for libpng and libjpeg
- Python headers
- glib-compile-resources and optionally xmllint
- pkg-config
- Python setuptools package

On Debian/Ubuntu, these can be installed with:

sudo apt install build-essential libglib2.0-dev-bin libjpeg-dev libpng-dev libpython3-dev libxml2-utils pkg-config python3-setuptools
sudo apt install build-essential libglib2.0-dev-bin libjpeg-dev libpng-dev libpython3-dev libxml2-utils meson pkg-config

If FFmpeg is installed it will be possible to create videos.

On macOS, you can install the dependencies using brew:

brew install librsvg python3 pkg-config gtk4 pygobject3 libpng jpeg
brew install librsvg meson python3 pkg-config gtk4 pygobject3 libpng jpeg

Testing
=======
Expand Down
2 changes: 2 additions & 0 deletions _conf_data.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_DATADIR = "@app_datadir@"
VERSION = "@version@"
6 changes: 3 additions & 3 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

rm -rf build
rm fract4d/*.so
./setup.py build
rm -rf _build
meson setup --prefix ~/.local/ _build
meson compile -C _build
5 changes: 2 additions & 3 deletions docker/bin/run_builds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3.6 ./setup.py build && \
python3.7 ./setup.py build && \
python3.8 ./setup.py build"
docker-compose exec server bash -c "meson setup --prefix ~/.local/ _build && \
meson compile -C _build"
docker-compose down
3 changes: 1 addition & 2 deletions docker/bin/run_clean.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

docker-compose up -d
docker-compose exec server bash -c "rm -rf build && \
rm fract4d/*.so && \
docker-compose exec server bash -c "rm -rf _build && \
rm -rf .pytest_cache && \
rm -rf .tox"
docker-compose down
5 changes: 3 additions & 2 deletions docker/bin/run_pylint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3 setup.py build && \
docker-compose exec server bash -c "rm -rf _build"
docker-compose exec server bash -c "meson setup --prefix ~/.local/ _build && \
meson compile -C _build && \
./bin/pylint.sh"
docker-compose down
3 changes: 2 additions & 1 deletion docker/bin/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3 setup.py build && \
docker-compose exec server bash -c "meson setup --prefix ~/.local/ _build && \
meson compile -C _build && \
pytest fract4d fract4dgui fract4d_compiler test.py"
docker-compose down
5 changes: 2 additions & 3 deletions docker/bin/run_tox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

docker-compose up -d --build
docker-compose exec server bash -c "rm -rf build"
docker-compose exec server bash -c "python3.6 ./setup.py build && \
python3.7 ./setup.py build && \
python3.8 ./setup.py build && \
docker-compose exec server bash -c "meson setup --prefix ~/.local/ _build && \
meson compile -C _build && \
tox"
docker-compose down
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

*Note: for all exmples make sure you have performed the setup previously:*
```
./setup.py build
meson setup --prefix ~/.local/ _build
meson compile -C _build
```

## Python examples
Expand Down
55 changes: 55 additions & 0 deletions fract4d/c/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
jpeg = dependency('libjpeg')
png = dependency('libpng')

fract4dc = py.extension_module('fract4dc',
'fract4dmodule.cpp',
'fract_stdlib.cpp',

'fract4dc/colormaps.cpp',
'fract4dc/loaders.cpp',
'fract4dc/sites.cpp',
'fract4dc/images.cpp',
'fract4dc/calcs.cpp',
'fract4dc/workers.cpp',
'fract4dc/functions.cpp',
'fract4dc/arenas.cpp',
'fract4dc/utils.cpp',
'fract4dc/calcargs.cpp',
'fract4dc/pysite.cpp',

'fract4dc/controllers.cpp',

'model/calcfunc.cpp',
'model/fractfunc.cpp',
'model/site.cpp',
'model/image.cpp',
'model/imagewriter.cpp',
'model/imagereader.cpp',
'model/colormap.cpp',
'model/worker.cpp',
'model/STFractWorker.cpp',
'model/MTFractWorker.cpp',
'model/pointfunc.cpp',
'model/stats.cpp',
'model/colorutils.cpp',
'model/imageutils.cpp',

dependencies: [jpeg, png, py_dep],
include_directories: ['fract4dc', 'model'],
cpp_args: ['-DTHREADS=1', '-DPNG_ENABLED=1', '-DJPG_ENABLED=1'],
gnu_symbol_visibility: 'default',
install: true,
subdir: 'fract4d',
)

install_headers(
'fract_stdlib.h',
'pf.h',
install_dir: py.get_install_dir() / 'fract4d/c',
)

install_headers(
'model/colorutils.h',
'model/imageutils.h',
install_dir: py.get_install_dir() / 'fract4d/c/model',
)
9 changes: 6 additions & 3 deletions fract4d/fractconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import os
import sys

try:
from ._conf_data import APP_DATADIR
except ImportError:
APP_DATADIR = ".."

CONFIG_FILE = "~/.gnofract4d"


Expand Down Expand Up @@ -132,9 +137,7 @@ def ensure_contains(self, section, required_item):
def get_data_path(subpath=""):
# find where data files are present.
# use share path one level up from module location
moduledir = os.path.dirname(sys.modules[__name__].__file__)
path = os.path.normpath(os.path.join(
moduledir, "../../../../share/gnofract4d", subpath))
path = os.path.join(APP_DATADIR, subpath)
#print("Looking in %s" % path)
return path

Expand Down
6 changes: 4 additions & 2 deletions fract4d/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import sys
from . import fractal as fract4d_fractal

# version of Gnofract 4D
VERSION = '4.3'
try:
from ._conf_data import VERSION
except ImportError:
VERSION = "dev"

POSITION_ARGUMENTS = ("xcenter", "ycenter", "zcenter", "wcenter",
"xyangle", "xzangle", "xwangle", "yzangle", "ywangle", "zwangle",
Expand Down
5 changes: 3 additions & 2 deletions gnofract4d
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ except ImportError as err:
print(_("Can't import a required module."))
if "fract4dc" in str(err):
print(_("If you haven't set up Gnofract 4D yet, run:\n"
"./setup.py build\n"))
print(_("Error was: '%s'") % err)
" meson setup _build\n"
" meson compile -C _build\n"))
print(_("Error was: '%s' ") % err)
sys.exit(1)

def main(args):
Expand Down
Loading

0 comments on commit 4feced8

Please sign in to comment.