Skip to content

Commit

Permalink
Merge pull request #12 from DUNE/feature/alister1_packaging
Browse files Browse the repository at this point in the history
Feature/alister1 packaging
  • Loading branch information
admlw authored Aug 26, 2022
2 parents fb3c400 + e10a451 commit b1aecf1
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 5 deletions.
3 changes: 1 addition & 2 deletions examples/root/python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools",
"wheel"
]
build-backend = "setuptools.build_meta"
40 changes: 40 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Empty file added src/__init__.py
Empty file.
Empty file added src/matplotlib/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions src/matplotlib/python/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *
File renamed without changes.
File renamed without changes.
Empty file added src/root/__init__.py
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions src/root/python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .dunestyle import *
13 changes: 10 additions & 3 deletions root/python/dunestyle.py → src/root/python/dunestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@
import builtins

CPP_HEADER = "DUNEStyle.h"
UPS_VAR = "DUNE_PLOT_STYLE_INC"


def enable():
import os.path
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:
Expand Down
19 changes: 19 additions & 0 deletions ups/dune-plot-style.table
Original file line number Diff line number Diff line change
@@ -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/)
137 changes: 137 additions & 0 deletions ups/make_dune-plot-style_ups_product.sh
Original file line number Diff line number Diff line change
@@ -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 <version_number>"
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"

0 comments on commit b1aecf1

Please sign in to comment.