Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

1 change: 1 addition & 0 deletions BASE_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

14 changes: 7 additions & 7 deletions dysql/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions scripts/write-version.py
Original file line number Diff line number Diff line change
@@ -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()
91 changes: 0 additions & 91 deletions setup.py

This file was deleted.

Loading