diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 78818cc0..88f37f7b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,7 +18,9 @@ jobs: cache: 'pip' - name: Install requirements - run: pip install -r requirements.txt + run: | + pip install "." + pip install ".[dev]" - name: Run all pre-commit hooks run: make lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa9d8e67..8d2f00a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: run: pip install -e '.[cassandra]' - name: Install testing requirements (not included by default in normal install) - run: pip install -r requirements.testing.txt + run: pip install ".[dev]" - name: Execute unit-tests run: make unittest diff --git a/Makefile b/Makefile index 5559c333..3970fe46 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ PROTODIR=astacus/proto PROTOBUFS = $(wildcard $(PROTODIR)/*.proto) GENERATED_PROTOBUFS = $(patsubst %.proto,%_pb2.py,$(PROTOBUFS)) -GENERATED = astacus/version.py $(GENERATED_PROTOBUFS) +GENERATED = $(GENERATED_PROTOBUFS) PYTHON = python3 DNF_INSTALL = sudo dnf install -y @@ -20,11 +20,20 @@ ZOOKEEPER_HASH = 284cb4675adb64794c63d95bf202d265cebddc0cda86ac86fb0ede8049de918 default: $(GENERATED) venv: default - $(PYTHON) -m venv venv && source venv/bin/activate && pip install -U pip && pip install -r requirements.txt + $(PYTHON) -m venv venv && source venv/bin/activate && pip install -U pip && pip install . ".[dev]" clean: rm -rf rpm/ $(GENERATED) +.PHONY: astacus/version.py +python-build: + $(PYTHON) -m build + +.PHONY: dev-deps +dev-deps: + pip install . + pip install ".[dev]" + .PHONY: build-dep-fedora build-dep-fedora: sudo dnf -y install --best --allowerasing rpm-build @@ -146,8 +155,5 @@ rpm: $(GENERATED) /usr/bin/rpmbuild /usr/lib/rpm/check-buildroot --define 'minor_version $(subst -,.,$(subst $(SHORT_VER)-,,$(LONG_VER)))' $(RM) astacus-rpm-src.tar -astacus/version.py: version_from_git.py - $(PYTHON) $^ $@ - %_pb2.py: %.proto protoc -I $(PROTODIR) $< --python_out=$(PROTODIR) diff --git a/astacus/node/uploader.py b/astacus/node/uploader.py index 5daf3fd8..84b8709c 100644 --- a/astacus/node/uploader.py +++ b/astacus/node/uploader.py @@ -27,7 +27,7 @@ def write_hashes_to_storage( parallel: int, progress: Progress, still_running_callback=lambda: True, - validate_file_hashes: bool = True + validate_file_hashes: bool = True, ): todo = [ (hexdigest, list(snapshot.get_files_for_digest(hexdigest))) diff --git a/pyproject.toml b/pyproject.toml index f86f32e7..724607c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,83 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "astacus" +authors = [ + { name="Aiven", email="opensource@aiven.io" }, +] +description = "Astacus, cluster (database) backup tool" +readme = "README.md" +requires-python = ">=3.11" +classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3.11", + "Topic :: Database :: Database Engines/Servers", + "Topic :: Software Development :: Libraries", +] +license = { text = "Apache License 2.0" } +dynamic = ["version"] +dependencies = [ + "fastapi", + "httpx", + "msgspec", + "kazoo", + "protobuf < 3.21", + "pydantic", + "pyyaml", + "rohmu >= 2.2.0", + "sentry-sdk", + "tabulate", + "typing-extensions >= 4.7.1", + "uvicorn==0.15.0", + "wcmatch", +] + +[project.optional-dependencies] +dev = [ + # makefile convenience" + "pre-commit>=2.20.0", + # pre-commit tasks in Makefile need these" + "anyio==3.5.0", + "pylint==2.15.5", + "pytest-asyncio==0.21.1", + "pytest-cov==3.0.0", + "pytest-mock==3.3.1", + "pytest-order==1.0.0", + "pytest-timeout==1.4.2", + "pytest-watch==4.2.0", + "pytest==7.2.2", + # pinning mypy to the same version as pre-commit" + "mypy==1.0.0", + # types for things that don't seem to have them" + "types-PyYAML>=6.0.12.2", + "types-tabulate>=0.9.0.0", + "types-urllib3>=1.26.25.4", + "typing_extensions>=4.4.0", + "freezegun>=1.2", + "respx==0.20.1", +] + +[project.urls] +"Homepage" = "https://github.com/Aiven-Open/astacus" +"Bug Tracker" = "https://github.com/Aiven-Open/astacus/issues" + +[project.scripts] +astacus = "astacus.main:main" + + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "astacus/version.py" + + [tool.black] line-length = 125 diff --git a/requirements.testing.txt b/requirements.testing.txt deleted file mode 100644 index 5ff9a6a1..00000000 --- a/requirements.testing.txt +++ /dev/null @@ -1,32 +0,0 @@ -# makefile convenience -pre-commit>=2.20.0 - -# pre-commit tasks in Makefile need these -anyio==3.5.0 -pylint==2.17.4 -# Note breaking change in 0.23. -# https://github.com/pytest-dev/pytest-asyncio/issues/706 -pytest-asyncio==0.21.1 -pytest-cov==3.0.0 -pytest-mock==3.10.0 -pytest-order==1.0.0 -pytest-timeout==1.4.2 -pytest-watch==4.2.0 -pytest==7.2.2 - -# pinning mypy to the same version as pre-commit -mypy==1.8.0 - -# types for things that don't seem to have them -types-PyYAML>=6.0.12.2 -types-requests>=2.28.11.5 -types-tabulate>=0.9.0.0 -types-ujson>=5.9.0.0 -types-urllib3>=1.26.25.4 -typing_extensions>=4.7.1 - -# F38 -coverage==7.0.5 - -freezegun>=1.2 -respx==0.20.1 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 1ae52b9f..00000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r requirements.testing.txt --e . diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c8686413..00000000 --- a/setup.cfg +++ /dev/null @@ -1,27 +0,0 @@ -[metadata] -name = astacus -description = Astacus, cluster (database) backup tool -long_description = file: README.md -url= https://github.com/aiven/astacus/ - -[options] -zip_safe = False - -# SKIP-IN-RPM -install_requires = - PyYAML==6.0 - fastapi==0.99.0 - httpx==0.24.1 - msgspec==0.18.6 - protobuf==3.19.4 - rohmu>=2.2.0,<3 - sentry-sdk==1.6.0 - tabulate==0.9.0 - typing-extensions==4.7.1 - uvicorn==0.15.0 - wcmatch==8.4.1 - # Pinned transitive deps - pydantic==1.10.9 - - # Clickhouse support - kazoo==2.8.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 957a578a..00000000 --- a/setup.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -astacus - setup - -Copyright (c) 2020 Aiven Ltd -See LICENSE for details -""" -import setuptools - - -def _run(): - try: - import version # pylint: disable=import-outside-toplevel - - version_for_setup_py = version.update_project_version("astacus/version.py") - version_for_setup_py = ".dev".join(version_for_setup_py.split("-", 2)[:2]) - except ImportError: - version_for_setup_py = "0.0.1" # tox - - setuptools.setup( - version=version_for_setup_py, - packages=setuptools.find_packages(exclude=["tests"]), - extras_require={ - "cassandra": ["cassandra-driver==3.20.2"], - }, - dependency_links=[], - package_data={}, - entry_points={ - "console_scripts": [ - "astacus = astacus.main:main", - ], - }, - author="Aiven", - author_email="support@aiven.io", - license="Apache 2.0", - platforms=["POSIX", "MacOS"], - description="Astacus", - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Intended Audience :: Information Technology", - "Intended Audience :: System Administrators", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python :: 3.11", - "Topic :: Database :: Database Engines/Servers", - "Topic :: Software Development :: Libraries", - ], - ) - - -if __name__ == "__main__": - _run() diff --git a/tests/utils.py b/tests/utils.py index b0e5cebb..4ba083f8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -92,7 +92,7 @@ def get_clickhouse_version(command: Sequence[str | Path]) -> tuple[int, ...]: def is_cassandra_driver_importable() -> bool: - return importlib.util.find_spec("cassandra") is not None + return importlib.util.find_spec("cassandra") is not None # type: ignore[attr-defined] def format_astacus_command(*arg: str) -> Sequence[str]: diff --git a/version_from_git.py b/version_from_git.py deleted file mode 100644 index a063b850..00000000 --- a/version_from_git.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -version - -Copyright (c) 2019 Aiven Ltd -See LICENSE for details -""" -import importlib.util -import os -import subprocess - - -def save_version(*, new_ver, old_ver, version_file): - "Save new version file, if old_ver != new_ver" - if not new_ver: - return False - version_file = os.path.join(os.path.dirname(__file__), version_file) - if not old_ver or new_ver != old_ver: - with open(version_file, "w") as file_handle: - file_handle.write(f'"""{__doc__}"""\n__version__ = "{new_ver}"\n') - return True - - -def update_project_version(version_file): - "Update the version_file, and return the version number stored in the file" - version_file_full_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), version_file) - module_spec = importlib.util.spec_from_file_location("verfile", version_file_full_path) - module = importlib.util.module_from_spec(module_spec) - file_ver = getattr(module, "__version__", None) - - os.chdir(os.path.dirname(__file__) or ".") - try: - git_out = subprocess.check_output(["git", "describe", "--always"], stderr=getattr(subprocess, "DEVNULL", None)) - except (OSError, subprocess.CalledProcessError): - pass - else: - git_ver = git_out.splitlines()[0].strip().decode("utf-8") - if "." not in git_ver: - git_ver = f"0.0.1-0-unknown-{git_ver}" - if save_version(new_ver=git_ver, old_ver=file_ver, version_file=version_file): - return git_ver - - if not file_ver: - raise ValueError(f"version not available from git or from file {version_file!r}") - - return file_ver - - -if __name__ == "__main__": - import sys - - update_project_version(sys.argv[1])