Commit Graph

37 Commits

Author SHA1 Message Date
Johannes Faigle c235ef44fd
FEAT: Switch default hash-algo to sha256 (#459)
Closes #452
2023-09-08 12:30:54 +02:00
Christian Clauss abc4bfb418
Upgrade to psf/black stable style 2023 (#474)
* Upgrade to psf/black stable style 2023

* Unpin psf/black
2023-02-02 13:08:09 +01:00
Mason Lin ae3dcf2bbd
feat: 🩺 allow customized health check endpoint (#442)
* feat: 🩺 allow customized health check endpoint

Get the liveness endpoint from the environment variable `HEALTH_ENDPOINT` and verify it. If the customized endpoint is invalied, it will fallback to the DEFAULT_HEALTH_ENDPOINT.

* test:  Test customized endpoint feature

* fix: 🚨 fix check

* feat: Use CLI interface to set health endpoint

* style: 💄 fix black format

* Separate 'build app' and 'add routes'

https://github.com/pypiserver/pypiserver/pull/442#discussion_r973771421

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* keep DEFAULTS in config.py

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* style alignment

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* make CLI arg description more clear

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* style: 🎨 style alignment

* refactor:  SRP, add routes after app created, instead of patching in app_from_config

* style: 🎨 format CLI help

* test:  add test_setup_routes_from_config

* fix: 🐛 test name doesn't work as expected because of using the wrong ids generator.

* test: 🧪 add config error cases for health endpoint

* test:  fix health_endpoint_arg tests

* fix:  Do not fallback to default silently, should raise error

* test: 🧪 add test_health_endpoint in test_main

* test:  setup routes in main

* docs: 📝 Update the help command output in the Quickstart

* docs: 🐛 missing space

* docs: 📝 Add 'Custom Health Check Endpoint' to 'Recipes'

* docs: 📝 refine README

* revert:  revert auto isoft

* build: 💚 fix mypy, missing return types

* Update README.rst

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* Update README.rst

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* Update pypiserver/config.py

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* Update README.rst

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

* style: 💄 black format

* Update README.rst

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>

Co-authored-by: Dmitrii Orlov <dmtree.dev@yahoo.com>
2022-11-02 12:32:20 +01:00
Kian-Meng Ang a67829eea6
chore: Fix typos (#431) 2022-05-23 08:49:18 +00:00
Matthew Planchard 8306de15db
Gunicorn/gevent docker, log fixes, cache busting (#371)
Updates the Docker configuration to use the gunicorn server with gevent
workers by default. Adds `waitress` to the docker container, so that if
no server is specified, we will fall back to that rather than `wsgiref`.

Making this happen brought a few other issues to light, which are also
addressed here.

- Docker log output not immediately being flushed to stdout (#358):
  resolved by setting the `PYTHONUNBUFFERED` env var to `t` in the
  docker container
- When the WSGIRef server is selected, its access logs are written
  directly to stderr, rather than going through the logging machinery:
  resolved by adding a new `WsgiHandler` class and passing in to
  bottle's `run()` method when running the wsgi server. This required a
  new `ServerCheck` class to determine whether the wsgi server is
  selected when the `auto` option is used
- When using `gunicorn` along with the watchdog cache, package uplaods
  were not being picked up by the watcher. Updated the `add_package`
  and `remove_package` methods on the `CachingFileBackend` to bust the
  cache
2021-02-07 17:04:06 -06:00
Matthew Planchard d868005e1f
Docker improvements (#365)
* Docker improvements

This addresses much of what was brought up in #359. Specifically, it:

- Significantly improves testing for the Docker image, adding a
  `docker/test_docker.py` file using the regular pytest machinery to
  set up and run docker images for testing
- Hopefully addresses a variety of permissions issues, by being explicit
  about what access pypiserver needs and asking for it, only erroring
  if that access is not available
  - Requires RX permissions on `/data` (R to read files, X to list files
    and to be able to cd into the directory. This is important since
    `/data` is the `WORKDIR`)
  - Requires RWX permissions on `/data/packages`, so that we can list
    packages, write packages, and read packages.
  - When running in the default configuration (as root on Linux or
    as the pypiserver-named rootish user on Mac), with no volumes
    mounted, these requirements are all satisfied
  - Volume mounts still must be readable by the pypiserver user (UID
    9898) in order for the container to run. However, we now error early
    if this is not the case, and direct users to a useful issue.
  - If the container is run as a non-root, non-pypiserver user (e.g.
    because someone ran `docker run --user=<user_id>`, we try to run
    pypiserver as that user). Provided that user has access to the
    necessary directories, it should run fine.
- Fixes issues with running help and similar commands
- Updates the Docker image to use `PYPISERVER_PORT` for port
  specification, while still falling back to `PORT` for backwards
  compatibility
- Moves some docker-related things into a `/docker` directory
- Adds a `Makefile` for building a test fixture package sdist and wheel,
  so that test code can call `make mypkg` and not need to worry about it
  potentially building multiple times

The only issue #359 raises that's not addressed here is the one of
running pypiserver in the Docker container using some non-default server
for performance. I would like to do some benchmarking before deciding on
what to do there.
2021-02-06 11:28:15 -06:00
PelleK cf424c982d
Refactor storage operations into separate Backend classes (#348)
Following the discussion in #253 and #325 I've created a first iteration on what a `Backend` interface could look like and how the current file storage operations may be refactored into this interface. It goes from the following principles

* `app.py` talks only to `core.py` with regards to package operations
* at configuration time, a `Backend` implementation is chosen and created for the lifetime of the configured app
* `core.py` proxies requests for packages to this `Backend()`
* The `Backend` interface/api is defined through three things
  * methods that an implementation must implement
  * methods that an implementation may override if it knows better than the defaults
  * the `PkgFIle` class that is (should be) the main carrier of data
* where possible, implementation details must be hidden from concrete `Backend`s to promote extensibility

Other things I've done in this PR:
* I've tried to talk about packages and projects, rather than files and prefixes, since these are the domain terms PEP503 uses, and imho it's also more clear what it means
* Better testability of the `CacheManager` (no more race conditions when `watchdog` is installed during testing)
* Cleanup some more Python 2 code
* Started moving away from  `os.path` and `py.path` in favour of `pathlib`

Furthermore I've created a `plugin.py` with a sample of how I think plugin system could look like. This sampIe assumes we use `argparse`  and allows for the extension of cli arguments that a plugin may need. I think the actual implementation of such a plugin system is beyond the scope of this PR, but I've used it as a target for the Backend refactoring. If requested, I'll remove it from this PR.

The following things still need to be done / discussed. These can be part of this PR or moved into their own, separate PRs
- [ ] Simplify the `PgkFile` class. It currently consists of a number of attributes that don't necessarily belong with it, and not all attributes are aptly named (imho). I would like to minimalize the scope of `PkgFile` so that its only concern is being a data carrier between the app and the backends, and make its use more clear.
- [ ] Add a `PkgFile.metadata` that backend implementations may use to store custom data for packages. For example the current `PkgFile.root` attribute is an implementation detail of the filestorage backends, and other Backend implementations should not be bothered by it.
- [ ] Use `pathlib` wherever possible. This may also result in less attributes for `PkgFile`, since some things may be just contained in a single `Path` object, instead of multtiple strings.
- [ ] Improve testing of the `CacheManager`.

----
* move some functions around in preparation for backend module

* rename pkg_utils to pkg_helpers to prevent confusion with stdlib pkgutil

* further implement the current filestorage as simple file backend

* rename prefix to project, since that's more descriptive

* add digester func as attribute to pkgfile

* WIP caching backend

* WIP make cache better testable

* better testability of cache

* WIP file backends as plugin

* fix typos, run black

* Apply suggestions from code review

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>

* add more type hints to pass mypy, fix tox.ini

* add package count method to backend

* add package count method to backend

* minor changes

* bugfix when checking invalid whl file

* check for existing package recursively, bugfix, some more pathlib

* fix unittest

* rm dead code

* exclude bottle.py from coverage

* fix merge mistakes

* fix tab indentation

* backend as a cli argument

* fix cli, add tests

* fix mypy

* fix more silly mistakes

* process feedback

* remove dead code

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>
2021-02-02 11:44:29 -06:00
Matthew Planchard c668b1814a
Use argparse config throughout app (#349)
This PR is a pretty substantial refactor of the entrypoints of pypiserver (`__main__` and `__init__`) to use the argparse-based config added in #339.

- Updated `RunConfig` and `UpdateConfig` classes to have exclusive init kwargs, instead of taking an namespace. This turned out to be much easier when working with the library-style app initialization in `__init__`, both for direct instantiation and via paste config
- Added an `iter_packages()` method to the `RunConfig` to iterate over packages specified by the configuration (note @elfjes, I think that replacing this with e.g. a `backend` reference will be a nice way to tie in #348)
- Added a general-purpose method to map legacy keyword arguments to the `app()` and `paste_app_factory()` functions to updated forms
- Refactored the `paste_app_factory()` to not mutate the incoming dictionary
- Removed all argument-parsing and config-related code from `__main__` and `core`
- Moved `_logwrite` from `__init__` to `__main__`, since that was the only place it was being used after the updates to `core`
- Updated `digest_file` to use `hashlib.new(algo)` instead of `getattr(hashlib, algo)`, because the former supports more algorithms
- Updated `setup.py` to, instead of calling `eval()` on the entirety of `__init__`, to instead just evaluate the line that defines the version
- Assigned the config to a `._pypiserver_config` attribute on the `Bottle` instance to reduce hacky test workarounds
- Fixed the tox config, which I broke in #339 

* Config: add auth & absolute path resolution

* Config: check pkg dirs on config creation

* Instantiate config with kwargs, not namespace

* WIP: still pulling the threads

* Init seems to be working

* tests passing locally, still need to update cache

* Fix tox command

* unused import

* Fix typing

* Be more selective in exec() in setup.py

* Require accurate casing for hash algos

* Remove old comment

* Comments, minor updates and simplifications

* move _logwrite to a more reasonable place

* Update config to work with cache

* Type cachemanager listdir in core

* Update config module docstring, rename method

* Add more comments re: paste config

* Add comments to main, remove unneded check

* Remove commented code

* Use {posargs} instead of [] for clarity in tox

* Add dupe check for kwarg updater

* Remove unused references on app instance

* Fix typo

* Remove redundancy in log level parsing
2020-10-25 18:48:28 -05:00
PelleK d886bc2eba
Cleanup code to python 3.6 (#342)
* Cleanup setup.py

* remove explicit inheritance from object

* convert most string interpolations to f-strings

Co-authored-by: Pelle Koster <pelle.koster@nginfra.nl>
2020-10-07 20:45:51 -05:00
PelleK 8101cf9192
Run black on codebase (#336)
* run black on codebase

* add black check to travis ci

* add pyproject.toml, revert black on bottle.py

Co-authored-by: Pelle Koster <pelle.koster@nginfra.nl>
2020-10-05 21:04:22 -05:00
PelleK 8b1979031e
Log messages to stdout instead of stderr (#334)
* log to stdout

* add stdout logging to config and test it

* remove non-implemented parameter from docs

* configure log stream based on config, somehow this change got lost

* fix unittests for other python versions

* option to specify log stream

* Be more explicit in usage text

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>

* remove redundant arguments

* be more consistent in usage text

* add test for disabling stream logging

* fix side-effect of unittests

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>
2020-10-03 16:30:49 -05:00
Peter Slovak c21cf72c25
Add the option to specify list of modules we don't want to update (#298)
* Add the option to specify list of modules we don't want to update

Signed-off-by: Peter Slovak <peter.slovak@websupport.sk>

* Fix docs

Signed-off-by: Peter Slovak <peter.slovak@websupport.sk>

* Minimize the number of strip() calls

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>

* Log an exception when we fail to open/read the package blacklist file

* Abort server startup if we fail to read the blacklist file

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>
2020-07-16 23:03:30 -05:00
Matthew Planchard c791d12292 FIX: Fallback URL, remove calls to pip.main
Resolves #205 - pypi.python.org shutting down

* Updated the default fallback URL to `pypi.org/simple` rather than
`pypi.python.org/simple`
* Scrubbed references and links to `pypi.python.org`
* Fixed tests breaking due to the removal of `pip.main()` in pip 10.0 -
see pypa/pip#5080 for more info
2018-06-11 20:31:03 -05:00
Matthew Planchard c0b93bdaef Revert Matrix Auth
This reverts commits 29c1803 c79dd18 568f901 and 3d37c00. This has
resulted in bugs referenced in #175, #179, and #186.
2017-11-14 08:43:49 -06:00
Jordan Speicher 519c195253 Default fallback_url to use HTTPS
`pypi.python.org/simple` will respond to HTTP requests with `403: SSL is required.`

This will change the default fallback_url to use HTTPS.  This should fix #179.
2017-10-26 12:44:05 -05:00
Kyle Hornberg 29c1803eae Add matrix auth exceptions 2017-02-21 16:29:47 -06:00
Kyle Hornberg 568f901ace Add test for multiple actions with multiple users 2017-02-21 16:29:47 -06:00
Kyle Hornberg 3d37c00999 Add matrix auth 2017-02-21 16:29:47 -06:00
Kostis Anagnostopoulos 0c4c27fa5c v1.2.0.dev1 (<--1.1.10): Stop supporting py<2.7 & py<3.3 (#107). 2016-01-20 20:05:47 +01:00
ankostis on tokoti 912d405a83 hashes, #53: Add `--hash-algo` option with TCs. 2015-12-21 02:50:15 +02:00
Kostis Anagnostopoulos cda0fad7a9 Dot means empty when specifying empty authed-ops (`-a .`).
+ FIX check of password/authentication-list options combinations.
+ doc: Update auth-ops list instructions.
+ Report bad port.
2015-09-17 19:39:02 +02:00
Kostis Anagnostopoulos d4d0463db6 Upgrade bottle 0.11.6-->0.13-dev
+ FIX #82: serve more than 100 packages.
- Missing TC.
2015-09-17 13:48:27 +02:00
ankostis on tokoti 133afe28f7 Rework standalone generation using ZIP.
+ Standalone executable based on wheel.
+ Properly use `pkg_resources` so reading `welcome-msg` file
  works even from within zip.
  + Mark `zip_safe=True` in setup.py.
+ Delete forgotten distutils startup script.
+ Build standalone before installing anything else,
  to check if any deps are missing.
+ Restore py25 in Travis.
2015-09-17 01:13:37 +02:00
Kostis Anagnostopoulos at STUW025 2c1ceb04b5 Restructure `main` to allow for gevent monkeypatch (FIX #49).
+ Update zip and setuptools startup-cripts.
2015-09-15 22:22:09 +02:00
Kostis Anagnostopoulos at STUW025 000e977978 #55: Do not require `passlib` when -P == '.'. 2015-09-11 17:29:08 +02:00
Kostis Anagnostopoulos at STUW025 1fd5653317 FIX #55: Allow unauthenticated uploads with `-P .` option.
+ Add `mock` lib into test-dependencies for py2.
+ travis: Use new containers.
2015-09-11 16:08:13 +02:00
Kostis Anagnostopoulos @ STUW025 91f635b570 tests: Normalize paths for comparisons to run on Windows. 2015-01-15 16:20:24 +01:00
ankostis@kilo c64b8c32d2 Allow to override welcome-msg(`/`) from a separate html file.
- Read welcome-msg in UTF-8.
- Add cmd-line option for `welcome-file`.
- Add TCs for welcome-file option and `/` http-req.
- Update docs for new option.
- Failback to in-code welcome-msg if unreadable (ie standalone mode, bad file).
2015-01-15 16:20:24 +01:00
ankostis@kilo cf03226ea2 Add Logging for all http actions.
* Use stabdard python's logging lib.
* Log http-request/response/errors.
* Cmd-line options for logging-format and filename.
* Cmd-line options for request /response/error requests/responses/errors
props to log.
* Add `-v` option controlling verbosity.
* Add docs about new options.
* TCs only `-v` & `--log_file ` (logging statements used throughout all
tests).
2014-11-17 16:51:45 +01:00
Ralf Schmitt 2232295412 implement multi-root support
one can now specify multiple package roots. watch out for filename
conflicts!
2013-01-22 23:00:48 +01:00
Ralf Schmitt e90a7ef822 make tests succeed under python 3 2012-12-02 01:20:52 +01:00
Ralf Schmitt 2f2eeee593 use new pytest.fixture functionality 2012-11-26 22:25:30 +01:00
Orne Brocaar 55273d55e3 Add --fallback-url argument to pypi-server script to make it configurable. 2012-08-15 10:02:58 +02:00
Ralf Schmitt 3df36e66a0 instantiate a new app object/module for each pypiserver.app call
adapt test_main to the new situation.
2012-04-07 23:23:29 +02:00
Ralf Schmitt 1b2f37ede5 do not use the default bottle app 2012-04-07 22:57:40 +02:00
Ralf Schmitt c0f82470c6 move bottle app function to _app module
I'd like to run multiple pypiserver wsgi apps inside one process and
plan to do so by reloading pypiserver._app.

this is the first step. we move all of the @route'd functions to _app.
2012-04-07 22:30:54 +02:00
Ralf Schmitt 775f64783d add some tests for core.main function 2011-08-30 02:36:25 +02:00