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

Use pyproject.toml + optional PDM #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm-project.org/#use-with-ide
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
38 changes: 16 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,37 @@

This is a Flask app generating a draft .zip of a YunoHost application after filling a form

Official instance: https://appgenerator.yunohost.org/
Official instance: <https://appgenerator.yunohost.org>

## Developement

You can use [PDM](https://pdm-project.org) to install deps and run the app.

```bash
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
# Generate the virtualenv
pdm install

# you need to manually download the assets to have access to the css and the javascript files
(cd static && bash fetch_assets)
# Fetch the css and javascript assets (only to be run once or after a git pull)
pdm run fetch_assets
```

And then start the dev server:
And then start the dev server (you can pass arguments that will be passed to Flask):

```bash
source venv/bin/activate
FLASK_APP=app.py FLASK_ENV=development flask --debug run
pdm run start
```

## Translation

It's based on Flask-Babel : <https://python-babel.github.io/flask-babel/>

```bash
source venv/bin/activate

# Extract the english sentences from the code, needed if you modified it
pybabel extract --ignore-dirs venv -F babel.cfg -o messages.pot .
You can use PDM to run the commands:

# If working on a new locale: initialize it (in this example: fr)
pybabel init -i messages.pot -d translations -l fr
# Otherwise, update the existing .po:
pybabel update -i messages.pot -d translations
```bash
pdm run update_translations
```

# ... translate stuff in translations/<lang>/LC_MESSAGES/messages.po
# re-run the 'update' command to let Babel properly format the text
# then compile:
pybabel compile -d translations
To initialize a new locale (here, fr):
```bash
pdm run translation_create fr
```
62 changes: 28 additions & 34 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
import re
import os
#!/usr/bin/env python3

import hashlib
import urllib.request
import importlib
import logging
import zipfile
import os
import random
import re
import string
import tomllib
import urllib.request
import zipfile
from io import BytesIO
from flask import (
Flask,
render_template,
render_template_string,
request,
redirect,
send_file,
make_response,
session,
)
from pathlib import Path

from flask import (Flask, make_response, redirect, render_template,
render_template_string, request, send_file, session)
from flask_babel import Babel
from flask_babel import lazy_gettext as _
from flask_wtf import FlaskForm
from flask_babel import Babel, lazy_gettext as _

from wtforms import (
StringField,
SelectField,
SubmitField,
TextAreaField,
BooleanField,
SelectMultipleField,
HiddenField,
)
from wtforms.validators import (
DataRequired,
Optional,
Regexp,
URL,
Length,
)

YOLOGEN_VERSION = "0.20"
from wtforms import (BooleanField, HiddenField, SelectField,
SelectMultipleField, StringField, SubmitField,
TextAreaField)
from wtforms.validators import URL, DataRequired, Length, Optional, Regexp


def get_version():
source_location = Path(__file__).parent
if (pyproject := (source_location / "pyproject.toml")).exists():
return tomllib.loads(pyproject.read_text())['project']['version']
else:
return importlib.metadata.version("package")


__version__ = get_version()
LANGUAGES = {"en": _("English"), "fr": _("French")}

###############################################################################
Expand Down
Loading