From a69a449a430349722fc4531a5c736069189eadb0 Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Thu, 5 Sep 2019 15:08:10 -0400 Subject: [PATCH] Move setup files into separate bash scripts and adjust README * Treat Linux and Darwin differently --- README.md | 65 +++++++++++++------------------------ share/replace_and_rename.sh | 29 +++++++++++++++++ share/squash_history.sh | 6 ++++ 3 files changed, 58 insertions(+), 42 deletions(-) create mode 100755 share/replace_and_rename.sh create mode 100755 share/squash_history.sh diff --git a/README.md b/README.md index 469806b5..444a59b1 100644 --- a/README.md +++ b/README.md @@ -5,68 +5,47 @@ Initial Setup ------------- -**Caution**: The following instructions require the `util-linux` rename command. -Please confirm that you have the right version by running `rename --version`. -For the Perl rename command see instructions in the following section. - To adapt this skeleton for a new TRIQS application, the following steps are necessary: -* Create a repository, e.g. https://github.com/myuser/mynewapp +* Create a repository, e.g. https://github.com/username/appname -* Run the following commands in order after replacing myuser, mynewapp and MYNEWAPP accordingly +* Run the following commands in order after replacing **appname** accordingly ```bash -github_username=myuser -app_name=mynewapp -capital_name=MYNEWAPP - -git clone https://github.com/triqs/app4triqs --branch unstable ${app_name} -cd ${app_name} -git reset $(git commit-tree HEAD\^{tree} -m "Create ${app_name} from github.com/triqs/app4triqs skeleton") -git merge --allow-unrelated-histories -s ours HEAD@{1} -m "Track app4triqs skeleton" -find . -type f | grep -v .git | xargs sed -i 's/app4triqs/${app_name}/g; s/APP4TRIQS/${capital_name}/g' -find . -type d | grep -v .git | xargs rename app4triqs ${app_name} -find . -type f | grep -v .git | xargs rename app4triqs ${app_name} -git add -A && git commit -m "Adjust app4triqs skeleton for ${app_name}" -git remote set-url origin https://github.com/${github_username}/${app_name} -git remote add app4triqs_remote https://github.com/triqs/app4triqs -git remote update && git remote prune origin +git clone https://github.com/triqs/app4triqs --branch unstable appname +cd appname +./share/squash_history.sh +./share/replace_and_rename.sh appname +git add -A && git commit -m "Adjust app4triqs skeleton for appname" ``` -You can now push to your github repository +You can now add your github repository and push to it ```bash +git remote add origin https://github.com/username/appname +git remote update git push origin unstable ``` -### Perl rename command ### - -If you are using the Perl-based rename command you will need to - -```bash -find . -type d | grep -v .git | xargs rename 's/app4triqs/${app_name}/' -find . -type f | grep -v .git | xargs rename 's/app4triqs/${app_name}/' -``` - -### Github SSH interface ### - -If you prefer to use the SSH interface to the remote repository, -replace the http link accordingly - -``` -https://github.com/myuser/mynewapp --> git@github.com:myuser/mynewapp -``` +If you prefer to use the [SSH interface](https://help.github.com/en/articles/connecting-to-github-with-ssh) +to the remote repository, replace the http link with e.g. `git@github.com:username/appname`. ### Merging app4triqs skeleton updates ### -You can merge future changes to app4triqs into your project with the following commands +You can merge future changes to the app4triqs skeleton into your project with the following commands ```bash git remote update -git merge app4triqs_remote -m "Merge latest app4triqs skeleton changes" +git merge app4triqs_remote/unstable -m "Merge latest app4triqs skeleton changes" ``` If you should encounter any conflicts resolve them and `git commit`. +Finally we repeat the replace and rename command from the initial setup. + +```bash +./share/replace_and_rename.sh appname +git commit --amend +``` Getting Started --------------- @@ -74,15 +53,17 @@ Getting Started After setting up your application as described above you should customize the following files and directories according to your needs (replace app4triqs in the following by the name of your application) +* Adjust or remove the `README.md` and `doc/ChangeLog.md` file * In the `c++/app4triqs` subdirectory adjust the example files `app4triqs.hpp` and `app4triqs.cpp` or add your own source files. * In the `test/c++` subdirectory adjust the example test `basic.cpp` or add your own tests. * In the `python/app4triqs` subdirectory add your Python source files. Be sure to remove the `app4triqs_module_desc.py` file unless you want to generate a Python module from your C++ source code. -* In the `test/c++` subdirectory adjust the example test `basic.cpp` or add your own tests. +* In the `test/python` subdirectory adjust the example test `Basic.py` or add your own tests. * The build and install process is identical to the one outline [here](https://triqs.github.io/app4triqs/unstable/install.html). ### Optional ### ---------------- + * If you want to wrap C++ classes and/or functions provided in the `c++/app4triqs/app4triqs.hpp` rerun the `c++2py` tool with ```bash c++2py -r app4triqs_module_desc.py diff --git a/share/replace_and_rename.sh b/share/replace_and_rename.sh new file mode 100755 index 00000000..8ae0bab5 --- /dev/null +++ b/share/replace_and_rename.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +if [ $# -ne 1 ]; then + echo "Please pass the application name" + exit 1 +fi +app_name=$1 +capital_name=$(printf '%s' "$1" | awk '{ print toupper($0) }') + +# Move app4triqs directories if necessary +[ -d c++/app4triqs ] && mv c++/app4triqs c++/${app_name} +[ -d python/app4triqs ] && mv python/app4triqs python/${app_name} + +# Replace app4triqs and APP4TRIQS for our application in all files and filenames +if [ $(uname -s) == Linux ]; then + find . -type f \ + -not -path "./.git/*" \ + -not -path "*/replace_and_rename.sh" \ + -not -path "*/squash_history.sh" \ + -exec sed -i "s/app4triqs/${app_name}/g; s/APP4TRIQS/${capital_name}/g" {} \; + find . -type f -not -path "./.git/*" -exec rename app4triqs ${app_name} {} &> /dev/null \; +elif [ $(uname -s) == Darwin ]; then + LC_CTYPE=C LANG=C find . -type f \ + -not -path "./.git/*" \ + -not -path "*/replace_and_rename.sh" \ + -not -path "*/squash_history.sh" \ + -exec sed -i '' -e "s/app4triqs/${app_name}/g; s/APP4TRIQS/${capital_name}/g" {} \; + find . -type f -not -path "./.git/*" -exec rename "s/app4triqs/${app_name}/" {} &> /dev/null \; +fi diff --git a/share/squash_history.sh b/share/squash_history.sh new file mode 100755 index 00000000..8c03c08f --- /dev/null +++ b/share/squash_history.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +git reset $(git commit-tree HEAD\^{tree} -m "Initialize project from github.com/triqs/app4triqs@$(git rev-parse --short HEAD)") +git merge --allow-unrelated-histories -s ours HEAD@{1} -m "Track app4triqs skeleton" +git remote rm origin +git remote add app4triqs_remote https://github.com/triqs/app4triqs