diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 6c7cc289..af9cc10b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -16,40 +16,29 @@ jobs: python-version: ["3.8", "3.11", "3.12"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Install poetry + run: pip install poetry - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-test.txt') }} - restore-keys: | - ${{ runner.os }}-pip- + cache: "poetry" + cache-dependency-path: "pyproject.toml" - name: Setup java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '8' - name: Install dependencies run: | - sudo apt-get update - sudo apt-get install python2 - - pip install -U pip setuptools - - pip install . - - if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi + poetry install --with=test - name: Cache binary versions id: cache-versions - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.ccm/repository @@ -63,6 +52,7 @@ jobs: - name: Download versions if: steps.cache-versions.outputs.cache-hit != 'true' run: | + source $(poetry env info --path)/bin/activate normalized=$(echo ${{ inputs.reloc_version }} | tr ':' '_') if [ ! -f ~/.ccm/scylla-repository/unstable/master/$normalized ]; then ./ccm create temp -n 1 --scylla --version unstable/master:${{ inputs.reloc_version }} @@ -73,6 +63,7 @@ jobs: - name: Test with pytest run: | + source $(poetry env info --path)/bin/activate python -m pytest ./tests -x - name: Copy logs/results diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 76013942..f8595b83 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -12,14 +12,14 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v20 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - name: Cache binary versions id: cache-versions - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.ccm/repository diff --git a/.gitignore b/.gitignore index 87d9cb67..19458c73 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ tests/test_results .direnv/ .envrc -ccmlib/tests/ \ No newline at end of file +ccmlib/tests/ + +poetry.lock \ No newline at end of file diff --git a/README.md b/README.md index 9aad3eee..a793f95a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,9 @@ Requirements ------------ - A working python installation (tested to work with python 3.12). -- `pip install -e .` to install the required dependencies. +- [Poetry](https://python-poetry.org/docs/) +- `poetry install` to install the required dependencies. + - This will create virtualenv, you can use `poetry shell` to enter it, see [poetry](https://python-poetry.org/docs/basic-usage/#using-your-virtual-environment) documentation for more details - Java if cassandra is used or older scylla < 6.0 (which version depends on the version of Cassandra you plan to use. If unsure, use Java 8 as it is known to work with current versions of Cassandra). @@ -82,7 +84,8 @@ Installation ccm uses python setuptools (with distutils fallback) so from the source directory run: - sudo ./setup.py install + poetry install + poetry shell ccm is available on the [Python Package Index][pip]: diff --git a/ccm b/ccm index 076baa2a..6adac75f 100755 --- a/ccm +++ b/ccm @@ -40,35 +40,39 @@ def print_global_usage(): exit(1) -common.check_win_requirements() +def main(): + common.check_win_requirements() -if len(sys.argv) <= 1: - print("Missing arguments") - print_global_usage() - -arg1 = sys.argv[1].lower() - -if arg1 in cluster_cmds.cluster_cmds(): - kind = 'cluster' - cmd = arg1 - cmd_args = sys.argv[2:] -else: - if len(sys.argv) <= 2: + if len(sys.argv) <= 1: print("Missing arguments") print_global_usage() - kind = 'node' - node = arg1 - cmd = sys.argv[2] - cmd_args = [node] + sys.argv[3:] - -cmd = get_command(kind, cmd) -if not cmd: - print("Unknown node or command: {0}".format(arg1)) - exit(1) -parser = cmd.get_parser() + arg1 = sys.argv[1].lower() + + if arg1 in cluster_cmds.cluster_cmds(): + kind = 'cluster' + cmd = arg1 + cmd_args = sys.argv[2:] + else: + if len(sys.argv) <= 2: + print("Missing arguments") + print_global_usage() + kind = 'node' + node = arg1 + cmd = sys.argv[2] + cmd_args = [node] + sys.argv[3:] + + cmd = get_command(kind, cmd) + if not cmd: + print("Unknown node or command: {0}".format(arg1)) + exit(1) + + parser = cmd.get_parser() + + (options, args) = parser.parse_args(cmd_args) + cmd.validate(parser, options, args) -(options, args) = parser.parse_args(cmd_args) -cmd.validate(parser, options, args) + cmd.run() -cmd.run() +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..9985b3d0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[tool.poetry] +name = "ccm" +version = "0.1.0" +license = "Apache-2.0" +description = "Cassandra Cluster Manager" +authors = ["Sylvain Lebresne "] +readme = "README.md" +repository = "https://github.com/scylladb/scylla-ccm" +packages = [ + { include = "ccmlib" }, +] + +[tool.poetry.scripts] +ccm = "ccm:main" + +[tool.poetry.dependencies] +python = "^3.8" +ruamel-yaml = "^0.18.6" +psutil = "^6.0.0" +requests = "^2.32.3" +packaging = "^24.1" +boto3 = "^1.35.32" +tqdm = "^4.66.5" +urllib3 = "<2" + +[tool.poetry.group.test.dependencies] +pytest = "*" +awscli = "*" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/requirements-test.txt b/requirements-test.txt deleted file mode 100644 index 1b3d9bbe..00000000 --- a/requirements-test.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest -awscli \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100755 index 94372e82..00000000 --- a/setup.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python - -from os.path import abspath, join, dirname -from platform import system -from shutil import copyfile - -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - -ccmscript = 'ccm' -if system() == "Windows": - copyfile('ccm', 'ccm.py') - ccmscript = 'ccm.py' - -setup( - name='ccm', - version='2.0.5', - description='Cassandra Cluster Manager', - long_description=open(abspath(join(dirname(__file__), 'README.md'))).read(), - author='Sylvain Lebresne', - author_email='sylvain@datastax.com', - url='https://github.com/pcmanus/ccm', - packages=['ccmlib', 'ccmlib.cmds', 'ccmlib.utils'], - scripts=[ccmscript], - install_requires=['ruamel.yaml', 'psutil', 'requests', 'packaging', 'boto3', 'tqdm', 'urllib3<2'], - tests_require=['pytest'], - classifiers=[ - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9' - 'Programming Language :: Python :: 3.11' - 'Programming Language :: Python :: 3.12' - ], - include_package_data=True, -)