Austreelis: 2 Move to a src-layout Fix packaging and add shim scripts 16 files changed, 71 insertions(+), 41 deletions(-)
Aaand... I forgot to fetch trunk. Sorry for the noise >.< I'll rebase and resend (again).
Hey, quick heads up while I have some brain space for it: I haven't found the time to re-send the patches yet. I've emailed ~sircmpwn/sr.ht-discuss but didn't got much feedback, nor time to investigate more. The last month has been a bit of a nightmare for me - mainly because I lost housing - so if I play dead: that's not because I gave up or forgot, I actually just don't always have internet access, and time or energy to think about it. I hope to have both in the coming week ! That looks plausible to me at least
Dear Austreelis, Your work is really appreciated but take care of yourself first. I have myself put offpunk on the side for now to focus on some profesionnal deadlines and family time. There’s no hurry. I’m also contemplating more and more the idea of going back to one single file (the "busybox" strategy) and would be happy to discuss that with you. Anyway, rest insured that you will be credited as a contributor to 2.0 release. If you are really motivated, I would be more than happy to discuss the future of your involvment with offpunk. Contributing to a free project should be a source of joy, not of stress nor an obligation. Take care!
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~lioploum/offpunk-devel/patches/45285/mbox | git am -3Learn more about email & git
This moves around and renames a bunch of code, as an effort toward fixing the package build process. Simply put, all source code has been moved in an `src/offpunk` subdirectory, and renamed in ways that (hopefully) make sense. The `pyproject.toml` file has been updated, too. This changes how to import code from offpunk modules: old top-level modules are now under `offpunk` (`import netcache` -> `from offpunk import netcache`), and "off" prefixes have been stripped (`from offutils import run` -> `from offpunk.utils import run`). Note file mode x (execute) was removed on all touched files (if it was set before), meaning they cannot be executed exactly like before this change. Running scripts directly (`./src/offpunk/netcache.py`) is broken because python doesn't populate parent modules of top-level modules. Running `python -m offpunk` still works *if* src/ was added to PYTHONPATH. Signed-off-by: Austreelis <dev@austreelis.net> --- pyproject.toml | 6 ++-- offpunk.py => src/offpunk/__init__.py | 29 +++++++++---------- ansicat.py => src/offpunk/ansicat.py | 11 ++++--- .../offpunk/cache_migration.py | 0 netcache.py => src/offpunk/netcache.py | 9 +++--- opnk.py => src/offpunk/opnk.py | 8 ++--- offthemes.py => src/offpunk/themes.py | 0 offutils.py => src/offpunk/utils.py | 2 +- 8 files changed, 29 insertions(+), 36 deletions(-) rename offpunk.py => src/offpunk/__init__.py (99%) mode change 100755 => 100644 rename ansicat.py => src/offpunk/ansicat.py (99%) mode change 100755 => 100644 rename cache_migration.py => src/offpunk/cache_migration.py (100%) rename netcache.py => src/offpunk/netcache.py (99%) mode change 100755 => 100644 rename opnk.py => src/offpunk/opnk.py (98%) mode change 100755 => 100644 rename offthemes.py => src/offpunk/themes.py (100%) rename offutils.py => src/offpunk/utils.py (99%) diff --git a/pyproject.toml b/pyproject.toml index 41c4843..eb38241 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,9 +45,9 @@ Source = "https://git.sr.ht/~lioploum/offpunk" [project.scripts] offpunk = "offpunk:main" -netcache = "netcache:main" -ansicat = "ansicat:main" -opnk = "opnk:main" +netcache = "offpunk.netcache:main" +ansicat = "offpunk.ansicat:main" +opnk = "offpunk.opnk:main" [tool.flit.sdist] include = ["doc/", "man/", "CHANGELOG"] diff --git a/offpunk.py b/src/offpunk/__init__.py old mode 100755 new mode 100644 similarity index 99% rename from offpunk.py rename to src/offpunk/__init__.py index 8526e03..f1cdff7 --- a/offpunk.py +++ b/src/offpunk/__init__.py @@ -21,12 +21,9 @@ import sys import time import urllib.parse import subprocess -import netcache -import opnk -import ansicat -import offthemes -from offutils import run,term_width,is_local,mode_url,unmode_url -from offutils import _CONFIG_DIR,_DATA_DIR,_CACHE_PATH +from offpunk import ansicat, netcache, opnk, themes +from offpunk.utils import run,term_width,is_local,mode_url,unmode_url +from offpunk.utils import _CONFIG_DIR,_DATA_DIR,_CACHE_PATH try: import setproctitle setproctitle.setproctitle("offpunk") @@ -141,7 +138,7 @@ class GeminiClient(cmd.Cmd): # type sensitivie information. os.umask(0o077) self.opencache = opnk.opencache() - self.theme = offthemes.default + self.theme = themes.default self.prompt = self.set_prompt("ON") self.current_url = None self.hist_index = 0 @@ -208,8 +205,8 @@ class GeminiClient(cmd.Cmd): open_color = "" close_color = "" for c in colors: - if c in offthemes.colors: - ansi = offthemes.colors[c] + if c in themes.colors: + ansi = themes.colors[c] else: ansi = ["32","39"] open_color += "%s;"%ansi[0] @@ -263,8 +260,8 @@ class GeminiClient(cmd.Cmd): return self.complete_add(text,line,begidx,endidx) def complete_theme(self,text,line,begidx,endidx): - elements = offthemes.default - colors = offthemes.colors + elements = themes.default + colors = themes.colors words = len(line.split()) if words <= 1: allowed = elements @@ -528,11 +525,11 @@ Each color can alternatively be prefaced with "bright_".""" print("%s set to %s"%(e,t[e])) else: element = words[0] - if element not in offthemes.default.keys(): + if element not in themes.default.keys(): print("%s is not a valid theme element"%element) print("Valid theme elements are: ") valid = [] - for k in offthemes.default: + for k in themes.default: valid.append(k) print(valid) else: @@ -540,16 +537,16 @@ Each color can alternatively be prefaced with "bright_".""" if element in self.theme.keys(): value = self.theme[element] else: - value = offthemes.default[element] + value = themes.default[element] print("%s is set to %s"%(element,str(value))) else: #Now we parse the colors for w in words[1:]: - if w not in offthemes.colors.keys(): + if w not in themes.colors.keys(): print("%s is not a valid color"%w) print("Valid colors are one of: ") valid = [] - for k in offthemes.colors: + for k in themes.colors: valid.append(k) print(valid) return diff --git a/ansicat.py b/src/offpunk/ansicat.py old mode 100755 new mode 100644 similarity index 99% rename from ansicat.py rename to src/offpunk/ansicat.py index 84a9cb9..774d499 --- a/ansicat.py +++ b/src/offpunk/ansicat.py @@ -10,11 +10,10 @@ import urllib import argparse import mimetypes import fnmatch -import netcache -import offthemes -from offutils import run,term_width,is_local,looks_like_base64 import base64 -from offutils import _DATA_DIR +from offpunk import netcache, themes +from offpunk.utils import run,term_width,is_local,looks_like_base64 +from offpunk.utils import _DATA_DIR try: from readability import Document _HAS_READABILITY = True @@ -161,7 +160,7 @@ class AbstractRenderer(): self.temp_files = {} self.center = center self.last_mode = "readable" - self.theme = offthemes.default + self.theme = themes.default def display(self,mode=None,directdisplay=False): wtitle = self.get_formatted_title() @@ -201,7 +200,7 @@ class AbstractRenderer(): self.disabled_indents = None # each color is an [open,close] pair code self.theme = theme - self.colors = offthemes.colors + self.colors = themes.colors def _insert(self,color,open=True): if open: o = 0 diff --git a/cache_migration.py b/src/offpunk/cache_migration.py similarity index 100% rename from cache_migration.py rename to src/offpunk/cache_migration.py diff --git a/netcache.py b/src/offpunk/netcache.py old mode 100755 new mode 100644 similarity index 99% rename from netcache.py rename to src/offpunk/netcache.py index c325934..1c61f81 --- a/netcache.py +++ b/src/offpunk/netcache.py @@ -13,9 +13,8 @@ import datetime import hashlib import sqlite3 from ssl import CertificateError -import ansicat -import offutils -from offutils import _CACHE_PATH,_DATA_DIR,_CONFIG_DIR +from offpunk import ansicat, utils +from offpunk.utils import _CACHE_PATH,_DATA_DIR,_CONFIG_DIR import time try: import chardet @@ -98,7 +97,7 @@ def is_cache_valid(url,validity=0): # a cache to be valid (in seconds) # If 0, then any cache is considered as valid # (use validity = 1 if you want to refresh everything) - if offutils.is_local(url): + if utils.is_local(url): return True cache = get_cache_path(url) if cache : @@ -838,7 +837,7 @@ def fetch(url,offline=False,download_image_first=True,images_mode="readable",val #Image should exist, should be an url (not a data image) #and should not be already cached if image and not image.startswith("data:image/") and not is_cache_valid(image): - width = offutils.term_width() - 1 + width = utils.term_width() - 1 toprint = "Downloading %s" %image toprint = toprint[:width] toprint += " "*(width-len(toprint)) diff --git a/opnk.py b/src/offpunk/opnk.py old mode 100755 new mode 100644 similarity index 98% rename from opnk.py rename to src/offpunk/opnk.py index 818ce0c..6156628 --- a/opnk.py +++ b/src/offpunk/opnk.py @@ -7,13 +7,11 @@ import os import sys import tempfile import argparse -import netcache -import ansicat -import offutils import shutil import time import fnmatch -from offutils import run,term_width,mode_url,unmode_url,is_local +from offpunk import ansicat, netcache, utils +from offpunk.utils import run,term_width,mode_url,unmode_url,is_local _HAS_XDGOPEN = shutil.which('xdg-open') _GREP = "grep --color=auto" @@ -184,7 +182,7 @@ class opencache(): #we immediately fallback to xdg-open. #netcache currently provide the path if it’s a file. #may this should be migrated here. - if not offutils.is_local(inpath): + if not utils.is_local(inpath): kwargs["images_mode"] = mode cachepath = netcache.fetch(inpath,**kwargs) if not cachepath: diff --git a/offthemes.py b/src/offpunk/themes.py similarity index 100% rename from offthemes.py rename to src/offpunk/themes.py diff --git a/offutils.py b/src/offpunk/utils.py similarity index 99% rename from offutils.py rename to src/offpunk/utils.py index dd716cb..c039916 100644 --- a/offutils.py +++ b/src/offpunk/utils.py @@ -13,7 +13,7 @@ import shutil import shlex import urllib.parse import urllib.parse -import cache_migration +from offpunk import cache_migration CACHE_VERSION = 1 -- 2.41.0
This adds a script for each executable, and a __main__.py for offpunk itself. This intends to "fix" (albeit unperfectly, see below) how the previous commit forbade locally running executables without first installing offpunk in your site packages (even though packaging was broken) or hacking on your PYTHONPATH. Those "glue script", files in the top-level directory and outside offpunk's module, which are purely there to allow running the `netcache`, `ansicat` and `opnk` without any other setup than a working python and a `git clone`. Notably, they will not be included in the packages (sdist/wheel/egg). This commit also migrates from flit to setuptools to build the project. This is because flit got confused by the root offpunk.py script, and disallowed "having two ambiguously named modules". In truth, offpunk.py isn't per se a module (we don't use it like one), and we don't even want to package it. But flit isn't able to distinguish this even with a src layout, unlike setuptools. It also adds a setup.py, even though it just reads the pyproject.toml and builds from that. Co-authored-by: David Zaslavsky <diazona@ellipsix.net> Signed-off-by: Austreelis <dev@austreelis.net> --- MANIFEST.in | 3 +++ ansicat.py | 5 +++++ netcache.py | 5 +++++ offpunk.py | 5 +++++ opnk.py | 5 +++++ pyproject.toml | 15 ++++++++++----- setup.py | 6 ++++++ src/offpunk/__main__.py | 3 +++ 8 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 MANIFEST.in create mode 100755 ansicat.py create mode 100755 netcache.py create mode 100755 offpunk.py create mode 100755 opnk.py create mode 100644 setup.py create mode 100644 src/offpunk/__main__.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ac0410a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include CHANGELOG +graft doc +graft man diff --git a/ansicat.py b/ansicat.py new file mode 100755 index 0000000..e48979d --- /dev/null +++ b/ansicat.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import os, sys +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) +from offpunk.ansicat import main +main() diff --git a/netcache.py b/netcache.py new file mode 100755 index 0000000..25a6ced --- /dev/null +++ b/netcache.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import os, sys +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) +from offpunk.netcache import main +main() diff --git a/offpunk.py b/offpunk.py new file mode 100755 index 0000000..5dc94a7 --- /dev/null +++ b/offpunk.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import os, sys +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) +from offpunk import main +main() diff --git a/opnk.py b/opnk.py new file mode 100755 index 0000000..dce6595 --- /dev/null +++ b/opnk.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import os, sys +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) +from offpunk.opnk import main +main() diff --git a/pyproject.toml b/pyproject.toml index eb38241..25adfa5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["flit_core >=3.2,<4"] -build-backend = "flit_core.buildapi" +requires = ["setuptools >=65.5"] +build-backend = "setuptools.build_meta" [project] name = "offpunk" @@ -23,7 +23,11 @@ classifiers = [ ] keywords = ["gemini", "browser"] requires-python = ">=3.7" -dynamic = ["version", "description"] +description = "Offline-First Gemini/Web/Gopher/RSS reader and browser" +dynamic = ["version"] + +[tool.setuptools.dynamic] +version = {attr = "offpunk.__version__"} [project.license] file = "LICENSE" @@ -49,5 +53,6 @@ netcache = "offpunk.netcache:main" ansicat = "offpunk.ansicat:main" opnk = "offpunk.opnk:main" -[tool.flit.sdist] -include = ["doc/", "man/", "CHANGELOG"] +[tool.setuptools.packages.find] +where = ["src"] +include = ["offpunk"] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..bac24a4 --- /dev/null +++ b/setup.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +import setuptools + +if __name__ == "__main__": + setuptools.setup() diff --git a/src/offpunk/__main__.py b/src/offpunk/__main__.py new file mode 100644 index 0000000..f984c47 --- /dev/null +++ b/src/offpunk/__main__.py @@ -0,0 +1,3 @@ +from offpunk import main +main() + -- 2.41.0
Austreelis <dev@austreelis.net>Aaand... I forgot to fetch trunk. Sorry for the noise >.< I'll rebase and resend (again).
Austreelis <dev@austreelis.net>Hey, quick heads up while I have some brain space for it: I haven't found the time to re-send the patches yet. I've emailed ~sircmpwn/sr.ht-discuss but didn't got much feedback, nor time to investigate more. The last month has been a bit of a nightmare for me - mainly because I lost housing - so if I play dead: that's not because I gave up or forgot, I actually just don't always have internet access, and time or energy to think about it. I hope to have both in the coming week ! That looks plausible to me at least