From d1081e918a0bf8e3ca0d51e01e9b52b8ee0ccd29 Mon Sep 17 00:00:00 2001 From: hminaee-tc Date: Wed, 3 Jul 2024 18:15:22 -0300 Subject: [PATCH] Feat/check-v2 common packages under open cepk (#2) * feat/check-v initial version --- .github/CODEOWNERS | 1 + .github/workflows/pre-commit.yml | 22 + .github/workflows/publish-to-pypi.yml | 60 +++ .github/workflows/tests.yml | 93 +++++ .gitignore | 10 +- .pre-commit-config.yaml | 104 +++++ .pre-commit-hooks.yaml | 17 + .yamllint.yaml | 35 ++ README.md | 40 ++ opencepk_lib_python_common/.gitignore | 168 ++++++++ opencepk_lib_python_common/__init__.py | 0 .../README.md | 200 +++++++++ .../__init__.py | 0 .../find_and_replace_strings/__init__.py | 0 .../find_and_replace_strings/__main__.py | 5 + .../find_and_replace_strings/main.py | 98 +++++ .../tests-package-e2e/.find-and-replace.json | 30 ++ .../tests-package-e2e/README_TEST_PACKAGE.md | 9 + .../README_TEST_PACKAGE.md.expected | 9 + .../README_TEST_PACKAGE.md.template | 9 + .../tests-package-e2e/check-commit-hook.sh | 28 ++ .../tests-package-e2e/test-package-e2e.sh | 32 ++ .../.find-and-replace.json | 30 ++ .../.pre-commit-config.yaml | 15 + .../README_TEST_PRE_COMMIT.md | 9 + .../README_TEST_PRE_COMMIT.md.expected | 9 + .../README_TEST_PRE_COMMIT.md.template | 9 + .../test-pre-commit-hook.sh | 33 ++ .../tests/__init__.py | 0 .../tests/test_main.py | 48 +++ .../__init__.py | 0 .../pypi_bumpversion_check/__init__.py | 0 .../pypi_bumpversion_check/__main__.py | 5 + .../pypi_bumpversion_check/main.py | 67 +++ .../pypi_bumpversion_check/requirements.txt | 3 + .../tests-package-e2e/pyproject.test | 44 ++ .../tests-package-e2e/test-package-e2e.sh | 11 + .../.pre-commit-config.yaml | 17 + .../tests-pre-commit-hook/pyproject.test | 44 ++ .../test-pre-commit-hook.sh | 13 + output.csv | 385 ++++++++++++++++++ pyproject.toml | 47 +++ requirements.txt | 1 + setup.py | 56 +++ 44 files changed, 1815 insertions(+), 1 deletion(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .github/workflows/publish-to-pypi.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .pre-commit-hooks.yaml create mode 100644 .yamllint.yaml create mode 100644 opencepk_lib_python_common/.gitignore create mode 100644 opencepk_lib_python_common/__init__.py create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/README.md create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/__init__.py create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__init__.py create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__main__.py create mode 100755 opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/main.py create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/.find-and-replace.json create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.expected create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.template create mode 100755 opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/check-commit-hook.sh create mode 100755 opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/test-package-e2e.sh create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.find-and-replace.json create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.pre-commit-config.yaml create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.expected create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.template create mode 100755 opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/test-pre-commit-hook.sh create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests/__init__.py create mode 100644 opencepk_lib_python_common/find_and_replace_strings_package/tests/test_main.py create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/__init__.py create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__init__.py create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__main__.py create mode 100755 opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/pyproject.test create mode 100755 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/test-package-e2e.sh create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test create mode 100755 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh create mode 100644 output.csv create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e6cefce --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @opencepk/opencepk-admins diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..4b2a84b --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,22 @@ +--- +name: pre-commit + +on: + pull_request: + +permissions: read-all + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + - name: setup-python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + # - name: install-dependencies + # run: pip install -r opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt + - name: pre-commit-run + uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..bab590d --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,60 @@ +--- +name: publish-to-pypi + +on: + workflow_run: + workflows: ["pre-commit"] + types: + - completed + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + name: build-pip-package + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.11 + + - name: run pip install + run: | + pip3 install . + pip3 install ".[dep]" + build-n-publish: + needs: build + name: build-n-publish + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.11 + + - name: Install pip packages + run: pip install twine build setuptools + + - name: Build the package + run: python -m build + + - name: Publish package to PyPI + if: ${{ github.event_name == 'pull_request' && github.head_ref == '/refs/heads/main' && github.event.action == 'closed' && github.event.pull_request.merged == true }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d2f3677 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,93 @@ +--- +name: tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + # ---------------------- + # JOB 1: Run unit tests + # ---------------------- + tests-unit: + name: tests-unit + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.11 + + - name: Run tests + run: python3 -m unittest opencepk_lib_python_common.find_and_replace_strings_package.tests.test_main + # ---------------------- + # JOB 2: Run python package end to end test + # ---------------------- + test-package-e2e: + name: test-package-e2e + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.11 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install toml requests + + - name: Run test-package-e2e.sh for find-replace-strings package + run: | + cd opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e + ./test-package-e2e.sh + + - name: Run test-package-e2e.sh for check version package + run: | + cd opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e + ./test-package-e2e.sh + # ---------------------- + # JOB 3: Run pre-commit hook test + # ---------------------- + test-pre-commit-hook: + name: test-pre-commit-hook + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.11 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pre-commit + + - name: Run test-pre-commit-hook.sh for find-replace-strings package + run: | + cd opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook + ./test-pre-commit-hook.sh + + - name: Run test-pre-commit-hook.sh for check version package + run: | + cd opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook + ./test-pre-commit-hook.sh diff --git a/.gitignore b/.gitignore index 82f9275..67273aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,19 @@ # Byte-compiled / optimized / DLL files __pycache__/ +**/__pycache__/ *.py[cod] *$py.class +.DS_Store +**/.DS_Store + +**/precommit-e2e.test + # C extensions *.so +**/*.egg-info + # Distribution / packaging .Python build/ @@ -85,7 +93,7 @@ ipython_config.py # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: -# .python-version +.python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..df60020 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,104 @@ +--- +repos: + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-merge-conflict + - id: check-added-large-files + args: [--maxkb=500] + - id: trailing-whitespace + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-encoding-pragma + - id: file-contents-sorter + - id: check-case-conflict + - id: mixed-line-ending + args: [--fix=lf] + # ----------------------------- + # Checkov is a static code analysis tool for scanning infrastructure as code (IaC) files for misconfigurations + # that may lead to security or compliance problems. + # ----------------------------- + # Checkov includes more than 750 predefined policies to check for common misconfiguration issues. + # Checkov also supports the creation and contribution of custom policies. + # ----------------------------- + - repo: https://github.com/bridgecrewio/checkov.git + rev: 3.2.171 + hooks: + - id: checkov + # ----------------------------- + # Gitleaks SAST tool for detecting and preventing hardcoded secrets like passwords, api keys, and tokens in git repos + # ----------------------------- + # If you are knowingly committing something that is not a secret and gitleaks is catching it, + # you can add an inline comment of '# gitleaks:allow' to the end of that line in your file. + # This will instructs gitleaks to ignore that secret - example: + # some_non_secret_value = a1b2c3d4e5f6g7h8i9j0 # gitleaks:allow + # ----------------------------- + - repo: https://github.com/gitleaks/gitleaks + rev: v8.18.4 + hooks: + - id: gitleaks + # ----------------------------- + # # Generates Table of Contents in Markdown files + # # ----------------------------- + - repo: https://github.com/frnmst/md-toc + rev: 9.0.0 + hooks: + - id: md-toc + args: [-p, github] # CLI options + # ----------------------------- + # YAML Linting on yaml files for pre-commit and github actions + # ----------------------------- + - repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint + name: Check YAML syntax with yamllint + args: [--strict, -c=.yamllint.yaml, '.'] + always_run: true + pass_filenames: true + + # ----------------------------- + # PYPI bumpversion check + # ----------------------------- + # - repo: local + # hooks: + # - id: install-pypi_bumpversion_check-requirements + # name: Install PYPI bumpversion check requirements + # entry: sh -c 'pip3 install -r ./opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt && exit 0' + # language: system + # always_run: true + + # ----------------------------- + # PYPI bumpversion check + # ----------------------------- + - repo: local + hooks: + - id: pypi_bumpversion_check + name: Check version + args: ['./pyproject.toml'] + entry: python3 -m opencepk_lib_python_common.pypi_bumpversion_check_package.pypi_bumpversion_check + language: python + pass_filenames: false # Do not pass filenames to the hook (this is important to keep) + additional_dependencies: + - toml + - requests + + + - repo: local + hooks: + - id: unittest + name: Run unit tests + entry: python3 -m unittest opencepk_lib_python_common.find_and_replace_strings_package.tests.test_main + language: system + pass_filenames: false + always_run: true + + - repo: local + hooks: + - id: toml build + name: test the .toml package health + entry: pip3 install . + language: system + pass_filenames: false + always_run: true diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..1260ca0 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,17 @@ +--- +- id: python-pypi-version-check + name: python-pypi-version-check + description: Check if Python package already exists on PYPI. + # entry: hooks/pypi_bumpversion_check-check + entry: python-pypi-version-check + language: python + +- id: find-and-replace-strings + name: find-and-replace-strings + description: Check if Python package already exists on PYPI. + entry: find-and-replace-strings + # entry: hooks/find_and_replace_strings + language: python + + + # python-pypi-version-check-test /Users/hamed/Desktop/tucows-code/find-and-replace-strings/pyproject.toml diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..0ccdc36 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,35 @@ +--- +yaml-files: + - '*.yaml' + - '*.yml' + - '.yamllint' + +rules: + anchors: enable + braces: enable + brackets: enable + colons: enable + commas: enable + comments: + level: warning + comments-indentation: + level: warning + document-end: disable + document-start: + level: warning + empty-lines: enable + empty-values: disable + float-values: disable + hyphens: enable + indentation: enable + key-duplicates: enable + key-ordering: disable + # line-length: + # max: 150 + # level: warning + new-line-at-end-of-file: enable + new-lines: enable + octal-values: disable + quoted-strings: disable + trailing-spaces: enable + truthy: disable diff --git a/README.md b/README.md index 627c9bc..6f69397 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # opencepk-lib-python-common + Common Python packages + +## Sample use case: + +```` + +repos: + + - repo: https://github.com/opencepk/opencepk-lib-python-common + rev: v0.0.5 + hooks: + - id: python-pypi-version-check # this is the id we refer to in precommit.hook + name: Check version + description: python-pypi-version-check + args: ['./pyproject.toml'] + entry: python-pypi-version-check + language: system + pass_filenames: false # Do not pass filenames to the hook (this is important to keep) + + - repo: https://github.com/opencepk/opencepk-lib-python-common + rev: v0.0.5 + hooks: + - id: find-and-replace-strings # this is the id we refer to in precommit.hook + name: find-and-replace-strings + description: Find and replace strings + entry: find-and-replace-strings + language: python + pass_filenames: true + exclude_types: + - binary + files: '.*\.md$' + verbose: true + + ``` + +```` + +## Find and Replace strings + + [find and replace strings documentation](./opencepk_lib_python_common/find_and_replace_strings_package/README.md) diff --git a/opencepk_lib_python_common/.gitignore b/opencepk_lib_python_common/.gitignore new file mode 100644 index 0000000..b2ce492 --- /dev/null +++ b/opencepk_lib_python_common/.gitignore @@ -0,0 +1,168 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +**/__pycache__/ +*.py[cod] +*$py.class + +.DS_Store +**/.DS_Store + +**/precommit-e2e.test + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/opencepk_lib_python_common/__init__.py b/opencepk_lib_python_common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/README.md b/opencepk_lib_python_common/find_and_replace_strings_package/README.md new file mode 100644 index 0000000..faa9a47 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/README.md @@ -0,0 +1,200 @@ +# find-and-replace + +Python package and pre-commit-hook for finding and replacing string(s) in file(s). + +## Prerequisite + +pre-commit install +pre-commit install -t pre-push + +The above will make sure precommit will be run automatically on push + +## Installation as a pip package + +This is an easy to use package which is already available here https://pypi.org/project/find-and-replace-template-commit-check/: + +![package to use](./assets/pypi-package.png "Title") + +You can install the package via pip: + +```bash +pip install find-and-replace-strings +``` +In case if you want to use it from the root folder in source: + +``` + python -m find_and_replace_strings -h +``` + +## Usage as a pre commit hook + +To use this package, you need to add it to your pre-commit configuration file (.pre-commit-config.yaml). Here's an example: + +For config mod + +``` +repos: + - repo: https://github.com/opencepk/find-and-replace + rev: v0.0.1 + hooks: + - id: find-and-replace-strings + name: find-and-replace-strings + description: Find and replace strings + entry: find-and-replace-strings + language: python + pass_filenames: true + exclude_types: + - binary + files: README.md + verbose: true + +``` + +and for direct mode + +``` +repos: + - repo: https://github.com/opencepk/find-and-replace + rev: v0.0.1 + hooks: + - id: find-and-replace-strings + name: find-and-replace-strings + description: Find and replace strings + entry: find-and-replace-strings + language: python + pass_filenames: true + exclude_types: + - binary + args: ["--find", "search_string", "--replacement", "replacement_string"] + files: README.md + verbose: true +``` + +Please note you also have a choice of +files: '.*\.md$' +or +files: . + +In this configuration, the find-and-replace hook is set to read search and replacement strings from a file (.project-properties.json by default which should be defined in the root of the project you want to use this package). You can also specify the search and replacement strings directly in the args field (which is not a suggested way). + +## Usage as a python package +python -m find_and_replace_strings --usage +or +find-and-replace-strings --usage + +shows some usage examples. +``` + python -m find_and_replace_strings --usage +Example usages: +python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --verbose +python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --log-level=DEBUG +python -m find_and_replace_strings --find 'old_string' --replacement 'new_string' example.txt --verbose +python -m find_and_replace_strings --find 'old_string' --replacement 'new_string' example1.txt example2.txt --verbose +python -m find_and_replace_strings --config my_config.json example.txt --dry-run --verbose +python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --log-level=INFO +``` + +## Run tests + +``` +python -m unittest tests.test_main + +``` + +## How to run it using installed python package + +``` + pip install find-and-replace-strings + find-and-replace --config .find-and-replace.json README1.md README2.md +``` + +also if you prefer to use a direct mod + +``` +find-and-replace-strings --find "old_string" --replacement "new_string" README1.md README2.md +``` + +## Dry run + +Inside the project + +python -m find_and_replace_strings --config ./.find-and-replace.json ./README.md READMEtest.md --dry-run + +or using the deployed package + +find-and-replace-strings --config ./.find-and-replace.json ./README.md READ +MEtest.md --dry-run + +More example: + + +python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --verbose + +python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --log-level=DEBUG + +``` +python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --verbose +INFO:root:Running in default config file mode +INFO:root:Replacing {{BUSINESS_UNIT}} with examp"lebu in e2e/precommit-e2e.test +INFO:root:Replacing {{PROJECT_NAME}} with exampleproject in e2e/precommit-e2e.test +INFO:root:{{PROJECT_NAME}} would be replaced with exampleproject in e2e/precommit-e2e.test +INFO:root:Replacing {{GITHUB_REPO_URL}} with https://github.com/examplebu/exampleproject in e2e/precommit-e2e.test +INFO:root:Replacing {{PROJECT_DESCRIPTION_SLUG}} with Example project used to demonstrate all aspects of a project development and deployment in e2e/precommit-e2e.test +INFO:root:Replacing tucowsinc/iaascloudenablement with tucowsinc/example-github-team-name in e2e/precommit-e2e.test +INFO:root:Replacing {{PROJECT_CONTRIBUTORS}} with * [Andre Ouellet](mailto:aouellet@tucowsinc.com) in e2e/precommit-e2e.test +``` + +## If you need more help with the available flags + +``` +python -m find_and_replace_strings -h +usage: __main__.py [-h] [--config CONFIG] [--find] [--replacement] [--dry-run] + [--log-level LOG_LEVEL] [--verbose] [--usage] + [files ...] + +Perform find and replace operations on one or more target files. By default, the script reads the +search and replacement entries (strings) from a JSON file. You can also specify the search and +replacement strings directly as command line args by setting the --find "search_string" and +--replacement "replacement_string" argument options. + +positional arguments: + files File(s) on which to perform search and replace + +options: + -h, --help show this help message and exit + --config CONFIG PATH to JSON config file containing find and replacement entries + --find String to find in files + --replacement String to replace with in files + --dry-run Perform a dry run without making any changes + --log-level LOG_LEVEL + Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) + --verbose Print debug and info messages + --usage Print example usages + +``` + +## Building and Publishing + +To build and publish it to pypi run with proper token + +``` +bash assets/publish.sh +``` +or create a PR and after merge the changes will be published to the artifactory. + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. + +## License + +This project is licensed under the terms of the MIT license. + + +## Reference Info + +- https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table +- https://setuptools.pypa.io/en/latest/userguide/declarative_config.html +- https://packaging.python.org/guides/distributing-packages-using-setuptools/ +- https://autopilot-docs.readthedocs.io/en/latest/license_list.html +- https://pypi.org/classifiers/ diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/__init__.py b/opencepk_lib_python_common/find_and_replace_strings_package/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__init__.py b/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__main__.py b/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__main__.py new file mode 100644 index 0000000..97aede6 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/__main__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +from .main import main + +if __name__ == "__main__": + main() diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/main.py b/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/main.py new file mode 100755 index 0000000..45f8487 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/main.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import argparse +import fileinput +import json +import sys +import logging + + +def replace_in_file(filename, search, replacement, dry_run=False): + logging.info(f"Replacing {search} with {replacement} in {filename}") + with fileinput.FileInput(filename, inplace=not dry_run) as file: + for line in file: + if search in line and dry_run: + logging.info(f"{search} would be replaced with {replacement} in {filename}") + elif not dry_run: + print(line.replace(rf"{search}", rf"{replacement}"), end='') + + +def print_usage(): + print("Example usages:") + print("python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --verbose") + print("python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --log-level=DEBUG") + print("python -m find_and_replace_strings --find 'old_string' --replacement 'new_string' example.txt --verbose") + print("python -m find_and_replace_strings --find 'old_string' --replacement 'new_string' example1.txt example2.txt --verbose") + print("python -m find_and_replace_strings --config my_config.json example.txt --dry-run --verbose") + print("python -m find_and_replace_strings --config e2e/.find-and-replace.json e2e/precommit-e2e.test --dry-run --log-level=INFO") + + +def main(): + parser = argparse.ArgumentParser( + description="""Perform find and replace operations on one or more target files. + By default, the script reads the search and replacement entries (strings) from a JSON file. + You can also specify the search and replacement strings directly as command line args by setting the + --find "search_string" and --replacement "replacement_string" argument options.""" + ) + parser.add_argument( + '--config', default='.find-and-replace.json', + help='PATH to JSON config file containing find and replacement entries' + ) + parser.add_argument( + '--find', dest='direct_mode', action='store_true', help='String to find in files' + ) + parser.add_argument( + '--replacement', dest='direct_mode', action='store_true', help='String to replace with in files' + ) + parser.add_argument( + 'files', nargs='*', help='File(s) on which to perform search and replace' + ) + parser.add_argument( + '--dry-run', action='store_true', help='Perform a dry run without making any changes' + ) + parser.add_argument( + '--log-level', default='WARNING', help='Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)' + ) + parser.add_argument( + '--verbose', action='store_true', help='Print debug and info messages' + ) + parser.add_argument( + '--usage', action='store_true', help='Print example usages' + ) + args = parser.parse_args() + + if args.usage: + print_usage() + sys.exit(0) + + levels = {'DEBUG': logging.DEBUG, 'INFO': logging.INFO, 'WARNING': logging.WARNING, 'ERROR': logging.ERROR, 'CRITICAL': logging.CRITICAL} + level = levels.get(args.log_level.upper(), logging.WARNING) + if args.verbose: + level = logging.DEBUG + logging.basicConfig(level=level) + + if args.direct_mode: + logging.info("Running in direct mode") + for filename in args.files: + replace_in_file(filename, args.find, args.replacement, args.dry_run) + else: + logging.info("Running in default config file mode") + try: + with open(os.path.join(os.getcwd(), args.config), 'r') as f: + replacements = json.load(f) + except FileNotFoundError: + logging.error(f"Error: {args.config} file not found.") + sys.exit(1) + except json.JSONDecodeError: + logging.error(f"Error: {args.config} is not a valid JSON file.") + sys.exit(1) + + for filename in args.files: + for replacement in replacements: + replace_in_file(filename, replacement['search'], replacement['replacement'], args.dry_run) + + +if __name__ == "__main__": + main() diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/.find-and-replace.json b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/.find-and-replace.json new file mode 100644 index 0000000..1adb550 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/.find-and-replace.json @@ -0,0 +1,30 @@ +[ + { + "search": "{{BUSINESS_UNIT}}", + "replacement": "opencepk" + }, + { + "search": "{{PROJECT_NAME}}", + "replacement": "exampleproject" + }, + { + "search": "{{GITHUB_REPO_URL}}", + "replacement": "https://github.com/opencepk/opencepk-exampleproject" + }, + { + "search": "{{PROJECT_DESCRIPTION_SLUG}}", + "replacement": "Example project used to demonstrate all aspects of a project development and deployment" + }, + { + "search": "{{PROJECT_TEAM}}", + "replacement": "opencepk/opencepk-exampleteam" + }, + { + "search": "{{PROJECT_CONTRIBUTORS}}", + "replacement": "* [Open CEPK](mailto:opencepk@gmail.com)" + }, + { + "search": "{{SPECIAL_CHARACTER_TESTS}}", + "replacement": "\"SomeValueInDoubleQuotes\"" + } +] diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md new file mode 100644 index 0000000..b0b9c9f --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md @@ -0,0 +1,9 @@ +# Target test file for find-and-replace-strings python package + +business unit is: {{BUSINESS_UNIT}} +project name is: {{PROJECT_NAME}} +github url is: {{GITHUB_REPO_URL}} +project description slug is: {{PROJECT_DESCRIPTION_SLUG}} +project team is: {{PROJECT_TEAM}} +project contributors are: {{PROJECT_CONTRIBUTORS}} +special character tests: {{SPECIAL_CHARACTER_TESTS}} diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.expected b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.expected new file mode 100644 index 0000000..ac6d9f7 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.expected @@ -0,0 +1,9 @@ +# Target test file for find-and-replace-strings python package + +business unit is: opencepk +project name is: exampleproject +github url is: https://github.com/opencepk/opencepk-exampleproject +project description slug is: Example project used to demonstrate all aspects of a project development and deployment +project team is: opencepk/opencepk-exampleteam +project contributors are: * [Open CEPK](mailto:opencepk@gmail.com) +special character tests: "SomeValueInDoubleQuotes" diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.template b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.template new file mode 100644 index 0000000..b0b9c9f --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/README_TEST_PACKAGE.md.template @@ -0,0 +1,9 @@ +# Target test file for find-and-replace-strings python package + +business unit is: {{BUSINESS_UNIT}} +project name is: {{PROJECT_NAME}} +github url is: {{GITHUB_REPO_URL}} +project description slug is: {{PROJECT_DESCRIPTION_SLUG}} +project team is: {{PROJECT_TEAM}} +project contributors are: {{PROJECT_CONTRIBUTORS}} +special character tests: {{SPECIAL_CHARACTER_TESTS}} diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/check-commit-hook.sh b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/check-commit-hook.sh new file mode 100755 index 0000000..d408221 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/check-commit-hook.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Create target test file +cp -f "tests-e2e/target-find-and-replace.txt.template" "tests-e2e/target-find-and-replace.txt" + +# Store the original content of the file +original_content=$(cat tests-e2e/precommit-e2e.test) +echo "Original content: $original_content" + +# Run the hook +python find_and_replace_strings_package/find_and_replace_strings/main.py --config tests-e2e/.find-and-replace.json tests-e2e/precommit-e2e.test + +# Check if the expected changes have been made +content=$(cat tests-e2e/precommit-e2e.test) +echo "Content after running the hook: $content" + +if [[ "$content" != "# exampleproject" ]]; then + # If the changes are not as expected, print the exit code and exit with a status code of 1 + echo "Exit code: 1" + exit 1 +fi + +# Restore the original content of the file +echo "$original_content" > tests-e2e/precommit-e2e.test + +# If the changes are as expected, print the exit code and exit with a status code of 0 +echo "Exit code: 0" +exit 0 diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/test-package-e2e.sh b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/test-package-e2e.sh new file mode 100755 index 0000000..8deaebd --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e/test-package-e2e.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +TEST_DIR="tests-package-e2e" +TEST_SCRIPT_FILENAME=$(basename -- "$0") +TEST_SCRIPT_NAME="${TEST_SCRIPT_FILENAME%.*}" +TEST_TARGET_FILE="README_TEST_PACKAGE.md" + +#------------------------------- +# Run the python package +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Running pre-commit using ${TEST_DIR}/.pre-commit-config.yaml" +(cd .. && python find_and_replace_strings/main.py --config ${TEST_DIR}/.find-and-replace.json ${TEST_DIR}/${TEST_TARGET_FILE}) + +#------------------------------- +# Evaluate results +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Running (diff ${TEST_TARGET_FILE} ${TEST_TARGET_FILE}.expected)" +echo "${TEST_SCRIPT_NAME}: Fetching return code of diff" +diff "${TEST_TARGET_FILE}" "${TEST_TARGET_FILE}.expected" +evaluate_diff_status=$? + +#------------------------------- +# Run the pre-commit hook reset +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Resetting ${TEST_TARGET_FILE} file to original state" +cp -pf "${TEST_TARGET_FILE}.template" "${TEST_TARGET_FILE}" + +#------------------------------- +# Exit with exit code of diff evaluation +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Exit code = $evaluate_diff_status" +exit $evaluate_diff_status diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.find-and-replace.json b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.find-and-replace.json new file mode 100644 index 0000000..1adb550 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.find-and-replace.json @@ -0,0 +1,30 @@ +[ + { + "search": "{{BUSINESS_UNIT}}", + "replacement": "opencepk" + }, + { + "search": "{{PROJECT_NAME}}", + "replacement": "exampleproject" + }, + { + "search": "{{GITHUB_REPO_URL}}", + "replacement": "https://github.com/opencepk/opencepk-exampleproject" + }, + { + "search": "{{PROJECT_DESCRIPTION_SLUG}}", + "replacement": "Example project used to demonstrate all aspects of a project development and deployment" + }, + { + "search": "{{PROJECT_TEAM}}", + "replacement": "opencepk/opencepk-exampleteam" + }, + { + "search": "{{PROJECT_CONTRIBUTORS}}", + "replacement": "* [Open CEPK](mailto:opencepk@gmail.com)" + }, + { + "search": "{{SPECIAL_CHARACTER_TESTS}}", + "replacement": "\"SomeValueInDoubleQuotes\"" + } +] diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.pre-commit-config.yaml b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.pre-commit-config.yaml new file mode 100644 index 0000000..3012b29 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +--- +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: local + hooks: + - id: find-and-replace-strings + name: find-and-replace-strings + entry: "./opencepk_lib_python_common/find_and_replace_strings_package/find_and_replace_strings/main.py" + language: python + exclude_types: + - binary + args: ["--config", "./opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/.find-and-replace.json"] + files: "find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT\\.md$" + # we need $ to terminate the check to avoid .md.template to be picked by hook diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md new file mode 100644 index 0000000..8757397 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md @@ -0,0 +1,9 @@ +# Target test file for find-and-replace-strings pre-commit hook + +business unit is: {{BUSINESS_UNIT}} +project name is: {{PROJECT_NAME}} +github url is: {{GITHUB_REPO_URL}} +project description slug is: {{PROJECT_DESCRIPTION_SLUG}} +project team is: {{PROJECT_TEAM}} +project contributors are: {{PROJECT_CONTRIBUTORS}} +special character tests: {{SPECIAL_CHARACTER_TESTS}} diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.expected b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.expected new file mode 100644 index 0000000..f5752d5 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.expected @@ -0,0 +1,9 @@ +# Target test file for find-and-replace-strings pre-commit hook + +business unit is: opencepk +project name is: exampleproject +github url is: https://github.com/opencepk/opencepk-exampleproject +project description slug is: Example project used to demonstrate all aspects of a project development and deployment +project team is: opencepk/opencepk-exampleteam +project contributors are: * [Open CEPK](mailto:opencepk@gmail.com) +special character tests: "SomeValueInDoubleQuotes" diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.template b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.template new file mode 100644 index 0000000..8757397 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/README_TEST_PRE_COMMIT.md.template @@ -0,0 +1,9 @@ +# Target test file for find-and-replace-strings pre-commit hook + +business unit is: {{BUSINESS_UNIT}} +project name is: {{PROJECT_NAME}} +github url is: {{GITHUB_REPO_URL}} +project description slug is: {{PROJECT_DESCRIPTION_SLUG}} +project team is: {{PROJECT_TEAM}} +project contributors are: {{PROJECT_CONTRIBUTORS}} +special character tests: {{SPECIAL_CHARACTER_TESTS}} diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/test-pre-commit-hook.sh b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/test-pre-commit-hook.sh new file mode 100755 index 0000000..d22ac9b --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook/test-pre-commit-hook.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +TEST_DIR_FROM_ROOT="opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook" +TEST_DIR="tests-pre-commit-hook" +TEST_SCRIPT_FILENAME=$(basename -- "$0") +TEST_SCRIPT_NAME="${TEST_SCRIPT_FILENAME%.*}" +TEST_TARGET_FILE="README_TEST_PRE_COMMIT.md" + +#------------------------------- +# Run the pre-commit hook test +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Running pre-commit using ${TEST_DIR_FROM_ROOT}/.pre-commit-config.yaml" +(cd ../../.. && pre-commit run -a -c "${TEST_DIR_FROM_ROOT}/.pre-commit-config.yaml") + +#------------------------------- +# Evaluate results +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Running (cd ${TEST_DIR} && diff ${TEST_TARGET_FILE} ${TEST_TARGET_FILE}.expected)" +echo "${TEST_SCRIPT_NAME}: Fetching return code of diff" +diff "./${TEST_TARGET_FILE}" "${TEST_TARGET_FILE}.expected" +evaluate_diff_status=$? + +#------------------------------- +# Run the pre-commit hook reset +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Resetting ${TEST_DIR}/${TEST_TARGET_FILE} file to original state" +cp -pf "${TEST_TARGET_FILE}.template" "${TEST_TARGET_FILE}" + +#------------------------------- +# Exit with exit code of diff evaluation +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Exit code = $evaluate_diff_status" +exit $evaluate_diff_status diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests/__init__.py b/opencepk_lib_python_common/find_and_replace_strings_package/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opencepk_lib_python_common/find_and_replace_strings_package/tests/test_main.py b/opencepk_lib_python_common/find_and_replace_strings_package/tests/test_main.py new file mode 100644 index 0000000..54382b0 --- /dev/null +++ b/opencepk_lib_python_common/find_and_replace_strings_package/tests/test_main.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +import unittest +import argparse +from unittest.mock import patch, mock_open + +import os +import sys + +project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')) +if project_root not in sys.path: + sys.path.insert(0, project_root) +from find_and_replace_strings_package.find_and_replace_strings.main import replace_in_file, main + + +class TestMainFunctions(unittest.TestCase): + @patch('fileinput.FileInput') + def test_replace_in_file(self, mock_fileinput): + """ + This test checks if the replace_in_file function correctly opens the file and replaces the specified text. + """ + # Mock the file input to return a specific line of text + mock_fileinput.return_value.__enter__.return_value = ['hello world'] + # Call the function with a specific search and replacement + replace_in_file('dummy.txt', 'hello', 'hi') + # Assert that the file was opened correctly + mock_fileinput.assert_called_once_with('dummy.txt', inplace=True) + + +@patch('argparse.ArgumentParser.parse_args') +@patch('find_and_replace.main.replace_in_file') +@patch('os.getcwd', return_value='/dummy/path') +@patch('builtins.open', new_callable=mock_open, read_data='{"search": "hello", "replacement": "hi"}') +@patch('json.load', return_value=[{"search": "hello", "replacement": "hi"}]) +def test_main(self, mock_json_load, mock_open, mock_getcwd, mock_replace_in_file, mock_parse_args): + """ + This test checks if the main function correctly reads the configuration file and calls the replace_in_file function with the correct arguments. + """ + # Mock the command line arguments + mock_parse_args.return_value = argparse.Namespace(files=['dummy.txt'], find=None, replacement=None, direct_mode=False, config='.find-and-replace.json') + # Call the main function + main() + # Assert that the config file was opened correctly and the replace_in_file function was called with the correct arguments + mock_open.assert_called_once_with('/dummy/path/.find-and-replace.json', 'r') + mock_replace_in_file.assert_called_once_with('dummy.txt', 'hello', 'hi') + + +if __name__ == '__main__': + unittest.main() diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/__init__.py b/opencepk_lib_python_common/pypi_bumpversion_check_package/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__init__.py b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__main__.py b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__main__.py new file mode 100644 index 0000000..97aede6 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/__main__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +from .main import main + +if __name__ == "__main__": + main() diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py new file mode 100755 index 0000000..3a8beca --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import argparse +import toml +import sys +import requests +import subprocess +import logging + +def main(): + # Configure logging + logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') + + # Setup argument parser with usage examples in the epilog + parser = argparse.ArgumentParser( + description='Check if the current version is published on PyPI.', + epilog='''Usage example: + python main.py pyproject.toml -- Check if the version specified in pyproject.toml is published on PyPI. + python main.py --usage -- Show this usage example.''', + formatter_class=argparse.RawDescriptionHelpFormatter + ) + parser.add_argument('toml_path', nargs='?', help='Path to the pyproject.toml file') # Make toml_path optional + parser.add_argument('--usage', action='store_true', help='Show usage example and exit') + + args = parser.parse_args() + + # If --usage is specified, print the epilog (usage examples) and exit + if args.usage: + print(parser.epilog) + sys.exit(0) + + # Check if toml_path is provided + if not args.toml_path: + parser.print_help() + sys.exit(1) + + logging.info("Loading pyproject.toml from %s", args.toml_path) + # Load the pyproject.toml file + with open(args.toml_path) as toml_file: + data = toml.load(toml_file) + + # Get the current version + current_version = data["project"]["version"] + logging.info("Current version: %s", current_version) + + # Get the package name + package_name = data["project"]["name"] + logging.info("Package name: %s", package_name) + + # Check if the version is already published + logging.info("Checking if version %s of %s is already published on PyPI", current_version, package_name) + response = requests.get(f"https://pypi.org/pypi/{package_name}/{current_version}/json") + + if response.status_code == 200: + logging.error("This version is already published. Please bump the version in pyproject.toml.") + sys.exit(1) + + # Check if pyproject.toml has been modified but not committed + logging.info("Checking if pyproject.toml has been modified but not committed") + modified_files = subprocess.check_output(["git", "diff", "--name-only"]).decode().splitlines() + + if "pyproject.toml" in modified_files: + logging.error("The version in pyproject.toml has been changed but not committed. Please commit your changes.") + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt new file mode 100644 index 0000000..5ced152 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt @@ -0,0 +1,3 @@ +# Requirements for pypi_bumpversion_check +toml +requests diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/pyproject.test b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/pyproject.test new file mode 100644 index 0000000..1a68cda --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/pyproject.test @@ -0,0 +1,44 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = { find = { where = ["."] } } + +[project] +name = "opencepk-lib-python-common" +version = "0.0.0" +description = "Python package and pre-commit-hook for finding and replacing string(s) in file(s)." +readme = "README.md" +license = { text = "GPLv3" } +authors = [{name = "OpenCEPK Open Cloud Engineering Platform Kit", email = "opencepk@gmail.com"}] +requires-python = ">=3.9" + +keywords = ["find", "replace", "string", "file", "pre-commit", "hook", "git", "tool", "utility", "opencepk"] +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Natural Language :: English", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Topic :: File Formats :: JSON", + "Topic :: Software Development :: Pre-processors", + "Topic :: Software Development :: Version Control :: Git", + "Topic :: Text Processing", + "Topic :: Text Processing :: Filters", + "Topic :: Text Processing :: General", + "Topic :: Utilities" +] + +[project.entry-points."console_scripts"] +python-pypi-version-check = "opencepk_lib_python_common.pypi_bumpversion_check_package.pypi_bumpversion_check.main:main" +find-and-replace-strings = "opencepk_lib_python_common.find_and_replace_strings_package.find_and_replace_strings.main:main" diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/test-package-e2e.sh b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/test-package-e2e.sh new file mode 100755 index 0000000..9fa8e71 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-package-e2e/test-package-e2e.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +TEST_DIR="tests-package-e2e" + +#------------------------------- +# Run the python package +#------------------------------- +echo "Running in: $(pwd)" +pushd .. > /dev/null +python3 pypi_bumpversion_check/main.py './${TEST_DIR}/pyproject.test' +popd > /dev/null diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml new file mode 100644 index 0000000..b613741 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +--- +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: local + hooks: + - id: python-pypi-version-check + name: python-pypi-version-check + entry: "./opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py" + language: python + exclude_types: + - binary + args: ['./opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test'] + pass_filenames: false # Do not pass filenames to the hook (this is important to keep) + additional_dependencies: + - toml + - requests diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test new file mode 100644 index 0000000..1a68cda --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test @@ -0,0 +1,44 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = { find = { where = ["."] } } + +[project] +name = "opencepk-lib-python-common" +version = "0.0.0" +description = "Python package and pre-commit-hook for finding and replacing string(s) in file(s)." +readme = "README.md" +license = { text = "GPLv3" } +authors = [{name = "OpenCEPK Open Cloud Engineering Platform Kit", email = "opencepk@gmail.com"}] +requires-python = ">=3.9" + +keywords = ["find", "replace", "string", "file", "pre-commit", "hook", "git", "tool", "utility", "opencepk"] +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Natural Language :: English", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Topic :: File Formats :: JSON", + "Topic :: Software Development :: Pre-processors", + "Topic :: Software Development :: Version Control :: Git", + "Topic :: Text Processing", + "Topic :: Text Processing :: Filters", + "Topic :: Text Processing :: General", + "Topic :: Utilities" +] + +[project.entry-points."console_scripts"] +python-pypi-version-check = "opencepk_lib_python_common.pypi_bumpversion_check_package.pypi_bumpversion_check.main:main" +find-and-replace-strings = "opencepk_lib_python_common.find_and_replace_strings_package.find_and_replace_strings.main:main" diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh new file mode 100755 index 0000000..0338530 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +TEST_DIR_FROM_ROOT="opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook" +TEST_DIR="tests-pre-commit-hook" +TEST_SCRIPT_FILENAME=$(basename -- "$0") +TEST_SCRIPT_NAME="${TEST_SCRIPT_FILENAME%.*}" +TEST_TARGET_FILE="README_TEST_PRE_COMMIT.md" + +#------------------------------- +# Run the pre-commit hook test +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Running pre-commit using ${TEST_DIR_FROM_ROOT}/.pre-commit-config.yaml" +(cd ../../.. && pre-commit run -a -c "${TEST_DIR_FROM_ROOT}/.pre-commit-config.yaml") diff --git a/output.csv b/output.csv new file mode 100644 index 0000000..2d102cb --- /dev/null +++ b/output.csv @@ -0,0 +1,385 @@ +repository_name,team_name,team_permissions,user_name,user_permissions,user_full_name +adminsite,,,ptrinidad-tc,admin, +ascio,ascio-dev,admin,cdehlsen-tc,,Claus Dehlsen +ascio,ascio-dev,admin,tgudmundsson-tc,,Tomas Gudmundsson +ascio,ascio-dev,admin,jbhardwaj-tc,,Jinish Bhardwaj +ascio,ascio-dev,admin,fbramer-tc,, +ascio,ascio-dev,admin,grsmith-tc,, +ascio,ascio-dev,admin,vjachimaviciute-tc,,Vilma J +ascio,ascio-dev,admin,itahir-tc,,Irfan Tahir +ascio,ascio-dev,admin,mhakansson-tc,,Magnus HÃ¥kansson +ascio,,,cdehlsen-tc,admin,Claus Dehlsen +ascio,ascio-dev,admin,cdehlsen-tc,,Claus Dehlsen +ascio,ascio-dev,admin,tgudmundsson-tc,,Tomas Gudmundsson +ascio,ascio-dev,admin,jbhardwaj-tc,,Jinish Bhardwaj +ascio,ascio-dev,admin,fbramer-tc,, +ascio,ascio-dev,admin,grsmith-tc,, +ascio,ascio-dev,admin,vjachimaviciute-tc,,Vilma J +ascio,ascio-dev,admin,itahir-tc,,Irfan Tahir +ascio,ascio-dev,admin,mhakansson-tc,,Magnus HÃ¥kansson +ascio,,,cdehlsen-tc,admin,Claus Dehlsen +dish-5g-proxy,wavelo-security,admin,msahai-tc,,Michael Sahai +dish-5g-proxy,wavelo-security,admin,sarentz-tc,,Stefan Arentz +dish-5g-proxy,,,epirogov-tc,admin,Evgueni Pirogov +dish-5g-proxy,,,ibamieh-tc,admin,Izzy +dish-5g-proxy,,,staghavizadeh-tc,admin,SamZadeh +dish-5g-proxy,,,asunderland-tc,admin,Andrew S +dish-5g-proxy,,,gwitecki-tc,admin,Gwendolyn Witecki +dish-5g-proxy,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +dish-5g-proxy,,,kcorreia-tc,admin,Kleber Correia +dish-5g-proxy,,,jdietrich-tc,admin,Jonathan Dietrich +dish-5g-proxy,,,msaleh-tc,admin,Mohammad Saleh +dish-5g-proxy,,,rserradura-tc,admin, +enom-dbservices,,,ptrinidad-tc,admin, +enom-dbservices,,,sthompson-tc,admin,Shannon Thompson +hover,,,ngaragliano-tc,admin, +hover,,,mbolisay-tc,admin, +hover,,,dhernandez-tc,admin, +hover,,,jguajardo-tc,admin, +hover,,,bthapa-tc,admin,Barun Thapa +hover-infra,,,dkoo-tc,admin, +hover-infra,,,ngaragliano-tc,admin, +hover-infra,,,pthakkar-tc,admin, +hover-infra,,,jlarter-tc,admin, +imara,imara,admin,RDhar,,Rishav Dhar +imara,imara,admin,benjaminrumble-tc,,Benjamin Rumble +imara,imara,admin,drego-tc,,Danny Rego +imara,imara,admin,jcrawford-tc,,Jeff Crawford +imara,imara,admin,adutton-tc,,Andrew Dutton +imara,imara,admin,pmcconnell-tc,,Patrick McConnell +imara,imara,admin,tgudmundsson-tc,,Tomas Gudmundsson +imara,imara,admin,taratyn-tc,,Tom Aratyn +imara,imara,admin,aeldaly-tc,,Ahmed El-Daly +imara,imara,admin,oigumbor-tc,,Osedum Igumbor +imara,imara,admin,aplacid-tc,,Ashitha Placid +imara,imara,admin,jlumley-tc,,Jeremy Lumley +imara,imara,admin,vzago-tc,,Vinicius Zago +imara,monos-ops,admin,adutton-tc,,Andrew Dutton +imara,monos-ops,admin,pmcconnell-tc,,Patrick McConnell +imara,monos-ops,admin,jmercer-tc,,Jim Mercer +imara,monos-ops,admin,aafuwape-tc,,Anthony Afuwape +imara,monos-ops,admin,kpatel-tc,, +imara,monos-ops,admin,mbolisay-tc,, +imara,monos-ops,admin,mse-bot-tc,, +imara,monos-ops,admin,rmokkapati-tc,, +imara,monos-ops,admin,schalamani-tc,, +imara,monos-ops,admin,cpaulino-tc,,Carlos Paulino +imara,wavelo-security,admin,msahai-tc,,Michael Sahai +imara,wavelo-security,admin,sarentz-tc,,Stefan Arentz +imara,,,benjaminrumble-tc,admin,Benjamin Rumble +imara,,,aeldaly-tc,admin,Ahmed El-Daly +imara,,,oigumbor-tc,admin,Osedum Igumbor +imara,,,asunderland-tc,admin,Andrew S +imara,,,ksitnik-tc,admin,Kamil Sitnik +imara,,,gtassinari-tc,admin,Guilherme Tassinari +imara,,,vzago-tc,admin,Vinicius Zago +monos-ada-shared,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-ada-shared,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-ada-shared,,,cdias-tc,admin,Cidiomar Dias +monos-aggregator,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-aggregator,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-aggregator,,,ccramer-tc,admin,Chad Cramer +monos-aggregator,,,oigumbor-tc,admin,Osedum Igumbor +monos-aggregator,,,asunderland-tc,admin,Andrew S +monos-billing,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-billing,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-billing,,,ccramer-tc,admin,Chad Cramer +monos-billing,,,oigumbor-tc,admin,Osedum Igumbor +monos-billing,,,asunderland-tc,admin,Andrew S +monos-floodgate,"Architecture ""A-Team""",admin,drego-tc,,Danny Rego +monos-floodgate,"Architecture ""A-Team""",admin,jcrawford-tc,,Jeff Crawford +monos-floodgate,"Architecture ""A-Team""",admin,pbevin-tc,,Pete Bevin +monos-floodgate,"Architecture ""A-Team""",admin,jlumley-tc,,Jeremy Lumley +monos-floodgate,"Architecture ""A-Team""",admin,cpaulino-tc,,Carlos Paulino +monos-floodgate,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-floodgate,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-floodgate,,,drego-tc,admin,Danny Rego +monos-floodgate,,,oigumbor-tc,admin,Osedum Igumbor +monos-floodgate,,,asunderland-tc,admin,Andrew S +monos-floodgate,,,kcorreia-tc,admin,Kleber Correia +monos-floodgate,,,rfloriano-tc,admin,Rafael Floriano da Silva +monos-metrics,SecOps,admin,mmeintker-tc,, +monos-metrics,SecOps,admin,jknight-tc,, +monos-metrics,SecOps,admin,akranz-tc,, +monos-metrics,SecOps,admin,spassi-tc,, +monos-metrics,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-metrics,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-quotation-gateway-service,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-quotation-gateway-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-quotation-gateway-service,,,ccramer-tc,admin,Chad Cramer +monos-quotation-gateway-service,,,oigumbor-tc,admin,Osedum Igumbor +monos-quotation-gateway-service,,,asunderland-tc,admin,Andrew S +monos-remootify,imara,admin,RDhar,,Rishav Dhar +monos-remootify,imara,admin,benjaminrumble-tc,,Benjamin Rumble +monos-remootify,imara,admin,drego-tc,,Danny Rego +monos-remootify,imara,admin,jcrawford-tc,,Jeff Crawford +monos-remootify,imara,admin,adutton-tc,,Andrew Dutton +monos-remootify,imara,admin,pmcconnell-tc,,Patrick McConnell +monos-remootify,imara,admin,tgudmundsson-tc,,Tomas Gudmundsson +monos-remootify,imara,admin,taratyn-tc,,Tom Aratyn +monos-remootify,imara,admin,aeldaly-tc,,Ahmed El-Daly +monos-remootify,imara,admin,oigumbor-tc,,Osedum Igumbor +monos-remootify,imara,admin,aplacid-tc,,Ashitha Placid +monos-remootify,imara,admin,jlumley-tc,,Jeremy Lumley +monos-remootify,imara,admin,vzago-tc,,Vinicius Zago +monos-remootify,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-remootify,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-remootify,,,ccramer-tc,admin,Chad Cramer +monos-remootify,,,oigumbor-tc,admin,Osedum Igumbor +monos-remootify,,,asunderland-tc,admin,Andrew S +monos-scheduler,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-scheduler,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-scheduler,,,ccramer-tc,admin,Chad Cramer +monos-scheduler,,,oigumbor-tc,admin,Osedum Igumbor +monos-scheduler,,,asunderland-tc,admin,Andrew S +monos-serialization,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-serialization,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-serialization,,,ccramer-tc,admin,Chad Cramer +monos-serialization,,,oigumbor-tc,admin,Osedum Igumbor +monos-serialization,,,asunderland-tc,admin,Andrew S +monos-shared,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-shared,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-switchboard,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-switchboard,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-switchboard,,,msolaja-tc,admin, +monos-switchboard,,,schalamani-tc,admin, +monos-tax-service,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-tax-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +monos-tax-service,,,ccramer-tc,admin,Chad Cramer +monos-tax-service,,,oigumbor-tc,admin,Osedum Igumbor +monos-tax-service,,,asunderland-tc,admin,Andrew S +monos-tracing,wavelo-security,admin,msahai-tc,,Michael Sahai +monos-tracing,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-accounting,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-accounting,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-accounting,,,ccramer-tc,admin,Chad Cramer +mse-accounting,,,epirogov-tc,admin,Evgueni Pirogov +mse-accounting,,,sbc-tc,admin, +mse-accounting,,,asunderland-tc,admin,Andrew S +mse-accounting,,,bpierrette-tc,admin, +mse-accounting,,,cdias-tc,admin,Cidiomar Dias +mse-accounts,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-accounts,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-accounts,,,ccramer-tc,admin,Chad Cramer +mse-accounts,,,epirogov-tc,admin,Evgueni Pirogov +mse-accounts,,,lmelnyk-tc,admin,Lily Melnyk +mse-accounts,,,asunderland-tc,admin,Andrew S +mse-accounts,,,bpierrette-tc,admin, +mse-accounts,,,cdias-tc,admin,Cidiomar Dias +mse-att-csi-proxy,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-att-csi-proxy,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-att-csi-proxy,,,epirogov-tc,admin,Evgueni Pirogov +mse-att-csi-proxy,,,ibamieh-tc,admin,Izzy +mse-att-csi-proxy,,,staghavizadeh-tc,admin,SamZadeh +mse-att-csi-proxy,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-att-csi-proxy,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-att-csi-proxy,,,kcorreia-tc,admin,Kleber Correia +mse-att-csi-proxy,,,msaleh-tc,admin,Mohammad Saleh +mse-att-ericsson-proxy,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-att-ericsson-proxy,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-att-ericsson-proxy,,,epirogov-tc,admin,Evgueni Pirogov +mse-att-ericsson-proxy,,,ibamieh-tc,admin,Izzy +mse-att-ericsson-proxy,,,staghavizadeh-tc,admin,SamZadeh +mse-att-ericsson-proxy,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-att-ericsson-proxy,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-att-ericsson-proxy,,,msaleh-tc,admin,Mohammad Saleh +mse-att-proxy-client,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-att-proxy-client,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-att-proxy-client,,,epirogov-tc,admin,Evgueni Pirogov +mse-att-proxy-client,,,ibamieh-tc,admin,Izzy +mse-att-proxy-client,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-att-proxy-client,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-catalog-ingestion-service,monos-prod-deploy-approvers,admin,ccramer-tc,,Chad Cramer +mse-catalog-ingestion-service,monos-prod-deploy-approvers,admin,msahai-tc,,Michael Sahai +mse-catalog-ingestion-service,monos-prod-deploy-approvers,admin,hliem-tc,,Hanno Liem +mse-catalog-ingestion-service,monos-prod-deploy-approvers,admin,ibamieh-tc,,Izzy +mse-catalog-ingestion-service,monos-prod-deploy-approvers,admin,asunderland-tc,,Andrew S +mse-catalog-ingestion-service,monos-prod-deploy-approvers,admin,jasbridge-tc,, +mse-catalog-ingestion-service,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-catalog-ingestion-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-catalog-ingestion-service,,,epirogov-tc,admin,Evgueni Pirogov +mse-catalog-ingestion-service,,,sbc-tc,admin, +mse-catalog-ingestion-service,,,oigumbor-tc,admin,Osedum Igumbor +mse-catalog-ingestion-service,,,asunderland-tc,admin,Andrew S +mse-catalog-ingestion-service,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-catalog-ingestion-service,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-catalog-ingestion-service,,,kcorreia-tc,admin,Kleber Correia +mse-catalog-ingestion-service,,,jdietrich-tc,admin,Jonathan Dietrich +mse-catalog-ingestion-service,,,svaz-tc,admin,svaz-tc +mse-catalog-ingestion-service,,,msaleh-tc,admin,Mohammad Saleh +mse-coverage-validation-service,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-coverage-validation-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-coverage-validation-service,,,epirogov-tc,admin,Evgueni Pirogov +mse-coverage-validation-service,,,ibamieh-tc,admin,Izzy +mse-coverage-validation-service,,,staghavizadeh-tc,admin,SamZadeh +mse-coverage-validation-service,,,asunderland-tc,admin,Andrew S +mse-coverage-validation-service,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-coverage-validation-service,,,mbolisay-tc,admin, +mse-coverage-validation-service,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-coverage-validation-service,,,msaleh-tc,admin,Mohammad Saleh +mse-device-validation-service,monos-ops,admin,adutton-tc,,Andrew Dutton +mse-device-validation-service,monos-ops,admin,pmcconnell-tc,,Patrick McConnell +mse-device-validation-service,monos-ops,admin,jmercer-tc,,Jim Mercer +mse-device-validation-service,monos-ops,admin,aafuwape-tc,,Anthony Afuwape +mse-device-validation-service,monos-ops,admin,kpatel-tc,, +mse-device-validation-service,monos-ops,admin,mbolisay-tc,, +mse-device-validation-service,monos-ops,admin,mse-bot-tc,, +mse-device-validation-service,monos-ops,admin,rmokkapati-tc,, +mse-device-validation-service,monos-ops,admin,schalamani-tc,, +mse-device-validation-service,monos-ops,admin,cpaulino-tc,,Carlos Paulino +mse-device-validation-service,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-device-validation-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-device-validation-service,,,epirogov-tc,admin,Evgueni Pirogov +mse-device-validation-service,,,ibamieh-tc,admin,Izzy +mse-device-validation-service,,,staghavizadeh-tc,admin,SamZadeh +mse-device-validation-service,,,asunderland-tc,admin,Andrew S +mse-device-validation-service,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-device-validation-service,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-device-validation-service,,,kcorreia-tc,admin,Kleber Correia +mse-device-validation-service,,,msaleh-tc,admin,Mohammad Saleh +mse-device-validation-service,,,rserradura-tc,admin, +mse-dish-5g-proxy-client,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-dish-5g-proxy-client,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-dish-5g-proxy-client,,,epirogov-tc,admin,Evgueni Pirogov +mse-dish-5g-proxy-client,,,ibamieh-tc,admin,Izzy +mse-dish-5g-proxy-client,,,staghavizadeh-tc,admin,SamZadeh +mse-dish-5g-proxy-client,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-dish-5g-proxy-client,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-e911-authenticator-and-router,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-e911-authenticator-and-router,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-e911-authenticator-and-router,,,epirogov-tc,admin,Evgueni Pirogov +mse-e911-authenticator-and-router,,,ibamieh-tc,admin,Izzy +mse-e911-authenticator-and-router,,,staghavizadeh-tc,admin,SamZadeh +mse-e911-authenticator-and-router,,,asunderland-tc,admin,Andrew S +mse-e911-authenticator-and-router,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-invoicing,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-invoicing,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-invoicing,,,ccramer-tc,admin,Chad Cramer +mse-invoicing,,,oigumbor-tc,admin,Osedum Igumbor +mse-invoicing,,,asunderland-tc,admin,Andrew S +mse-port-eligibility-service,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-port-eligibility-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-port-eligibility-service,,,epirogov-tc,admin,Evgueni Pirogov +mse-port-eligibility-service,,,staghavizadeh-tc,admin,SamZadeh +mse-port-eligibility-service,,,asunderland-tc,admin,Andrew S +mse-port-eligibility-service,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-port-eligibility-service,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-port-eligibility-service,,,kcorreia-tc,admin,Kleber Correia +mse-port-eligibility-service,,,msaleh-tc,admin,Mohammad Saleh +mse-provisioning-service,monos-ops,admin,adutton-tc,,Andrew Dutton +mse-provisioning-service,monos-ops,admin,pmcconnell-tc,,Patrick McConnell +mse-provisioning-service,monos-ops,admin,jmercer-tc,,Jim Mercer +mse-provisioning-service,monos-ops,admin,aafuwape-tc,,Anthony Afuwape +mse-provisioning-service,monos-ops,admin,kpatel-tc,, +mse-provisioning-service,monos-ops,admin,mbolisay-tc,, +mse-provisioning-service,monos-ops,admin,mse-bot-tc,, +mse-provisioning-service,monos-ops,admin,rmokkapati-tc,, +mse-provisioning-service,monos-ops,admin,schalamani-tc,, +mse-provisioning-service,monos-ops,admin,cpaulino-tc,,Carlos Paulino +mse-provisioning-service,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-provisioning-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-provisioning-service,,,ccramer-tc,admin,Chad Cramer +mse-provisioning-service,,,epirogov-tc,admin,Evgueni Pirogov +mse-provisioning-service,,,sbc-tc,admin, +mse-provisioning-service,,,ibamieh-tc,admin,Izzy +mse-provisioning-service,,,staghavizadeh-tc,admin,SamZadeh +mse-provisioning-service,,,asunderland-tc,admin,Andrew S +mse-provisioning-service,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-provisioning-service,,,mbolisay-tc,admin, +mse-provisioning-service,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-provisioning-service,,,kcorreia-tc,admin,Kleber Correia +mse-provisioning-service,,,ppanganiban-tc,admin,Perlanie +mse-provisioning-service,,,jdietrich-tc,admin,Jonathan Dietrich +mse-provisioning-service,,,svaz-tc,admin,svaz-tc +mse-provisioning-service,,,msaleh-tc,admin,Mohammad Saleh +mse-provisioning-service,,,rserradura-tc,admin, +mse-routing-service,wavelo-security,admin,msahai-tc,,Michael Sahai +mse-routing-service,wavelo-security,admin,sarentz-tc,,Stefan Arentz +mse-routing-service,,,epirogov-tc,admin,Evgueni Pirogov +mse-routing-service,,,staghavizadeh-tc,admin,SamZadeh +mse-routing-service,,,asunderland-tc,admin,Andrew S +mse-routing-service,,,gwitecki-tc,admin,Gwendolyn Witecki +mse-routing-service,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +mse-routing-service,,,kcorreia-tc,admin,Kleber Correia +mse-routing-service,,,msaleh-tc,admin,Mohammad Saleh +mse-routing-service,,,rserradura-tc,admin, +opensrs,opensrs-admins,admin,mnieweglowski-tc,,Mark Nieweglowski +opensrs-infra,DomainsA,admin,dkoo-tc,, +opensrs-infra,DomainsA,admin,ngaragliano-tc,, +opensrs-infra,DomainsA,admin,dschaan-tc,, +opensrs-infra,DomainsA,admin,mwalraven-tc,, +opensrs-infra,DomainsA,admin,pthakkar-tc,, +opensrs-infra,DomainsA,admin,jlarter-tc,, +opensrs-infra,DomainsA,admin,jtecson-tc,, +prod_enom-terraform,DomainsB,admin,ptrinidad-tc,, +prod_enom-terraform,DomainsB,admin,dschaan-tc,, +prod_enom-terraform,DomainsB,admin,mumar-tc,, +prod_enom-terraform,DomainsB,admin,jtecson-tc,, +prod_enom-terraform,DomainsB,admin,domainsb-bot-tc,, +prod_enom-terraform,,,domainsb-bot-tc,admin, +ting-backend,,,epirogov-tc,admin,Evgueni Pirogov +ting-backend,,,mvanlammeren-tc,admin,Mike van Lammeren +ting-funds,,,mvanlammeren-tc,admin,Mike van Lammeren +ting-middleware,,,mvanlammeren-tc,admin,Mike van Lammeren +ting-node,,,mvanlammeren-tc,admin,Mike van Lammeren +tmo-notify-proxy,monos-ops,admin,adutton-tc,,Andrew Dutton +tmo-notify-proxy,monos-ops,admin,pmcconnell-tc,,Patrick McConnell +tmo-notify-proxy,monos-ops,admin,jmercer-tc,,Jim Mercer +tmo-notify-proxy,monos-ops,admin,aafuwape-tc,,Anthony Afuwape +tmo-notify-proxy,monos-ops,admin,kpatel-tc,, +tmo-notify-proxy,monos-ops,admin,mbolisay-tc,, +tmo-notify-proxy,monos-ops,admin,mse-bot-tc,, +tmo-notify-proxy,monos-ops,admin,rmokkapati-tc,, +tmo-notify-proxy,monos-ops,admin,schalamani-tc,, +tmo-notify-proxy,monos-ops,admin,cpaulino-tc,,Carlos Paulino +tmo-notify-proxy,wavelo-security,admin,msahai-tc,,Michael Sahai +tmo-notify-proxy,wavelo-security,admin,sarentz-tc,,Stefan Arentz +tmo-notify-proxy,,,epirogov-tc,admin,Evgueni Pirogov +tmo-notify-proxy,,,ibamieh-tc,admin,Izzy +tmo-notify-proxy,,,staghavizadeh-tc,admin,SamZadeh +tmo-notify-proxy,,,asunderland-tc,admin,Andrew S +tmo-notify-proxy,,,gwitecki-tc,admin,Gwendolyn Witecki +tmo-notify-proxy,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +tmo-notify-proxy,,,kcorreia-tc,admin,Kleber Correia +tmo-notify-proxy,,,ppanganiban-tc,admin,Perlanie +tmo-notify-proxy,,,svaz-tc,admin,svaz-tc +tmo-notify-proxy,,,msaleh-tc,admin,Mohammad Saleh +tmo-notify-proxy,,,rserradura-tc,admin, +tmobile-netcracker-proxy,wavelo-security,admin,msahai-tc,,Michael Sahai +tmobile-netcracker-proxy,wavelo-security,admin,sarentz-tc,,Stefan Arentz +tmobile-netcracker-proxy,,,epirogov-tc,admin,Evgueni Pirogov +tmobile-netcracker-proxy,,,staghavizadeh-tc,admin,SamZadeh +tmobile-netcracker-proxy,,,asunderland-tc,admin,Andrew S +tmobile-netcracker-proxy,,,gwitecki-tc,admin,Gwendolyn Witecki +tmobile-netcracker-proxy,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +tmobile-netcracker-proxy,,,kcorreia-tc,admin,Kleber Correia +tmobile-netcracker-proxy,,,svaz-tc,admin,svaz-tc +tmobile-netcracker-proxy,,,msaleh-tc,admin,Mohammad Saleh +tmobile-netcracker-proxy-api,wavelo-security,admin,msahai-tc,,Michael Sahai +tmobile-netcracker-proxy-api,wavelo-security,admin,sarentz-tc,,Stefan Arentz +tmobile-netcracker-proxy-api,,,ibamieh-tc,admin,Izzy +tmobile-netcracker-proxy-api,,,staghavizadeh-tc,admin,SamZadeh +tmobile-netcracker-proxy-api,,,asunderland-tc,admin,Andrew S +tmobile-netcracker-proxy-api,,,gwitecki-tc,admin,Gwendolyn Witecki +tmobile-netcracker-proxy-api,,,vwijesooriya-tc,admin,Viduranga Wijesooriya +turbine,monos-ops,admin,adutton-tc,,Andrew Dutton +turbine,monos-ops,admin,pmcconnell-tc,,Patrick McConnell +turbine,monos-ops,admin,jmercer-tc,,Jim Mercer +turbine,monos-ops,admin,aafuwape-tc,,Anthony Afuwape +turbine,monos-ops,admin,kpatel-tc,, +turbine,monos-ops,admin,mbolisay-tc,, +turbine,monos-ops,admin,mse-bot-tc,, +turbine,monos-ops,admin,rmokkapati-tc,, +turbine,monos-ops,admin,schalamani-tc,, +turbine,monos-ops,admin,cpaulino-tc,,Carlos Paulino +turbine,wavelo-security,admin,msahai-tc,,Michael Sahai +turbine,wavelo-security,admin,sarentz-tc,,Stefan Arentz +turbine,,,ccramer-tc,admin,Chad Cramer +turbine,,,asunderland-tc,admin,Andrew S +turbine,,,bpierrette-tc,admin, +turbine,,,tcurvelo-tc,admin,Thiago Curvelo +verizon-proxy,,,ccramer-tc,admin,Chad Cramer +verizon-proxy,,,aeldaly-tc,admin,Ahmed El-Daly +verizon-proxy,,,mbolisay-tc,admin, +verizon-proxy,,,jcracchiolo-tc,admin,Joseph Cracchiolo +verizon-proxy,,,mvanlammeren-tc,admin,Mike van Lammeren diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..37da49f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = { find = { where = ["."] } } + +[project] +name = "opencepk-lib-python-common" +version = "1.0.0" +description = "Python package and pre-commit-hook for finding and replacing string(s) in file(s)." +readme = "README.md" +license = { text = "GPLv3" } +authors = [{name = "OpenCEPK Open Cloud Engineering Platform Kit", email = "opencepk@gmail.com"}] +requires-python = ">=3.9" + +keywords = ["find", "replace", "string", "file", "pre-commit", "hook", "git", "tool", "utility", "opencepk"] +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Natural Language :: English", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Topic :: File Formats :: JSON", + "Topic :: Software Development :: Pre-processors", + "Topic :: Software Development :: Version Control :: Git", + "Topic :: Text Processing", + "Topic :: Text Processing :: Filters", + "Topic :: Text Processing :: General", + "Topic :: Utilities" +] + +[project.entry-points."console_scripts"] +python-pypi-version-check = "opencepk_lib_python_common.pypi_bumpversion_check_package.pypi_bumpversion_check.main:main" +find-and-replace-strings = "opencepk_lib_python_common.find_and_replace_strings_package.find_and_replace_strings.main:main" + +[project.optional-dependencies] +dep = ["toml"] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2081745 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +build>=0.7.0 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b86cb19 --- /dev/null +++ b/setup.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +from setuptools import find_packages +from setuptools import setup + + +# setup( +# name='python-pypi-version-check', +# description='Pre-commit hooks for terraform_docs_replace', +# url='https://github.com/opencepk/opencepk-lib-python-common', +# version_format='{tag}+{gitsha}', + +# author='Contributors', + +# classifiers=[ +# "Programming Language :: Python", +# "Programming Language :: Python :: 3", +# "Programming Language :: Python :: 3 :: Only", +# "Programming Language :: Python :: 3.6", +# "Programming Language :: Python :: 3.7", +# "Programming Language :: Python :: 3.8", +# "Programming Language :: Python :: 3.9", +# "Programming Language :: Python :: 3.10", +# "Programming Language :: Python :: 3.11", +# "Programming Language :: Python :: 3.12", +# "Development Status :: 4 - Beta", +# "Intended Audience :: Developers", +# "Natural Language :: English", +# "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", +# "Topic :: File Formats :: JSON", +# "Topic :: Software Development :: Pre-processors", +# "Topic :: Software Development :: Version Control :: Git", +# "Topic :: Text Processing", +# "Topic :: Text Processing :: Filters", +# "Topic :: Text Processing :: General", +# "Topic :: Utilities" +# ], + +# packages=find_packages(exclude=('tests*', 'testing*')), +# install_requires=[ +# 'setuptools-git-version', +# ], +# entry_points={ +# 'console_scripts': [ +# 'python-pypi-version-check = hooks.pypi_bumpversion_check.main:main', +# 'python-pypi-version-check-test = hooks.pypi_bumpversion_check.main:main' + +# ], +# }, +# ) + + +# python-pypi-version-check /Users/hamed/Desktop/tucows-code/find-and-replace-strings/pyproject.toml +# This version is already published. Please bump the version in pyproject.toml. + + +setup()