Skip to content

Commit

Permalink
Improve project structure, add pre-commit config, pyproject.toml
Browse files Browse the repository at this point in the history
- Add pyproject.toml to simplify installing project dependencies
- Add pre-commit config to run black, isort and mypy before commits
  • Loading branch information
debanjum committed Apr 27, 2024
1 parent ca36a15 commit bb7c99a
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.*
!.gitignore
*~
.vscode
.\#*
\#*\#
remove.txt
Location/L.txt
Location/location_old
**/__pycache__/
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
# Exclude elisp files to not clear page breaks
exclude: \.el$
- id: check-json
- id: check-toml
- id: check-yaml

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
hooks:
- id: mypy
stages: [push, manual]
pass_filenames: false
args:
- --config-file=pyproject.toml
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@ Prequisites
Install
------------

1. Clone this Repository
1. Download and Install
```shell
# Clone the repository
git clone https://github.com/debajum/ai-wallpaper

# Install dependencies
cd ai-wallpaper && pip install .
```

2. Run any of the following commands to paint and update your wallpaper
```python
```shell
# Minimal
KHOJ_API_KEY=<YOUR_KHOJ_API_KEY> python Wallpaper.py
KHOJ_API_KEY=<YOUR_KHOJ_API_KEY> python src/aiwall/paper.py

# With Custom Prompt
KHOJ_API_KEY=<YOUR_KHOJ_API_KEY> python Wallpaper.py "Generate a wallpaper based on the latest news here"
KHOJ_API_KEY=<YOUR_KHOJ_API_KEY> python src/aiwall/paper.py "Generate a wallpaper based on the latest news here"

# With Custom Wallpaper File Path
KHOJ_API_KEY=<YOUR_KHOJ_API_KEY> WALLPAPER_PATH="~/Pictures/wallpaper.png" python Wallpaper.py
KHOJ_API_KEY=<YOUR_KHOJ_API_KEY> WALLPAPER_PATH="~/Pictures/wallpaper.png" python src/aiwall/paper.py

# With Self-hosted Khoj
KHOJ_HOST="http://localhost:42100" python Wallpaper.py
KHOJ_HOST="http://localhost:42100" python src/aiwall/paper.py
```

Extensions
Expand All @@ -54,7 +61,7 @@ Extensions
- Create a simple shell script to call the AI wallpaper creation command
```shell
cd /path/to/ai/wallpaper/folder/
echo "#!/bin/sh\nKHOJ_API_KEY=<YOUR_KHOJ_API_KEY> python $PWD/Wallpaper.py" > wallpaper.sh
echo "#!/bin/sh\nKHOJ_API_KEY=<YOUR_KHOJ_API_KEY> python $PWD/src/aiwall/paper.py" > wallpaper.sh
chmod +x wallpaper.sh
```
- On Android: Use [termux-job-scheduler](https://wiki.termux.com/wiki/Termux:API#:~:text=termux-job-scheduler) on Termux to get yourself a fresh and personal wallpaper painted every 12 hours
Expand Down
80 changes: 80 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "ai-wallpaper"
description = "Create fresh, personal AI painted wallpapers"
readme = "README.md"
license = "GPL-3.0-or-later"
requires-python = ">=3.9"
authors = [
{ name = "Debanjum Singh Solanky" },
]
keywords = [
"AI",
"images",
"khoj",
]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Artistic Software",
"Topic :: Adaptive Technologies",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Intended Audience :: Information Technology",
]
dependencies = [
"rich >= 13.3.1",
"requests >= 2.26.0",
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/debanjum/ai-wallpaper"

[project.scripts]
aiwall = "aiwall.paper:generate"

[project.optional-dependencies]
dev = [
"pytest >= 7.1.2",
"mypy >= 1.0.1",
"black >= 23.1.0",
"pre-commit >= 3.0.4",
]

[tool.hatch.version]
source = "vcs"
raw-options.local_scheme = "no-local-version" # PEP440 compliant version for PyPi

[tool.hatch.build.targets.sdist]
include = ["src/aiwall"]

[tool.hatch.build.targets.wheel]
packages = ["src/aiwall"]

[tool.mypy]
files = "src/aiwall"
pretty = true
strict_optional = false
install_types = true
ignore_missing_imports = true
non_interactive = true
show_error_codes = true
warn_unused_ignores = false

[tool.black]
line-length = 120

[tool.isort]
profile = "black"

[tool.pytest.ini_options]
addopts = "--strict-markers"
File renamed without changes.
Empty file added src/aiwall/__init__.py
Empty file.
8 changes: 6 additions & 2 deletions Wallpaper.py → src/aiwall/paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ def update_wallpaper(prompt):
if khoj_info_notify:
run(notification.format(f"🏕️ Khoj Pasted Wallpaper on Screen"))

def generate():
"Main entrypoint for the script"
prompt = default_prompt if len(sys.argv) != 2 else sys.argv[1]
update_wallpaper(prompt)


# Run the main function
# ---------------------
if __name__ == "__main__":
prompt = default_prompt if len(sys.argv) != 2 else sys.argv[1]
update_wallpaper(prompt)
generate()

0 comments on commit bb7c99a

Please sign in to comment.