diff --git a/examples/root/python/example.py b/examples/root/python/example.py index 0ba4de0..b5c02b3 100644 --- a/examples/root/python/example.py +++ b/examples/root/python/example.py @@ -4,8 +4,7 @@ import ROOT import numpy as np -#import dunestyle.root as dunestyle -import dunestyle as dunestyle +import dunestyle.root as dunestyle c = ROOT.TCanvas() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e2a4801 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..e2b1b6e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,40 @@ +[metadata] +name = dune-plot-style +version = 0.0.1 +author = Young Dune +author_email = dune-young@fnal.gov +description = Plot styling tools +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/DUNE/dune-plot-style +project_urls = +bug_tracker = https://github.com/DUNE/dune-plot-style/issues +classifiers = +programming language :: Python :: 3 +operating system :: OS Independent + +[options] +python_requires = >=3.6 +install_requires = +package_dir= + dunestyle = src + dunestyle.matplotlib = src/matplotlib/python + dunestyle.root = src/root/python + dunestyle.data = src/root/cpp/include + dunestyle.stylelib = src/matplotlib/stylelib +packages = + dunestyle + dunestyle.matplotlib + dunestyle.root + dunestyle.data + dunestyle.stylelib + +[options.package_data] +dunestyle.data = + *.h +dunestyle.stylelib = + *.mplstyle + + +#[options.packages.find] +#where=src diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/matplotlib/__init__.py b/src/matplotlib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/matplotlib/python/__init__.py b/src/matplotlib/python/__init__.py new file mode 100644 index 0000000..e899562 --- /dev/null +++ b/src/matplotlib/python/__init__.py @@ -0,0 +1,11 @@ +try: + # this handles the arrangement that comes out + # when dune-plot-style is set up standalone by using `pip install`. + # (the UPS product sets $MPLCONFIGDIR directly in its setup process.) + import os, os.path, pathlib + import dunestyle.stylelib as module + os.environ["MPLCONFIGDIR"] = str(pathlib.Path(module.__path__[0]).parent.absolute()) + (":" + os.environ["MPLCONFIGDIR"] if "MPLCONFIGDIR" in os.environ else "") +except: + pass + +from .dunestyle import * diff --git a/matplotlib/python/dunestyle.py b/src/matplotlib/python/dunestyle.py similarity index 100% rename from matplotlib/python/dunestyle.py rename to src/matplotlib/python/dunestyle.py diff --git a/matplotlib/stylelib/dune.mplstyle b/src/matplotlib/stylelib/dune.mplstyle similarity index 100% rename from matplotlib/stylelib/dune.mplstyle rename to src/matplotlib/stylelib/dune.mplstyle diff --git a/src/root/__init__.py b/src/root/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/root/cpp/include/DUNEStyle.h b/src/root/cpp/include/DUNEStyle.h similarity index 100% rename from root/cpp/include/DUNEStyle.h rename to src/root/cpp/include/DUNEStyle.h diff --git a/src/root/python/__init__.py b/src/root/python/__init__.py new file mode 100644 index 0000000..1ad6d0e --- /dev/null +++ b/src/root/python/__init__.py @@ -0,0 +1 @@ +from .dunestyle import * diff --git a/root/python/dunestyle.py b/src/root/python/dunestyle.py similarity index 86% rename from root/python/dunestyle.py rename to src/root/python/dunestyle.py index 409ea2b..cf2243e 100644 --- a/root/python/dunestyle.py +++ b/src/root/python/dunestyle.py @@ -18,6 +18,7 @@ import builtins CPP_HEADER = "DUNEStyle.h" +UPS_VAR = "DUNE_PLOT_STYLE_INC" def enable(): @@ -25,10 +26,16 @@ def enable(): import sys import ROOT + search_paths = [os.path.curdir, os.path.join(os.path.dirname(__file__), "../cpp/include")] - ups_var = "DUNE_PLOT_STYLE_INC" - if ups_var in os.environ: - search_paths.insert(0, os.environ[ups_var]) + try: + from dunestyle import data as data_module + search_paths.insert(0, data_module.__path__[0]) + except: + pass + + if UPS_VAR in os.environ: + search_paths.insert(0, os.environ[UPS_VAR]) found_path = None for search_paths in search_paths: diff --git a/ups/dune-plot-style.table b/ups/dune-plot-style.table new file mode 100644 index 0000000..5047f1d --- /dev/null +++ b/ups/dune-plot-style.table @@ -0,0 +1,19 @@ +FILE=TABLE +PRODUCT=dune-plot-style +VERSION=XXVERSIONXX + +#--------------------- +FLAVOR=NULL +QUALIFIERS = "" + +ACTION=SETUP + + setupEnv() + prodDir() + + EnvSet(DUNE-PLOT-STYLE_VERSION, ${UPS_PROD_VERSION} ) + EnvSet(DUNE-PLOT-STYLE_DIR, ${UPS_PROD_DIR} ) + EnvSet(DUNE-PLOT-STYLE_INC, ${UPS_PROD_DIR}/include) + + PathPrepend(PYTHONPATH, ${UPS_PROD_DIR}/python) + PathPrepend(MPLCONFIGDIR, ${UPS_PROD_DIR}/stylelib/) diff --git a/ups/make_dune-plot-style_ups_product.sh b/ups/make_dune-plot-style_ups_product.sh new file mode 100644 index 0000000..214f922 --- /dev/null +++ b/ups/make_dune-plot-style_ups_product.sh @@ -0,0 +1,137 @@ +#!/bin/bash + +# heavily inspired by NOvAs ups product making script +# 2022-07-12 + +# print usage +usage() { + + echo "" + echo "Usage is:" + echo " sh make_dune-plot-style_ups_product.sh " + echo "" + echo "The version number should be of the form vXX_XX." + echo "" + exit -1 + +} + +# setup +# ----------------------------------------------------------------------------- + +if [ ${#@} != 1 ]; then + usage +fi + +# useful vars +path=/grid/fermiapp/products/dune/ +reponame="dune-plot-style" +version=$1 +tmpdir=/tmp/${reponame}_${version} + +if [[ ! ${version} =~ v[0-9][0-9]_[0-9][0-9] ]]; then + echo "" + echo "Version pattern not allowed." + usage +fi + +echo "Tagging ${reponame} ${version}" + +source ${path}/setup_dune.sh +setup upd + +echo "Printing active products" +echo "-------------------------------------------" +ups active +echo "-------------------------------------------" + +# check if the first argument is a valid path +if [ -d "${tmpdir}" ]; then + echo "${tmpdir} is already exists! Cannot do clean checkout!" + echo "Aborting" + exit -1 +fi + +# pull the latest version of the git repo and put it in the product directory +# ----------------------------------------------------------------------------- + +# clone to temp directory +git clone -b ${version} git@github.com:DUNE/${reponame}.git ${tmpdir}/${reponame}-preorg + +# need to do some reogranising for the ups product +mkdir -p ${tmpdir}/${reponame}/python/dunestyle/matplotlib +mkdir -p ${tmpdir}/${reponame}/python/dunestyle/root +mv ${tmpdir}/${reponame}-preorg/src/matplotlib/stylelib ${tmpdir}/${reponame}/ +mv ${tmpdir}/${reponame}-preorg/src/root/cpp/include ${tmpdir}/${reponame}/ +mv ${tmpdir}/${reponame}-preorg/src/__init__.py ${tmpdir}/${reponame}/python/dunestyle/ +mv ${tmpdir}/${reponame}-preorg/src/matplotlib/python/* ${tmpdir}/${reponame}/python/dunestyle/matplotlib +mv ${tmpdir}/${reponame}-preorg/src/root/python/* ${tmpdir}/${reponame}/python/dunestyle/root + +tree ${tmpdir}/${reponame} + +#proddir=${path}/${reponame} +#dest=${proddir}/${version}/NULL +# +#echo "$reponame will be created in $dest" +# +#if [ ! -d "${proddir}" ]; then +# mkdir -p ${proddir} +#fi +# +## offer option to overwrite a product if it exists, though +## in general we won't want to do this +#if [ -d "${proddir}/${version}" ]; then +# echo "" +# echo "Product ${reponame} with version ${version} already exists." +# echo "Making it again will over-write the existing one." +# echo "" +# read -p "Are you sure you want to proceed (y/n)? " -n 1 -r +# echo +# if [[ $REPLY =~ ^[Yy]$ ]] +# then +# echo "OK. If you say so." +# else +# echo "The script will now abort. Try again with a different version." +# exit -1 +# fi +#fi +# +## now copy the code to it's location in the /grid area +#mkdir -p ${dest} +#rsync --exclude '*~' --exclude '*.git' -rL $tmpdir/${reponame}/* ${dest} +# +## update the ups table to give the correct version number +#ups_table=${dest}/ups/${reponame}.table +#if [ ! -f "${ups_table}" ] ; then +# echo "" +# echo "Error! UPS table ${ups_table} does not exist!" +# echo "" +# exit -1 +#fi +# +#echo "Updating table file" +# +#sed -i -e "s:XXVERSIONXX:${version}:" \ +# ${ups_table} +# +#echo"Declaring product ${reponame} with version ${version} to UPS." +# +## declare to ups +#ups declare -f NULL -z ${path} \ +# -r ${path}/${reponame}/${version}/NULL \ +# -m ${reponame}.table \ +# ${reponame} ${version} +# +#retval=$? +#test $retval -ne 0 && echo "Error! 'ups declare' returned non-zero - BAILING" && exit 1 +# +## add to upd +#cd ${proddir}/${version}/NULL/ +# +#upd addproduct ${reponame} ${version} +#retval=$? +#test $retval -ne 0 && echo "Error! 'upd addproduct' returned non-zero - BAILING" && exit 1 +# +#rm -rf ${tmpdir} +# +#echo "Done"