Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor to suport SQLAlchemy 2.0 migration #82

Merged
merged 6 commits into from
Apr 25, 2023
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
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
python setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -qq -y update \
&& apt-get -qq -y install python3-pip \
pkg-config libicu-dev \
&& apt-get -qq -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pip3 install --no-binary=:pyicu: pyicu
stchris marked this conversation as resolved.
Show resolved Hide resolved

ENV LANG='en_US.UTF-8'

COPY . /opt/servicelayer
RUN pip3 install -q --no-cache-dir -e /opt/servicelayer[dev]
WORKDIR /opt/servicelayer
RUN pip3 install -q --no-cache-dir -e /opt/servicelayer[dev]
RUN pip3 install -r requirements.txt

CMD /bin/bash
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

all: clean install test

build-docker:
docker-compose build --no-rm --parallel

install:
pip install -q -e .
pip install -q twine coverage nose moto boto3
Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
banal==1.0.6
catileptic marked this conversation as resolved.
Show resolved Hide resolved
normality==2.4.0
fakeredis==1.10.1
sqlalchemy==2.0.4
structlog==22.3.0
colorama==0.4.6
pika==1.3.1
16 changes: 10 additions & 6 deletions servicelayer/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, name, uri=settings.TAGS_DATABASE_URI, **config):
self.is_postgres = self.engine.dialect.name == "postgresql"
self.table = Table(
name,
MetaData(self.engine),
MetaData(),
Column("key", String, primary_key=True), # noqa
Column("value", JSONB if self.is_postgres else JSON),
Column("timestamp", DateTime),
Expand All @@ -36,27 +36,31 @@ def delete(self, key=None, prefix=None):
stmt = stmt.where(self.table.c.key == key)
if prefix is not None:
stmt = stmt.where(self.table.c.key.startswith(prefix))
self.engine.execute(stmt)
with self.engine.connect() as conn:
conn.execute(stmt)
conn.commit()

def close(self):
self.engine.dispose()

def get(self, key, since=None):
stmt = select([self.table.c.value])
stmt = select(self.table.c.value)
stmt = stmt.where(self.table.c.key == key)
if since is not None:
stmt = stmt.where(self.table.c.timestamp >= since)
rp = self.engine.execute(stmt)
with self.engine.connect() as conn:
rp = conn.execute(stmt)
row = rp.fetchone()
if row is not None:
return row.value

def exists(self, key, since=None):
stmt = select([func.count()])
stmt = select(func.count())
stmt = stmt.where(self.table.c.key == key)
if since is not None:
stmt = stmt.where(self.table.c.timestamp >= since)
rp = self.engine.execute(stmt)
with self.engine.connect() as conn:
rp = conn.execute(stmt)
count = rp.scalar()
return count > 0

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
include_package_data=True,
zip_safe=True,
install_requires=[
"banal >= 1.0.1, <2.0.0",
"normality >= 2.1.1, <3.0.0",
"fakeredis == 1.10.1",
"sqlalchemy >= 1.3",
"banal >= 1.0.6, < 2.0.0",
"normality >= 2.4.0, < 3.0.0",
"fakeredis == 1.10.1, < 2.0.0",
"sqlalchemy >= 2.0.4, < 3.0.0",
"structlog >= 20.2.0, < 23.0.0",
"colorama >= 0.4.4, < 1.0.0",
"pika == 1.3.1",
"pika >= 1.3.1, < 2.0.0"
],
extras_require={
"amazon": ["boto3 >= 1.11.9, <2.0.0"],
Expand Down