-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from os-climate/apply-substitutions
Chore: Make template substitutions [skip ci]
- Loading branch information
Showing
11 changed files
with
186 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
Contributing | ||
============ | ||
|
||
Welcome to ``osc-data-extractor`` contributor's guide. | ||
Welcome to ``osc-transformer-based-extractor`` contributor's guide. | ||
|
||
This document focuses on getting any potential contributor familiarized | ||
with the development processes, but `other kinds of contributions`_ are also | ||
|
@@ -46,7 +46,7 @@ guidelines. | |
Issue Reports | ||
============= | ||
|
||
If you experience bugs or general issues with ``osc-data-extractor``, please have a look | ||
If you experience bugs or general issues with ``osc-transformer-based-extractor``, please have a look | ||
on the `issue tracker`_. If you don't see anything useful there, please feel | ||
free to fire an issue report. | ||
|
||
|
@@ -65,10 +65,10 @@ you help us to identify the root cause of the issue. | |
Documentation Improvements | ||
========================== | ||
|
||
You can help improve ``osc-data-extractor`` docs by making them more readable and coherent, or | ||
You can help improve ``osc-transformer-based-extractor`` docs by making them more readable and coherent, or | ||
by adding missing information and correcting mistakes. | ||
|
||
``osc-data-extractor`` documentation uses Sphinx_ as its main documentation compiler. | ||
``osc-transformer-based-extractor`` documentation uses Sphinx_ as its main documentation compiler. | ||
This means that the docs are kept in the same repository as the project code, and | ||
that any documentation update is done in the same way was a code contribution. | ||
|
||
|
@@ -80,7 +80,7 @@ that any documentation update is done in the same way was a code contribution. | |
|
||
.. tip:: | ||
Please notice that the `GitHub web interface`_ provides a quick way of | ||
propose changes in ``osc-data-extractor``'s files. While this mechanism can | ||
propose changes in ``osc-transformer-based-extractor``'s files. While this mechanism can | ||
be tricky for normal code contributions, it works perfectly fine for | ||
contributing to the docs, and can be quite handy. | ||
|
||
|
@@ -131,8 +131,8 @@ This can easily be done via either |virtualenv|_:: | |
|
||
or Miniconda_:: | ||
|
||
conda create -n osc-data-extractor python=3 six virtualenv pytest pytest-cov | ||
conda activate osc-data-extractor | ||
conda create -n osc-transformer-based-extractor python=3 six virtualenv pytest pytest-cov | ||
conda activate osc-transformer-based-extractor | ||
|
||
Clone the repository | ||
-------------------- | ||
|
@@ -142,8 +142,8 @@ Clone the repository | |
page. This creates a copy of the code under your account on |the repository service|. | ||
#. Clone this copy to your local disk:: | ||
|
||
git clone [email protected]:YourLogin/osc-data-extractor.git | ||
cd osc-data-extractor | ||
git clone [email protected]:YourLogin/osc-transformer-based-extractor.git | ||
cd osc-transformer-based-extractor | ||
|
||
#. You should run:: | ||
|
||
|
@@ -158,7 +158,7 @@ Clone the repository | |
pip install pre-commit | ||
pre-commit install | ||
|
||
``osc-data-extractor`` comes with a lot of hooks configured to automatically help the | ||
``osc-transformer-based-extractor`` comes with a lot of hooks configured to automatically help the | ||
developer to check the code being written. | ||
|
||
Implement your changes | ||
|
@@ -285,7 +285,7 @@ Releases | |
|
||
If you are part of the group of maintainers and have correct user permissions | ||
on PyPI_, the following steps can be used to release a new version for | ||
``osc-data-extractor``: | ||
``osc-transformer-based-extractor``: | ||
|
||
#. Make sure all unit tests are successful. | ||
#. Tag the current commit on the main branch with a release tag, e.g., ``v1.2.3``. | ||
|
@@ -314,8 +314,8 @@ on PyPI_, the following steps can be used to release a new version for | |
.. |the repository service| replace:: GitHub | ||
.. |contribute button| replace:: "Create pull request" | ||
|
||
.. _repository: https://github.com/<USERNAME>/osc-data-extractor | ||
.. _issue tracker: https://github.com/<USERNAME>/osc-data-extractor/issues | ||
.. _repository: https://github.com/<USERNAME>/osc-transformer-based-extractor | ||
.. _issue tracker: https://github.com/<USERNAME>/osc-transformer-based-extractor/issues | ||
.. <-- end --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
#set -x | ||
|
||
REPO_NAME=$(basename "$(git rev-parse --show-toplevel)") | ||
echo "Repository name: $REPO_NAME" | ||
|
||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 [test folder]"; exit 1 | ||
elif [ ! -d "$1" ]; then | ||
echo "Error: specified target was not a folder"; exit 1 | ||
else | ||
# Target specified was a folder | ||
TARGET="$1" | ||
fi | ||
|
||
for TEST in $(find "$TARGET" -type f -name '*_test.py' | xargs -0); do | ||
echo "Processing: $TEST" | ||
FILE_PATH=$(dirname "$TEST") | ||
FILE_NAME=$(basename "$TEST") | ||
STRIPPED="${FILE_NAME//_test.py/.py}" | ||
echo " git mv \"${TEST}\" $FILE_PATH/test_\"${STRIPPED%%}\"" | ||
git mv "${TEST}" "$FILE_PATH"/test_"${STRIPPED%%}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/bin/bash | ||
|
||
# set -x | ||
|
||
### Shared functions | ||
|
||
# Renames files/folders containing template name | ||
rename_object() { | ||
if [ $# -ne 1 ]; then | ||
echo "Function requires an argumeent: rename_object [filesystem object]"; exit 1 | ||
else | ||
FS_OBJECT="$1" | ||
fi | ||
# Function take a filesystem object as a single argument | ||
FS_OBJECT="$1" | ||
OBJECT_PATH=$(dirname "$FS_OBJECT") | ||
OBJECT_NAME=$(basename "$FS_OBJECT") | ||
|
||
# Check if filesystem object contains template name | ||
if [[ ! "$OBJECT_NAME" == *"$TEMPLATE_NAME"* ]]; then | ||
# Nothing to do; abort early | ||
return | ||
else | ||
NEW_NAME="${OBJECT_NAME//$TEMPLATE_NAME/$REPO_NAME}" | ||
fi | ||
if [[ ! "$OBJECT_NAME" == *"$ALT_TEMPLATE_NAME"* ]]; then | ||
# Nothing to do; abort early | ||
return | ||
else | ||
NEW_NAME="${OBJECT_NAME//$ALT_TEMPLATE_NAME/$ALT_REPO_NAME}" | ||
fi | ||
|
||
# Perform the renaming operation | ||
if [ -d "$FS_OBJECT" ]; then | ||
echo "Renaming folder: $FS_OBJECT" | ||
elif [ -f "$FS_OBJECT" ]; then | ||
echo "Renaming file: $FS_OBJECT" | ||
elif [ -L "$FS_OBJECT" ]; then | ||
echo "Renaming symlink: $FS_OBJECT" | ||
fi | ||
git mv "$OBJECT_PATH/$OBJECT_NAME" "$OBJECT_PATH/$NEW_NAME" | ||
} | ||
|
||
# Checks file content for template name and replaces matching strings | ||
file_content_substitution() { | ||
if [ $# -ne 1 ]; then | ||
echo "Function requires an argument: file_content_substitution [filename]"; exit 1 | ||
else | ||
FILENAME="$1" | ||
fi | ||
COUNT=0 | ||
if (grep "$TEMPLATE_NAME" "$FILENAME" > /dev/null 2>&1); then | ||
MATCHES=$(grep -c "$TEMPLATE_NAME" "$FILENAME") | ||
if [ "$MATCHES" -eq 1 ]; then | ||
echo "1 content substitution required: $FILENAME (dashes)" | ||
COUNT=$((COUNT++)) | ||
else | ||
echo "$MATCHES content substitutions required: $FILENAME (dashes)" | ||
COUNT=$((COUNT+MATCHES)) | ||
fi | ||
sed -i "s/$TEMPLATE_NAME/$REPO_NAME/g" "$FILENAME" | ||
fi | ||
if (grep "$ALT_TEMPLATE_NAME" "$FILENAME" > /dev/null 2>&1); then | ||
MATCHES=$(grep -c "$ALT_TEMPLATE_NAME" "$FILENAME") | ||
if [ "$MATCHES" -eq 1 ]; then | ||
echo "1 content substitution required: $FILENAME (underscores)" | ||
COUNT=$((COUNT++)) | ||
else | ||
echo "$MATCHES content substitutions required: $FILENAME (underscores)" | ||
COUNT=$((COUNT+MATCHES)) | ||
fi | ||
sed -i "s/$ALT_TEMPLATE_NAME/$ALT_REPO_NAME/g" "$FILENAME" | ||
fi | ||
if [[ "$COUNT" != "0" ]] && [[ "$COUNT" = "1" ]]; then | ||
echo "$COUNT substitution made in file: $FILENAME" | ||
elif [[ "$COUNT" != "0" ]] && [[ "$COUNT" -gt "1" ]]; then | ||
echo "$COUNT substitutions made in file: $FILENAME" | ||
fi | ||
} | ||
|
||
### Main script entry point | ||
|
||
TEMPLATE_NAME=osc-transformer-based-extractor | ||
ALT_TEMPLATE_NAME="${TEMPLATE_NAME//-/_}" | ||
|
||
if ! (git rev-parse --show-toplevel > /dev/null); then | ||
echo "Error: this folder is not part of a GIT repository"; exit 1 | ||
fi | ||
|
||
REPO_DIR=$(git rev-parse --show-toplevel) | ||
REPO_NAME=$(basename "$REPO_DIR") | ||
ALT_REPO_NAME="${REPO_NAME//-/_}" | ||
|
||
if [ "$TEMPLATE_NAME" == "$REPO_NAME" ]; then | ||
echo "WARNING: template name matches repository name" | ||
else | ||
echo "Template name: $TEMPLATE_NAME" | ||
echo "Alternate name: $ALT_TEMPLATE_NAME" | ||
echo "Repository name: $REPO_NAME" | ||
echo "Alternate name: $ALT_REPO_NAME" | ||
fi | ||
|
||
# Change to top-level of GIT repository | ||
CURRENT_DIR=$(pwd) | ||
if [ "$REPO_DIR" != "$CURRENT_DIR" ]; then | ||
echo "Changing directory to: $REPO_DIR" | ||
if ! (cd "$REPO_DIR"); then | ||
echo "Could not change directory!"; exit 1 | ||
fi | ||
fi | ||
|
||
echo "Processing repository contents..." | ||
|
||
# Rename directories first, as they affect file paths afterwards | ||
for FS_OBJECT in $(find -- * -type d | xargs -0); do | ||
rename_object "$FS_OBJECT" | ||
if [ -f "$FS_OBJECT" ]; then | ||
file_content_substitution "$FS_OBJECT" | ||
fi | ||
done | ||
|
||
for FS_OBJECT in $(find -- * -type f | xargs -0); do | ||
rename_object "$FS_OBJECT" | ||
if [ -f "$FS_OBJECT" ]; then | ||
file_content_substitution "$FS_OBJECT" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.