refactor: restructure project for PyPI packaging

- Added `pyproject.toml` for project metadata and dependency management
- Moved application code to `src/wikimore` directory for better organization
- Updated `launch.json` configuration for Flask app
- Enhanced README with installation, development instructions, and badges
- Introduced `main` function in `app.py` for environment-based configuration

These changes streamline packaging and improve project maintainability.
This commit is contained in:
Kumi 2024-07-16 09:58:18 +02:00
parent 31687723aa
commit ae73156fc9
Signed by: kumi
GPG key ID: ECBCC9082395383F
9 changed files with 107 additions and 10 deletions

3
.vscode/launch.json vendored
View file

@ -10,10 +10,11 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py",
"FLASK_DEBUG": "1",
},
"args": [
"--app",
"wikimore",
"run",
"--no-debugger",
"--no-reload",

View file

@ -1,26 +1,84 @@
# Wikimore - A simple frontend for Wikimedia projects
[![Support Private.coffee!](https://shields.private.coffee/badge/private.coffee-support%20us!-pink?logo=coffeescript)](https://private.coffee)
[![Matrix](https://shields.private.coffee/badge/Matrix-join%20us!-blue?logo=matrix)](https://matrix.pcof.fi/#/#wikimore:private.coffee)
[![PyPI](https://shields.private.coffee/pypi/v/wikimore)](https://pypi.org/project/wikimore/)
[![PyPI - Python Version](https://shields.private.coffee/pypi/pyversions/wikimore)](https://pypi.org/project/wikimore/)
[![PyPI - License](https://shields.private.coffee/pypi/l/wikimore)](https://pypi.org/project/wikimore/)
[![Latest Git Commit](https://shields.private.coffee/gitea/last-commit/privatecoffee/wikimore?gitea_url=https://git.private.coffee)](https://git.private.coffee/privatecoffee/wikimore)
Wikimore is a simple frontend for Wikimedia projects. It uses the MediaWiki API to fetch data from Wikimedia projects and display it in a user-friendly way. It is built using Flask.
This project is still in development and more features will be added in the future. It is useful for anyone who wants to access Wikimedia projects with a more basic frontend, or to provide access to Wikimedia projects to users who cannot access them directly, for example due to state censorship.
## Features
- Multi-language support (currently English and German, more can and will be added)
- Multi-project support (currently Wikipedia and Wiktionary, more can and will be added)
- Supports all Wikimedia projects in all languages
- Search functionality
- Proxy support for Wikimedia images
## Instances
| URL | Provided by | Country | Comments |
| ----------------------------------------------------------- | ----------------------------------------- | ------- | -------- |
| [wikimore.private.coffee](https://wikimore.private.coffee/) | [Private.coffee](https://private.coffee/) | Austria | |
If you operate a public instance of Wikimore and would like to have it listed here, please open an issue or a pull request.
## Installation
### Production
1. Create a virtual environment and activate it
```bash
python3 -m venv venv
source venv/bin/activate
```
2. Install the package from PyPI
```bash
pip install wikimore
```
3. Run the application
```bash
wikimore
```
4. Open your browser and navigate to `http://localhost:8109`
## Development
1. Clone the repository
2. Install the required packages using `pip install -r requirements.txt`
3. Run the app using `python app.py`
## Usage
```bash
git clone https://git.private.coffee/privatecoffee/wikimore.git
cd wikimore
```
1. Open your browser and navigate to `http://localhost:5000`
2. Use the search bar to search for articles on a given Wikimedia project, in a given language
2. Create a virtual environment and activate it
```bash
python3 -m venv venv
source venv/bin/activate
```
3. Install the package in editable mode
```bash
pip install -e .
```
4. Run the application
```bash
flask --app wikimore run
```
5. Open your browser and navigate to `http://localhost:5000`
## License

26
pyproject.toml Normal file
View file

@ -0,0 +1,26 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "wikimore"
version = "0.1.0"
authors = [{ name = "Private.coffee Team", email = "support@private.coffee" }]
description = "A simple frontend for Wikimedia wikis"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
]
dependencies = ["flask", "bs4"]
[project.scripts]
wikimore = "wikimore.app:main"
[project.urls]
"Homepage" = "https://git.private.coffee/privatecoffee/wikimore"
"Bug Tracker" = "https://git.private.coffee/privatecoffee/wikimore/issues"
"Source Code" = "https://git.private.coffee/privatecoffee/wikimore"

3
src/wikimore/__init__.py Normal file
View file

@ -0,0 +1,3 @@
from .app import app
__all__ = ["app"]

View file

@ -3,6 +3,7 @@ import urllib.request
from urllib.parse import urlencode, urlparse
from html import escape
import json
import os
import logging
from bs4 import BeautifulSoup
@ -208,7 +209,15 @@ def search_redirect(project, lang, query):
app.wikimedia_projects, app.languages = get_wikimedia_projects()
print(len(app.wikimedia_projects), len(app.languages))
logger.debug(
f"Loaded {len(app.wikimedia_projects)} Wikimedia projects and {len(app.languages)} languages"
)
def main():
port = int(os.environ.get("PORT", 8109))
host = os.environ.get("HOST", "0.0.0.0")
debug = os.environ.get("DEBUG", False)
app.run(port=port, host=host, debug=debug)
if __name__ == "__main__":
app.run(debug=True)
main()