Skip to content

Commit

Permalink
chore(refactor): Move sorted_versions function into caller
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 19, 2024
1 parent 276fab5 commit 091f3a5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 147 deletions.
11 changes: 11 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ CLI
- Remove all ``twistd`` subcommands (FTP servers, etc.). Run ``twistd``, if needed.
- Run the ``scrapyd.__main__`` module, instead of the ``scrapyd.scripts.scrapyd_run`` module.

Utils
^^^^^

Move functions from ``scrapyd.utils`` into their callers:

- ``sorted_versions`` to ``scrapyd.eggstorage``
- ``get_crawl_args`` to ``scrapyd.launcher``
- ``JsonResource``, ``get_spider_list`` and ``UtilsCache`` to ``scrapyd.webservice``

Move ``activate_egg`` from ``scrapyd.eggutils`` to ``scrapyd.runner``

Fixed
~~~~~

Expand Down
9 changes: 8 additions & 1 deletion scrapyd/eggstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
import shutil
from glob import escape, glob

from packaging.version import InvalidVersion, Version
from zope.interface import implementer

from scrapyd.exceptions import DirectoryTraversalError, EggNotFoundError, ProjectNotFoundError
from scrapyd.interfaces import IEggStorage
from scrapyd.utils import sorted_versions


def sorted_versions(versions):
try:
return sorted(versions, key=Version)
except InvalidVersion:
return sorted(versions)


@implementer(IEggStorage)
Expand Down
8 changes: 0 additions & 8 deletions scrapyd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import ClassVar
from urllib.parse import urlsplit

from packaging.version import InvalidVersion, Version
from scrapy.utils.misc import load_object
from twisted.web import resource

Expand Down Expand Up @@ -174,10 +173,3 @@ def _to_native_str(text, encoding="utf-8", errors="strict"):
if isinstance(text, str):
return text
return text.decode(encoding, errors)


def sorted_versions(versions):
try:
return sorted(versions, key=Version)
except InvalidVersion:
return sorted(versions)
14 changes: 13 additions & 1 deletion tests/test_eggstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@

from scrapyd.app import application
from scrapyd.config import Config
from scrapyd.eggstorage import FilesystemEggStorage
from scrapyd.eggstorage import FilesystemEggStorage, sorted_versions
from scrapyd.exceptions import DirectoryTraversalError
from scrapyd.interfaces import IEggStorage


@pytest.mark.parametrize(
("versions", "expected"),
[
(["zzz", "b", "ddd", "a", "x"], ["a", "b", "ddd", "x", "zzz"]),
(["10", "1", "9"], ["1", "9", "10"]),
(["2.11", "2.01", "2.9"], ["2.01", "2.9", "2.11"]),
],
)
def test_sorted_versions(versions, expected):
assert sorted_versions(versions) == expected


@implementer(IEggStorage)
class SomeFakeEggStorage:
def __init__(self, config):
Expand Down
137 changes: 0 additions & 137 deletions tests/test_utils.py

This file was deleted.

0 comments on commit 091f3a5

Please sign in to comment.