1
0
mirror of https://github.com/pypiserver/pypiserver synced 2024-11-09 16:45:51 +01:00
Commit Graph

123 Commits

Author SHA1 Message Date
Dmitrii Orlov
a10cdcead3 Fix black errors on test_server.py 2022-02-20 21:17:20 +01:00
awachtler
e7bc2bb75d test_app.py/json_info: added tests for the json_info endpoint 2021-08-12 07:46:42 +02: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
PelleK
4b1bd1c9db
Refactor test_server to increase speed (#354)
I gave test_server.py some much needed attention. This file now take ~30 seconds on my machine to run (down from 130 seconds), and I cleaned up the code a little. Let's see how this goes in CI

Commits:
-------------
* minimize time.sleep, convert to pathlib
* refactor, dry code
* run black

Co-authored-by: Matthew Planchard <mplanchard@users.noreply.github.com>
2020-11-15 15:57:53 -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
Matthew Planchard
47d6efe196
Restore ability to drop hashing in new config (#347)
Thanks @elfjes for pointing out that I'd missed this! I also went ahead
and bumped the version in the README to 2.0.0dev1, so that it's clear
that what's in master shouldn't be what people expect from pypi or in the
docker image.
2020-10-11 14:16:57 -05:00
Matthew Planchard
0594c33e53
Backwards-compatible argparse config (not yet in use) (#339)
Adds an argparse config that, while adding subcommands (`pypi-server run` and `pypi-server update`), retains full commandline backwards compatibility with the existing config parsing logic.

There's a bit of hackery required to do this, so this also issues a warning if using the non-subcommand arguments, allowing us to potentially remove support for the old form in our next next major version bump (i.e. 3.0).

Also adds a `.pyproject.toml` with a black config, and a mypy config block to `setup.cfg`.

`mypy` is now called in `tox`, currently only for `config.py`, because nothing else typechecks successfully.

----

* WIP: argparse config

* Complete config

* Test all the config options

* Another test and a note re: being unused

* mypy config, call mypy in tox

* No mypy on pypy

* Fix tox config

* Add venv to black ignore

* fix tox config (again)

* Fix formatting, simplify error handling

* FMT: Run black on changed files
2020-10-08 19:37:39 -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
Géry Ogam
dbee4ec4ce Update welcome.html (#278)
* Update welcome.html

* Update test_app.py
2019-11-10 17:40:13 -06:00
Matthew Planchard
205342049b
[268] Ensure remove_pkg removes all pkg instances (#273)
* [268] Ensure remove_pkg removes all pkg instances

Reported by @esciara in #268.

Previously, the `remove_pkg` command was only removing the first
matching package that it found so if, for example, there were a .tar.gz
file and a .whl file, it would only remove one of them.

Of course, it could be run in succession to accomplish full removal, but
the expected behavior is that removal will remove the package entirely.

Here, I've grouped `remove_pkg` related tests into a test class, added
some tests that verify the expected behavior, and updated the
`remove_pkg` method to remove all matching packages.

* CHANGES.rst
2019-09-17 21:30:30 -05:00
Matthew Planchard
a52c0d6f4c
fmt: tests/test_app.py 2019-09-17 20:29:48 -05:00
Matthew Planchard
91a5ebd8b1
[#265] Resolve issue with non-md5 hashing algorithms (#266) 2019-09-02 14:31:59 -05:00
swe-jaeyoungpark
a060e99a25 implement "supporting changing the prefix of the path of url" again, using before_request hook. 2019-05-02 23:18:31 +09:00
swe-jaeyoungpark
c3965e31a0 fix typos on test_app.py 2019-05-02 23:14:31 +09:00
swe-jaeyoungpark
8a196ddc90 add test cases with X_FORWARDED_HOST header 2019-04-29 18:22:35 +09:00
Matthew Planchard
1375a67c55 CRLF Injection Mitigation
Resolves #237

Previously, we were not running any sort of URL escaping on values
passed in from the client that were used for redirects. This allowed
injection attacks via URL encoded newlines in the original request.

This update ensures that all user-supplied paths that are used as
components of redirects are passed through `urllib.parse.quote()`
(or the python 2 equivalent) prior to being used in a redirect
response.

Also specified 127.0.0.1 rather than 0.0.0.0 (the default) in server
tests to avoid triggering firewall dialogs when testing on MacOS
2019-01-24 17:53:03 -06:00
Matthew Planchard
def22f49a7 another pep8 fn name 2018-11-09 18:46:06 -06:00
Matthew Planchard
410498a059 test_server.py cleanup
Resolves #226

Cleaned up `test_server.py` a bit:

* Call `twine` via `Popen` instead of using their internal API, which
  should help us from having to fix twine tests as often
* Cleaned up fixtures
* Some PEP8 updates and general formatting
* Grouped test fixtures and functions all before the tests themselves
2018-11-09 18:44:41 -06:00
Matthew Planchard
4109c10524 Tests and refactoring
* Refactored `updae()` into several single-responsibility functions
* Added tests for said functions
* Some PEP 008 cleanup
* Imported standard `__future__` imports in `manage.py` and its test
module
2018-08-04 16:17:56 -05:00
Matthew Planchard
2499dac8ec Merge branch 'rm-3.3' of git://github.com/hugovk/pypiserver into hugovk-rm-3.3 2018-06-12 20:26:31 -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
Hugo
676e86d683 Remove redundant parentheses 2018-05-07 22:29:36 +03:00
Hugo
31a5b5d7e7 Replace function call with set literal 2018-05-07 22:29:36 +03:00
Hugo
288f38f26e Remove unused imports 2018-05-07 22:29:36 +03:00
Matthew Planchard
e6a0bfc812 Resolved paste config parsing issue for Python 2
The ability to propagate configuration values from a paste config
file was introduced in #156. However, as pointed out in #125
by @redbaron4, the string strip method introduced in #156 was
problematic in Python 2.

This resolves that issue while also creating a test that fails
on the current master and passes with updates, demonstrating the
issue.
2017-11-29 20:04:09 -06:00
Matthew Planchard
1770f3cf93 Updated Tests
In addition to including tests from @jameshiebert with slight
updates, I have also resolved an issue with newer versions of twine,
which require an extra parameter in the calls to `upload` and
`register`.
2017-11-14 11:02:44 -06: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
Matthew Planchard
05f5920c25 Updated Default Fallback URL to https
Resolves #179

Due to a pypi API change (reasoning
[here](https://mail.python.org/pipermail/distutils-sig/2017-October/031712.html),
thanks to @natefoo for the link), the redirect links that we were
generating for distributions not present in the package index were
failing with `403` errors.

@ankostis, I have not had time to look into why the standalone tests are
failing. Perhaps we should just ignore them in order to get a new
version out once this is merged to master?
2017-10-31 12:34:22 -05: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
Bert JW Regeer
ecfd1796a7 Add test to disallow regression 2017-03-31 12:48:08 +02: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
Matthew Planchard
a05d5a103b Update Tests for New Twine
* Updated .travis.yml to fix PEP 440 warnings
* Fixed twine calls

We were getting test failures on multiple branches in
`test_server.py`. I first investigated a warning message
popping up in every test run:

```
PEP440Warning,
/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/pkg_resources/__init__.py:2510: PEP440Warning: 'setuptools (git-0.4.0)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
```

Moving the installation of setuptools, pip, sphinx, and tox
into the `install` key for Travis resolved that issue, but
`test_server.py` tests were still failing. It turns out that
Twine 1.7.0 added support for SSL cert specification and,
in the process, changed the call signature for the `upload`
and `register` internal methods.

This PR fixes the calls so that they align with Twine's new
function signature. Note that tests now fail on Twine <1.7.0,
so I have also updated the dev requirements file.
2016-07-17 14:35:58 -05:00
Matthew Planchard
7aa9240391 Merge pull request #114 from blade2005/topic/allow-search-with-pip
Topic/allow search with pip
2016-06-22 21:11:01 -05:00
Dana Powers
1f6da1fe00 Implement PEP 503 Package Name Normalization and URL Redirects 2016-05-19 15:45:08 -07:00
Dana Powers
394da3212f upload test requires pypirc to avoid password prompt 2016-05-14 21:43:57 -07:00
Matthew Planchard
7180dc477f Added init.py to tests 2016-05-12 20:02:10 -05:00
Matthew Planchard
b9b95713b4 Test for search functionality
Removed unused imports
Added docstrings
Whitespace changes
PEP 008 compliance
Added test for search
2016-05-12 19:44:24 -05:00
bibby
54247a17bb test_upload_with_signature fix to allow uploaded files in any order. My result appears different than the expected outcome. 2016-04-21 08:08:18 -07:00
Matthew Planchard
5ba186264e Added a test that fails in current master and succeeds in
proposed branch changes
2016-03-21 20:39:46 -05: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
Kostis Anagnostopoulos
27a0b05433 Merge branch 'allow-asc-uploads' into dev. 2016-01-19 20:10:22 +01:00
Kostis Anagnostopoulos
140796bb6e gpg, #106, test: Add upload+sig TC.
- Rename upload-file vars in /upload action.
2016-01-19 18:50:14 +01:00
Matthew Planchard
abf8785f4d gpg, #106, test: Add TC for parsing all-filenames with .asc. 2016-01-19 18:41:53 +01:00