From 5c73194b708fd7dceadab0875f219d88f3c1447a Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Fri, 27 Sep 2024 17:24:08 +0100 Subject: [PATCH] Add misisng scripts Remove circleci --- .circleci/config.yml | 93 ------------------- .circleci/has-functional-changes.sh | 12 --- .circleci/is-version-number-acceptable.sh | 33 ------- .circleci/publish-git-tag.sh | 4 - .circleci/publish-python-package.sh | 4 - openfisca_tunisia/scripts/__init__.py | 0 .../scripts/check_path_length.py | 55 +++++++++++ 7 files changed, 55 insertions(+), 146 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100755 .circleci/has-functional-changes.sh delete mode 100755 .circleci/is-version-number-acceptable.sh delete mode 100755 .circleci/publish-git-tag.sh delete mode 100755 .circleci/publish-python-package.sh create mode 100644 openfisca_tunisia/scripts/__init__.py create mode 100644 openfisca_tunisia/scripts/check_path_length.py diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 3d8dea15..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,93 +0,0 @@ -version: 2 - -jobs: - build: - docker: - - image: python:3.7 - - steps: - - checkout - - - restore_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - - - run: - name: Create a virtualenv - command: | - mkdir -p /tmp/venv/openfisca_tunisia - python -m venv /tmp/venv/openfisca_tunisia - echo "source /tmp/venv/openfisca_tunisia/bin/activate" >> $BASH_ENV - # Writes the command to a file which path is provided by the $BASH_ENV - - - run: - name: Install tests dependencies - command: | - pip install --upgrade pip twine wheel - pip install --editable .[tests] --upgrade - # pip install --editable git+https://github.com/openfisca/openfisca-core.git@BRANCH_NAME#egg=OpenFisca-Core # use a specific branch of OpenFisca-Core - - - run: - name: Install notebook dependencies - command: pip install --editable .[notebook] --upgrade - - - save_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - paths: - - /tmp/venv/openfisca_tunisia - - - run: - name: Run tests and check notebooks - command: make test - - deploy: - docker: - - image: python:3.7 - environment: - PYPI_USERNAME: openfisca-bot - # PYPI_PASSWORD: this value is set in CircleCI's web interface; do not set it here, it is a secret! - - steps: - - checkout - - - restore_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - - - run: - name: Check for functional changes - command: if ! .circleci/has-functional-changes.sh ; then circleci step halt ; fi - - - run: - name: Upload a Python package to Pypi - command: | - source /tmp/venv/openfisca_tunisia/bin/activate - .circleci/publish-python-package.sh - - - run: - name: Publish a git tag - command: .circleci/publish-git-tag.sh - - check_version_and_changelog: - docker: - - image: python:3.7 - steps: - - checkout - - - run: - name: Check version number has been properly updated - command: | - git fetch - .circleci/is-version-number-acceptable.sh - -workflows: - version: 2 - build_and_deploy: - jobs: - - build - - check_version_and_changelog - - deploy: - requires: - - build - - check_version_and_changelog - filters: - branches: - only: master diff --git a/.circleci/has-functional-changes.sh b/.circleci/has-functional-changes.sh deleted file mode 100755 index b787de99..00000000 --- a/.circleci/has-functional-changes.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env bash - -IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .circleci/* .github/*" - -last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit - -if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. -then - echo "No functional changes detected." - exit 1 -else echo "The functional files above were changed." -fi diff --git a/.circleci/is-version-number-acceptable.sh b/.circleci/is-version-number-acceptable.sh deleted file mode 100755 index ae370e2a..00000000 --- a/.circleci/is-version-number-acceptable.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env bash - -if [[ $CIRCLE_BRANCH == master ]] -then - echo "No need for a version check on master." - exit 0 -fi - -if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh -then - echo "No need for a version update." - exit 0 -fi - -current_version=`python setup.py --version` - -if git rev-parse --verify --quiet $current_version -then - echo "Version $current_version already exists in commit:" - git --no-pager log -1 $current_version - echo - echo "Update the version number in setup.py before merging this branch into master." - echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." - exit 1 -fi - -if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md -then - echo "CHANGELOG.md has not been modified, while functional changes were made." - echo "Explain what you changed before merging this branch into master." - echo "Look at the CONTRIBUTING.md file to learn how to write the changelog." - exit 2 -fi diff --git a/.circleci/publish-git-tag.sh b/.circleci/publish-git-tag.sh deleted file mode 100755 index 4450357c..00000000 --- a/.circleci/publish-git-tag.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/env bash - -git tag `python setup.py --version` -git push --tags # update the repository version diff --git a/.circleci/publish-python-package.sh b/.circleci/publish-python-package.sh deleted file mode 100755 index 8d331bd9..00000000 --- a/.circleci/publish-python-package.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/env bash - -python setup.py bdist_wheel # build this package in the dist directory -twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD # publish diff --git a/openfisca_tunisia/scripts/__init__.py b/openfisca_tunisia/scripts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openfisca_tunisia/scripts/check_path_length.py b/openfisca_tunisia/scripts/check_path_length.py new file mode 100644 index 00000000..cf8b1275 --- /dev/null +++ b/openfisca_tunisia/scripts/check_path_length.py @@ -0,0 +1,55 @@ +''' +EN: Look into folders to check path length and return an error if a too long path is found. +Also write too long path in a file. + +FR: Ce script sert à estimer la longueur des chemins d'arborescence des paramètres, +afin de ne pas avoir de chemins > 150 caractères (incompatible Windows). +Il est à utiliser avant de contribuer à l'harmonisation +''' + + +import os +import logging + + +logging.basicConfig(level=logging.INFO) + + +def extract_paths_too_long(root_dir): + ''' + Look into folders to check path length and return True if a too long path is found. + ''' + path_too_long_detected = False + maxlen = 0 + root_dir = root_dir.rstrip(os.sep) + + with open('path_too_long_list.txt', 'w') as outfile: + for path, dirs, files in os.walk(root_dir): + relative_path = path[len(root_dir) + 1:] + for dir in dirs: + if dir.startswith('.'): + # Ignore hidden directories. + dirs.remove(dir) + for file in files: + if file.startswith('.'): + # Ignore hidden files. + continue + relative_file_path = os.path.join(relative_path, file) + maxlen = max(maxlen, len(relative_file_path)) + if len(relative_file_path) > 150: + path_too_long_detected = True + logging.error(f'Path too long of {len(relative_file_path)-150} characters : {relative_file_path}') + outfile.write('{} here: {}\n'.format( + len(relative_file_path), + relative_file_path, + )) + logging.info(f'Max length found : {maxlen} characters.') + return path_too_long_detected + + +country_dir = os.path.dirname((os.path.dirname(os.path.abspath(__file__)))) +parameters_dir = os.path.join(country_dir, 'parameters') +if extract_paths_too_long(parameters_dir): + # Return code 1 to indicate an error. Default is 0. + exit(1) +# If no path are too long, the default return is 0: no error.