GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - uranusjr/simpleindex

BranchesTags
Open more actions menu

Latest commit

 

History

56 Commits
56 Commits

Folders and files

NameName
Last commit message
Last commit date
src/simpleindex
src/simpleindex
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

PEP 503 Simple Repository from routing rules

Install simpleindex (pipx is recommended):

$ pipx install simpleindex

Generate distributions:

$ tree .
.
├── configuration.toml
├── uranusjr-core
│   ├── uranusjr_core-1.0.py3.none-any.whl
│   └── uranusjr_core-2.0.py3.none-any.whl
└── uranusjr-web
    └── uranusjr_web-2.0.py3.none-any.whl

Write a configuration:

# ./configuration.toml

# Serve local files for packages with prefix "uranusjr-".
[routes."uranusjr-{subproject}"]
source = "path"
to = "./uranusjr-{subproject}"

# Otherwise use PyPI.
[routes."{project}"]
source = "http"
to = "https://pypi.org/simple/{project}/"

[server]
host = "127.0.0.1"
port = 8000

Run the server:

$ simpleindex /path/to/configuration.toml

Install projects:

$ python -m pip install -i http://127.0.0.1:8000 uranusjr-web

Custom route types

simpleindex can be made aware of new route types via the simpleindex.routes entry point group.

A new route type should subclass simpleindex.routes.Route, and implement behaviour to respond to HTTP requests.

The Route instance has two attributes:

  • root: A pathlib.Path pointing to the directory containing the configuration file current being served.
  • to: The to string in the configuration block.

For example, here's how you might want to implement Amazon S3 support:

# simpleindex_s3.py

from simpleindex.routes import Response, Route

class AmazonS3Route(Route):
    async def get_page(self, params: dict[str, Any]) -> Response:
        # "params" is a mapping of parameters captured from the URL.
        s3_bucket = self.to.format(**params)
        list_of_files = _list_s3_files(s3_bucket)
        html = _create_html_for_files(list_of_files)
        return Response(status_code=200, content=html, media_type="text/html")

Response accepts an optional argument headers if you want to add additional response headers.

Now add the class to the entry point group:

# setup.cfg

[options.entry_points]
simpleindex.routes =
    s3 = simpleindex_s3:AmazonS3Route

You'll be able to use source = "s3" in the a routes block after installing the package:

$ pipx inject simpleindex simpleindex-s3

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

57 stars

Watchers

3 watching

Forks

10 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.