-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
396 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# use a more expressive value range while coverage is still relatively low | ||
coverage: | ||
precision: 2 | ||
round: down | ||
range: "40...100" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM python:3.12.2-alpine3.19 | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Install PostgreSQL development packages required for psycopg | ||
RUN apk add --no-cache postgresql-dev gcc python3-dev musl-dev | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Make the entrypoint script executable | ||
RUN chmod +x /app/entrypoint.sh | ||
|
||
# Set the entrypoint to the script | ||
ENTRYPOINT ["/app/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,12 @@ This will remove packages that have been manually installed locally | |
|
||
uv pip sync requirements.txt test_requirements.txt | ||
|
||
## Testing the Dockerfile works | ||
|
||
docker run --rm -p 8080:6543 -v $PWD/config:/app/config privatim-1 config/development.ini | ||
|
||
then open http://127.0.0.1:8080/ | ||
|
||
|
||
## Miscellaneous | ||
### Javascript dependencies | ||
|
@@ -90,3 +96,5 @@ These files are included in the project. They have been downloaded from these CD | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/tom-select.css" rel="stylesheet"> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/tom-select.complete.min.js"></script> | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "$1" ]; then | ||
echo "No configuration file (input argument) provided. Exiting." | ||
exit 1 | ||
fi | ||
|
||
echo "test" | ||
echo "Running the entrypoint.sh script." | ||
|
||
CONFIG_FILE=$1 | ||
|
||
# Run the upgrade script with the provided config file | ||
python src/privatim/cli/upgrade.py "$CONFIG_FILE" | ||
|
||
python src/privatim/cli/initialize_db.py | ||
|
||
pserve "$CONFIG_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import click | ||
from privatim.cli.add_user import add_user | ||
from privatim.utils import first | ||
|
||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from typing import Iterator | ||
|
||
|
||
@click.group() | ||
def cli() -> None: | ||
pass | ||
|
||
|
||
cli.add_command(add_user) | ||
|
||
|
||
def find_ini_files() -> Iterator[str]: | ||
current_path = os.path.dirname(os.path.abspath(__file__)) | ||
while current_path != os.path.abspath(os.path.join(current_path, '..')): | ||
for filename in os.listdir(current_path): | ||
if filename.endswith('.ini'): | ||
yield os.path.join(current_path, filename) | ||
current_path = os.path.abspath(os.path.join(current_path, '..')) | ||
|
||
|
||
def find_ini_file_or_abort() -> str: | ||
""" Search the file system from the current location for the | ||
development.ini or production.ini file | ||
Returns the absolute path to the .ini file """ | ||
ini_file = first(find_ini_files()) | ||
if click.confirm(f'Found {ini_file} file: continue? y/n'): | ||
click.echo('Continuing...') | ||
return ini_file | ||
else: | ||
click.echo('Stopping.') | ||
click.get_current_context().abort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import click | ||
from pyramid.paster import bootstrap | ||
from pyramid.paster import get_appsettings | ||
|
||
from privatim.models import User | ||
from privatim.orm import get_engine, Base | ||
|
||
|
||
@click.command() | ||
@click.argument('config_uri') | ||
@click.option('--email', prompt=True) | ||
@click.option('--password', prompt=True, hide_input=True) | ||
def add_user(config_uri: str, email: str, password: str) -> None: | ||
|
||
env = bootstrap(config_uri) | ||
settings = get_appsettings(config_uri) | ||
engine = get_engine(settings) | ||
Base.metadata.create_all(engine) | ||
|
||
with env['request'].tm: | ||
dbsession = env['request'].dbsession | ||
|
||
user = User(email=email) | ||
user.set_password(password) | ||
dbsession.add(user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,11 @@ def main(argv: list[str] = sys.argv) -> None: | |
|
||
with env['request'].tm: | ||
db = env['request'].dbsession | ||
add_placeholder_content(db) | ||
add_example_content(db) | ||
|
||
|
||
def add_placeholder_content(db: 'Session') -> None: | ||
def add_example_content(db: 'Session') -> None: | ||
|
||
users = [ | ||
User( | ||
email='[email protected]', | ||
|
@@ -63,6 +64,7 @@ def add_placeholder_content(db: 'Session') -> None: | |
last_name='Huber', | ||
), | ||
] | ||
print(f'Adding users: {users}') | ||
for user in users: | ||
user.set_password('test') | ||
db.add(user) | ||
|
@@ -97,3 +99,7 @@ def add_placeholder_content(db: 'Session') -> None: | |
db.add(consultation) | ||
db.add(status) | ||
db.flush() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from code import InteractiveConsole | ||
import readline | ||
import rlcompleter | ||
|
||
import click | ||
from pyramid.paster import bootstrap | ||
from transaction import commit | ||
|
||
from typing import Any | ||
|
||
from privatim.cli import find_ini_file_or_abort | ||
|
||
|
||
class EnhancedInteractiveConsole(InteractiveConsole): | ||
"""Wraps the InteractiveConsole with some basic shell features: | ||
- horizontal movement (e.g. arrow keys) | ||
- history (e.g. up and down keys) | ||
- very basic tab completion | ||
""" | ||
|
||
def __init__(self, locals: dict[str, Any] | None = None): | ||
super().__init__(locals) | ||
self.init_completer() | ||
|
||
def init_completer(self) -> None: | ||
readline.set_completer( | ||
rlcompleter.Completer( | ||
dict(self.locals) if self.locals else {} | ||
).complete | ||
) | ||
readline.set_history_length(100) | ||
readline.parse_and_bind("tab: complete") | ||
|
||
@click.command() | ||
def shell() -> None: | ||
"""Enters an interactive shell.""" | ||
|
||
config_uri = find_ini_file_or_abort() | ||
assert 'development.ini' in config_uri | ||
|
||
env = bootstrap(config_uri) | ||
with env['request'].tm: | ||
session = env['request'].dbsession | ||
app = env['app'] | ||
shell = EnhancedInteractiveConsole( | ||
{ | ||
|
||
'app': app, | ||
'session': session, | ||
'commit': commit, | ||
} | ||
) | ||
shell.interact( | ||
banner=""" | ||
privatim Shell | ||
================== | ||
Exit the console using exit() or quit(). | ||
Available variables: session | ||
Available functions: commit | ||
""" | ||
) |
Oops, something went wrong.