From 00bbb5bb64db712e8c99d53491b7b40b494a660e Mon Sep 17 00:00:00 2001 From: saville Date: Mon, 14 Jul 2025 10:39:21 -0600 Subject: [PATCH 1/3] Use mariadb commands instead of mysql for test managers --- dysql/test_managers.py | 14 +++++++------- setup.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dysql/test_managers.py b/dysql/test_managers.py index eb71b10..e218f4e 100644 --- a/dysql/test_managers.py +++ b/dysql/test_managers.py @@ -49,7 +49,7 @@ def __init__( :param username: the username to access the test database :param password: the password to access the test database :param db_name: the name of the test database - :param schema_db_name: the name of the DB to duplicate schema from (using mysqldump) + :param schema_db_name: the name of the DB to duplicate schema from (using mariadb-dump) :param docker_container: the name of the docker container where the database is running (if in docker) :param keep_db: This prevents teardown from removing the created database after running tests which can be helpful in debugging @@ -184,7 +184,7 @@ def __init__( ): # pylint: disable=too-many-arguments """ :param db_name: the name you want for your test database - :param schema_db_name: the name of the DB to duplicate schema from (using mysqldump) + :param schema_db_name: the name of the DB to duplicate schema from (using mariadb-dump) :param echo_queries: True if you want to see queries :param keep_db: This prevents teardown from removing the created DB after running tests which can be helpful in debugging @@ -206,20 +206,20 @@ def __init__( def _create_test_db(self) -> None: self._run( - f'mysql -p{self.password} -h{self.host} -N -e "DROP DATABASE IF EXISTS {self.db_name}"' + f'mariadb -p{self.password} -h{self.host} -N -e "DROP DATABASE IF EXISTS {self.db_name}"' ) self._run( - f'mysql -p{self.password} -h{self.host} -s -N -e "CREATE DATABASE IF NOT EXISTS {self.db_name}"' + f'mariadb -p{self.password} -h{self.host} -s -N -e "CREATE DATABASE IF NOT EXISTS {self.db_name}"' ) if self.schema_db_name: self._run( - f"mysqldump --no-data -p{self.password} {self.schema_db_name} -h{self.host} " - f"| mysql -p{self.password} {self.db_name} -h{self.host}" + f"mariadb-dump --no-data -p{self.password} {self.schema_db_name} -h{self.host} " + f"| mariadb -p{self.password} {self.db_name} -h{self.host}" ) def _tear_down_test_db(self) -> None: self._run( - f'echo "DROP DATABASE IF EXISTS {self.db_name} " | mysql -p{self.password} -h{self.host}' + f'echo "DROP DATABASE IF EXISTS {self.db_name} " | mariadb -p{self.password} -h{self.host}' ) @sqlquery(mapper=CountMapper()) diff --git a/setup.py b/setup.py index 16a007e..1591197 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup, find_packages -BASE_VERSION = "3.0" +BASE_VERSION = "3.1" SOURCE_DIR = os.path.dirname(os.path.abspath(__file__)) DYSQL_DIR = os.path.join(SOURCE_DIR, "dysql") VERSION_FILE = os.path.join(DYSQL_DIR, "version.py") From ab07c76830d73a0c21698685c3bdf6b11cdc89df Mon Sep 17 00:00:00 2001 From: saville Date: Mon, 14 Jul 2025 11:17:20 -0600 Subject: [PATCH 2/3] Upgrade test dependencies --- test_requirements.txt | 91 ++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/test_requirements.txt b/test_requirements.txt index 50e8d0b..63e4bd0 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -4,104 +4,107 @@ # # pip-compile test_requirements.in # -attrs==23.1.0 + +attrs==25.3.0 # via # cattrs # lsprotocol - # pytest -cattrs==23.2.3 - # via lsprotocol -certifi==2023.11.17 +cachetools==6.1.0 + # via tox +cattrs==25.1.1 + # via + # lsprotocol + # pygls +certifi==2025.7.14 # via requests cfgv==3.4.0 # via pre-commit -charset-normalizer==3.3.2 +chardet==5.2.0 + # via tox +charset-normalizer==3.4.2 # via requests -coverage==7.3.4 +colorama==0.4.6 + # via tox +coverage[toml]==7.9.2 # via pytest-cov -distlib==0.3.8 +distlib==0.3.9 # via virtualenv docker==6.1.3 # via -r test_requirements.in -filelock==3.13.1 +filelock==3.18.0 # via # tox # virtualenv -identify==2.5.33 +identify==2.6.12 # via pre-commit -idna==3.6 +idna==3.10 # via requests -iniconfig==2.0.0 +iniconfig==2.1.0 # via pytest -lsprotocol==2023.0.0 +lsprotocol==2023.0.1 # via # pygls # ruff-lsp -nodeenv==1.8.0 +nodeenv==1.9.1 # via pre-commit -packaging==23.2 +packaging==25.0 # via # docker + # pyproject-api # pytest # ruff-lsp # tox -platformdirs==4.1.0 +platformdirs==4.3.8 # via # tox # virtualenv -pluggy==0.13.1 +pluggy==1.6.0 # via # pytest + # pytest-cov # tox pre-commit==3.5.0 # via -r test_requirements.in -py==1.11.0 - # via - # pytest - # tox -pygls==1.2.1 +pygls==1.3.1 # via ruff-lsp -pytest==6.2.4 +pygments==2.19.2 + # via pytest +pyproject-api==1.9.1 + # via tox +pytest==8.4.1 # via # -r test_requirements.in # pytest-cov # pytest-randomly -pytest-cov==2.12.1 +pytest-cov==6.2.1 # via -r test_requirements.in -pytest-randomly==3.10.1 +pytest-randomly==3.16.0 # via -r test_requirements.in -pyyaml==6.0.1 +pyyaml==6.0.2 # via pre-commit -requests==2.31.0 +requests==2.32.4 # via docker -ruff==0.1.8 +ruff==0.12.3 # via # -r test_requirements.in # ruff-lsp -ruff-lsp==0.0.48 +ruff-lsp==0.0.62 # via -r test_requirements.in -six==1.16.0 - # via tox -toml==0.10.2 - # via - # pytest - # pytest-cov -tox==3.28.0 +tox==4.27.0 # via tox-pyenv tox-pyenv==1.1.0 # via -r test_requirements.in -typing-extensions==4.9.0 - # via ruff-lsp -urllib3==2.1.0 +typing-extensions==4.14.1 + # via + # cattrs + # ruff-lsp +urllib3==2.5.0 # via # docker # requests -virtualenv==20.25.0 +virtualenv==20.31.2 # via # pre-commit # tox -websocket-client==1.7.0 +websocket-client==1.8.0 # via docker - -# The following packages are considered to be unsafe in a requirements file: -# setuptools From 05f4b778e6f9f7f71e2c3878dd3ed1360d8d0961 Mon Sep 17 00:00:00 2001 From: saville Date: Mon, 14 Jul 2025 11:21:33 -0600 Subject: [PATCH 3/3] Convert to using pyproject.toml and build module --- .github/workflows/build.yaml | 54 ++++++++++++++++++--- BASE_VERSION | 1 + MANIFEST.in | 1 - pyproject.toml | 24 ++++++++++ requirements.txt | 8 ++-- scripts/write-version.py | 36 ++++++++++++++ setup.py | 91 ------------------------------------ 7 files changed, 112 insertions(+), 103 deletions(-) create mode 100644 BASE_VERSION delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml create mode 100644 scripts/write-version.py delete mode 100644 setup.py diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c46ef00..16efa80 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,7 +37,40 @@ jobs: with: files: test-reports/test-results.xml check_name: "Test Results ${{ matrix.python-version }}" - publish: + get-version: + if: github.repository == 'adobe/dy-sql' + runs-on: ubuntu-latest + needs: test + outputs: + current-version: ${{ steps.version-number.outputs.CURRENT_VERSION }} + steps: + - uses: actions/checkout@v2 + with: + # Fetch all history instead of the latest commit + fetch-depth: 0 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Write version file + run: python scripts/write-version.py + - name: Get current version + id: version-number + run: echo "CURRENT_VERSION=$( python -c 'from dysql.version import __version__; print(__version__)' )" >> $GITHUB_OUTPUT + - name: Print current version + run: echo CURRENT_VERSION ${{ steps.version-number.outputs.CURRENT_VERSION }} + tag-commit: + if: github.repository == 'adobe/dy-sql' && github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + needs: [test, get-version] + steps: + - uses: actions/checkout@v2 + with: + # Fetch all history instead of the latest commit + fetch-depth: 0 + - name: Tag commit + run: git tag ${{ needs.get-version.outputs.current-version }} && git push --tags + publish-pypi: if: github.repository == 'adobe/dy-sql' runs-on: ubuntu-latest needs: test @@ -49,20 +82,27 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.9 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install wheel build - name: Remove version file # This is just in case something else created it, destroy it to get a fresh version run: rm -f dysql/version.py - - name: Install wheel - run: pip install wheel + - name: Write version file + run: python scripts/write-version.py - name: Build - run: python setup.py sdist bdist_wheel + run: python -m build - name: Check upload - run: pip install twine && twine check dist/* + # packaging needs updating due to https://github.com/pypa/twine/issues/1216 + run: pip install -U twine packaging && twine check dist/* - name: Publish to PyPi + uses: pypa/gh-action-pypi-publish@release/v1 # Only publish on pushes to main if: github.event_name == 'push' && github.ref == 'refs/heads/main' - uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.ADOBE_BOT_PYPI_TOKEN }} + diff --git a/BASE_VERSION b/BASE_VERSION new file mode 100644 index 0000000..8c50098 --- /dev/null +++ b/BASE_VERSION @@ -0,0 +1 @@ +3.1 diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 42eb410..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include LICENSE.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..31fb3b7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "dy-sql" +description = "Dynamically runs SQL queries and executions." +readme = "README.rst" +requires-python = ">=3.9" +license = {text = "MIT"} +authors = [ + {name = "Adobe", email = "noreply@adobe.com"} +] +urls = { "Homepage" = "https://github.com/adobe/dy-sql" } + +dynamic = ["version", "dependencies", "optional-dependencies"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {test = { file = ["test_requirements.txt"] }} +version = {attr = "dysql.version.__version__"} + +[tool.setuptools.packages.find] +exclude = ["*.tests", "*.tests.*", "tests.*", "tests"] diff --git a/requirements.txt b/requirements.txt index e3a4fc3..97817ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e . - -# Used in development, and as an extra -pydantic>2 +# SQLAlchemy 2+ is not yet supported +sqlalchemy<2 +# now using features only found in pydantic 2+ +pydantic>=2 diff --git a/scripts/write-version.py b/scripts/write-version.py new file mode 100644 index 0000000..ad053fe --- /dev/null +++ b/scripts/write-version.py @@ -0,0 +1,36 @@ +""" +Copyright 2025 Adobe +All Rights Reserved. + +NOTICE: Adobe permits you to use, modify, and distribute this file in accordance +with the terms of the Adobe license agreement accompanying it. +""" +import subprocess +from pathlib import Path + + +def main(): + base_dir = Path(__file__).parent.parent + base_version_file = base_dir / "BASE_VERSION" + + base_version = base_version_file.read_text(encoding="utf8").strip() + + major, minor = map(int, base_version.split(".")[:2]) + + try: + commit_count = ( + subprocess.check_output(["git", "rev-list", "--count", "HEAD"]) + .strip() + .decode("utf-8") + ) + except Exception: + commit_count = "0" + + version_file = base_dir / "dysql" / "version.py" + + version = f"{major}.{minor}.{commit_count}" + version_file.write_text(f'__version__ = "{version}"\n', encoding="utf8") + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py deleted file mode 100644 index 1591197..0000000 --- a/setup.py +++ /dev/null @@ -1,91 +0,0 @@ -import importlib.machinery -import os -import subprocess -import types - -from setuptools import setup, find_packages - - -BASE_VERSION = "3.1" -SOURCE_DIR = os.path.dirname(os.path.abspath(__file__)) -DYSQL_DIR = os.path.join(SOURCE_DIR, "dysql") -VERSION_FILE = os.path.join(DYSQL_DIR, "version.py") - - -def get_version(): - """ - Call out to the git command line to get the current commit "number". - """ - if os.path.exists(VERSION_FILE): - # Read version from file - loader = importlib.machinery.SourceFileLoader("dysql_version", VERSION_FILE) - version_mod = types.ModuleType(loader.name) - loader.exec_module(version_mod) - existing_version = version_mod.__version__ # pylint: disable=no-member - print(f"Using existing dysql version: {existing_version}") - return existing_version - - # Generate the version from the base version and the git commit number, then store it in the file - try: - cmd = subprocess.Popen( - args=[ - "git", - "rev-list", - "--count", - "HEAD", - ], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - encoding="utf8", - ) - stdout = cmd.communicate()[0] - output = stdout.strip() - if cmd.returncode == 0: - new_version = "{0}.{1}".format(BASE_VERSION, output) - print(f"Setting version to {new_version}") - - # write the version file - if os.path.exists(DYSQL_DIR): - with open(VERSION_FILE, "w", encoding="utf8") as fobj: - fobj.write(f"__version__ = '{new_version}'\n") - return new_version - except Exception as exc: - print(f"Could not generate version from git commits: {exc}") - # If all else fails, use development version - return f"{BASE_VERSION}.DEVELOPMENT" - - -with open(os.path.join(os.path.dirname(__file__), "README.rst")) as fobj: - long_description = fobj.read().strip() - - -setup( - name="dy-sql", - version=get_version(), - license="MIT", - description="Dynamically runs SQL queries and executions.", - long_description=long_description, - long_description_content_type="text/x-rst", - author="Adobe", - author_email="noreply@adobe.com", - url="https://github.com/adobe/dy-sql", - platforms=["Any"], - packages=find_packages(exclude=("*test*",)), - zip_safe=False, - install_requires=[ - # SQLAlchemy 2+ is not yet submitted - "sqlalchemy<2", - # now using features only found in pydantic 2+ - "pydantic>=2", - ], - classifiers=[ - "Development Status :: 4 - Beta", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - ], -)