Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
c2b1fb3d
Commit
c2b1fb3d
authored
Oct 11, 2022
by
Chad Crawford
Committed by
Bjorn Neergaard
Oct 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate codebase from `cachy` to `poetry.utils.cache`.
parent
e512cbee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
64 deletions
+62
-64
poetry.lock
+0
-0
pyproject.toml
+2
-1
src/poetry/console/commands/cache/clear.py
+2
-9
src/poetry/repositories/cached.py
+4
-14
src/poetry/repositories/legacy_repository.py
+13
-17
src/poetry/repositories/pypi_repository.py
+6
-16
tests/console/commands/cache/test_clear.py
+3
-2
tests/console/commands/test_add.py
+32
-5
No files found.
poetry.lock
View file @
c2b1fb3d
This diff is collapsed.
Click to expand it.
pyproject.toml
View file @
c2b1fb3d
...
...
@@ -51,7 +51,6 @@ poetry-core = "^1.3.2"
poetry-plugin-export
=
"^1.1.2"
"backports.cached-property"
=
{
version
=
"^1.0.2"
,
python
=
"<3.8"
}
cachecontrol
=
{
version
=
"^0.12.9"
,
extras
=
["filecache"]
}
cachy
=
"^0.3.0"
cleo
=
"^1.0.0a5"
crashtest
=
"^0.3.0"
dulwich
=
"^0.20.46"
...
...
@@ -80,6 +79,8 @@ urllib3 = "^1.26.0"
pre-commit
=
"^2.6"
[tool.poetry.group.test.dependencies]
# Cachy frozen to test backwards compatibility for `poetry.utils.cache`.
cachy
=
"0.3.0"
deepdiff
=
"^5.0"
flatdict
=
"^4.0.1"
httpretty
=
"^1.0"
...
...
src/poetry/console/commands/cache/clear.py
View file @
c2b1fb3d
...
...
@@ -8,6 +8,7 @@ from packaging.utils import canonicalize_name
from
poetry.config.config
import
Config
from
poetry.console.commands.command
import
Command
from
poetry.utils.cache
import
FileCache
class
CacheClearCommand
(
Command
):
...
...
@@ -18,8 +19,6 @@ class CacheClearCommand(Command):
options
=
[
option
(
"all"
,
description
=
"Clear all entries in the cache."
)]
def
handle
(
self
)
->
int
:
from
cachy
import
CacheManager
cache
=
self
.
argument
(
"cache"
)
parts
=
cache
.
split
(
":"
)
...
...
@@ -33,13 +32,7 @@ class CacheClearCommand(Command):
except
ValueError
:
raise
ValueError
(
f
"{root} is not a valid repository cache"
)
cache
=
CacheManager
(
{
"default"
:
parts
[
0
],
"serializer"
:
"json"
,
"stores"
:
{
parts
[
0
]:
{
"driver"
:
"file"
,
"path"
:
str
(
cache_dir
)}},
}
)
cache
=
FileCache
(
cache_dir
)
if
len
(
parts
)
==
1
:
if
not
self
.
option
(
"all"
):
...
...
src/poetry/repositories/cached.py
View file @
c2b1fb3d
...
...
@@ -5,12 +5,12 @@ from abc import abstractmethod
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
cachy
import
CacheManager
from
packaging.utils
import
canonicalize_name
from
poetry.core.constraints.version
import
parse_constraint
from
poetry.config.config
import
Config
from
poetry.repositories.repository
import
Repository
from
poetry.utils.cache
import
FileCache
if
TYPE_CHECKING
:
...
...
@@ -30,17 +30,7 @@ class CachedRepository(Repository, ABC):
super
()
.
__init__
(
name
)
self
.
_disable_cache
=
disable_cache
self
.
_cache_dir
=
(
config
or
Config
.
create
())
.
repository_cache_directory
/
name
self
.
_cache
=
CacheManager
(
{
"default"
:
"releases"
,
"serializer"
:
"json"
,
"stores"
:
{
"releases"
:
{
"driver"
:
"file"
,
"path"
:
str
(
self
.
_cache_dir
)},
"packages"
:
{
"driver"
:
"dict"
},
"matches"
:
{
"driver"
:
"dict"
},
},
}
)
self
.
_release_cache
:
FileCache
[
dict
[
str
,
Any
]]
=
FileCache
(
path
=
self
.
_cache_dir
)
@abstractmethod
def
_get_release_info
(
...
...
@@ -60,7 +50,7 @@ class CachedRepository(Repository, ABC):
if
self
.
_disable_cache
:
return
PackageInfo
.
load
(
self
.
_get_release_info
(
name
,
version
))
cached
=
self
.
_
cache
.
remember_forev
er
(
cached
=
self
.
_
release_cache
.
rememb
er
(
f
"{name}:{version}"
,
lambda
:
self
.
_get_release_info
(
name
,
version
)
)
...
...
@@ -73,7 +63,7 @@ class CachedRepository(Repository, ABC):
)
cached
=
self
.
_get_release_info
(
name
,
version
)
self
.
_
cache
.
forever
(
f
"{name}:{version}"
,
cached
)
self
.
_
release_cache
.
put
(
f
"{name}:{version}"
,
cached
)
return
PackageInfo
.
load
(
cached
)
...
...
src/poetry/repositories/legacy_repository.py
View file @
c2b1fb3d
...
...
@@ -90,23 +90,19 @@ class LegacyRepository(HTTPRepository):
if
not
constraint
.
is_any
():
key
=
f
"{key}:{constraint!s}"
if
self
.
_cache
.
store
(
"matches"
)
.
has
(
key
):
versions
=
self
.
_cache
.
store
(
"matches"
)
.
get
(
key
)
else
:
page
=
self
.
_get_page
(
f
"/{name}/"
)
if
page
is
None
:
self
.
_log
(
f
"No packages found for {name}"
,
level
=
"debug"
,
)
return
[]
versions
=
[
(
version
,
page
.
yanked
(
name
,
version
))
for
version
in
page
.
versions
(
name
)
if
constraint
.
allows
(
version
)
]
self
.
_cache
.
store
(
"matches"
)
.
put
(
key
,
versions
,
5
)
page
=
self
.
_get_page
(
f
"/{name}/"
)
if
page
is
None
:
self
.
_log
(
f
"No packages found for {name}"
,
level
=
"debug"
,
)
return
[]
versions
=
[
(
version
,
page
.
yanked
(
name
,
version
))
for
version
in
page
.
versions
(
name
)
if
constraint
.
allows
(
version
)
]
return
[
Package
(
...
...
src/poetry/repositories/pypi_repository.py
View file @
c2b1fb3d
...
...
@@ -100,13 +100,7 @@ class PyPiRepository(HTTPRepository):
The information is returned from the cache if it exists
or retrieved from the remote server.
"""
if
self
.
_disable_cache
:
return
self
.
_get_package_info
(
name
)
package_info
:
dict
[
str
,
Any
]
=
self
.
_cache
.
store
(
"packages"
)
.
remember_forever
(
name
,
lambda
:
self
.
_get_package_info
(
name
)
)
return
package_info
return
self
.
_get_package_info
(
name
)
def
_find_packages
(
self
,
name
:
NormalizedName
,
constraint
:
VersionConstraint
...
...
@@ -129,15 +123,11 @@ class PyPiRepository(HTTPRepository):
if
not
constraint
.
is_any
():
key
=
f
"{key}:{constraint!s}"
if
self
.
_cache
.
store
(
"matches"
)
.
has
(
key
):
versions
=
self
.
_cache
.
store
(
"matches"
)
.
get
(
key
)
else
:
versions
=
[
(
version
,
json_page
.
yanked
(
name
,
version
))
for
version
in
json_page
.
versions
(
name
)
if
constraint
.
allows
(
version
)
]
self
.
_cache
.
store
(
"matches"
)
.
put
(
key
,
versions
,
5
)
versions
=
[
(
version
,
json_page
.
yanked
(
name
,
version
))
for
version
in
json_page
.
versions
(
name
)
if
constraint
.
allows
(
version
)
]
pretty_name
=
json_page
.
content
[
"name"
]
packages
=
[
...
...
tests/console/commands/cache/test_clear.py
View file @
c2b1fb3d
...
...
@@ -30,11 +30,12 @@ def test_cache_clear_all(
cache
:
CacheManager
,
):
exit_code
=
tester
.
execute
(
f
"cache clear {repository_one} --all"
,
inputs
=
"yes"
)
repository_one_dir
=
repository_cache_dir
/
repository_one
assert
exit_code
==
0
assert
tester
.
io
.
fetch_output
()
==
""
# ensure directory is empty
assert
not
any
((
repository_cache_dir
/
repository_one
)
.
iterdir
())
# ensure directory is empty
or doesn't exist
assert
not
repository_one_dir
.
exists
()
or
not
any
(
repository_one_dir
.
iterdir
())
assert
not
cache
.
has
(
"cachy:0.1"
)
assert
not
cache
.
has
(
"cleo:0.2"
)
...
...
tests/console/commands/test_add.py
View file @
c2b1fb3d
...
...
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING
import
pytest
from
poetry.core.constraints.version
import
Version
from
poetry.core.packages.package
import
Package
from
poetry.repositories.legacy_repository
import
LegacyRepository
from
tests.helpers
import
get_dependency
...
...
@@ -819,12 +820,26 @@ Package operations: 1 install, 0 updates, 0 removals
def
test_add_constraint_with_source
(
app
:
PoetryTestApplication
,
poetry
:
Poetry
,
tester
:
CommandTester
app
:
PoetryTestApplication
,
poetry
:
Poetry
,
tester
:
CommandTester
,
mocker
:
MockerFixture
,
):
repo
=
LegacyRepository
(
name
=
"my-index"
,
url
=
"https://my-index.fake"
)
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
repo
.
_cache
.
store
(
"matches"
)
.
put
(
"cachy:0.2.0"
,
[(
Version
.
parse
(
"0.2.0"
),
False
)],
5
mocker
.
patch
.
object
(
repo
,
"_find_packages"
,
wraps
=
lambda
_
,
name
:
[
Package
(
"cachy"
,
Version
.
parse
(
"0.2.0"
),
source_type
=
"legacy"
,
source_reference
=
repo
.
name
,
source_url
=
repo
.
_url
,
yanked
=
False
,
)
],
)
poetry
.
pool
.
add_repository
(
repo
)
...
...
@@ -1809,11 +1824,23 @@ def test_add_constraint_with_source_old_installer(
poetry
:
Poetry
,
installer
:
NoopInstaller
,
old_tester
:
CommandTester
,
mocker
:
MockerFixture
,
):
repo
=
LegacyRepository
(
name
=
"my-index"
,
url
=
"https://my-index.fake"
)
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
repo
.
_cache
.
store
(
"matches"
)
.
put
(
"cachy:0.2.0"
,
[(
Version
.
parse
(
"0.2.0"
),
False
)],
5
mocker
.
patch
.
object
(
repo
,
"_find_packages"
,
wraps
=
lambda
_
,
name
:
[
Package
(
"cachy"
,
Version
.
parse
(
"0.2.0"
),
source_type
=
"legacy"
,
source_reference
=
repo
.
name
,
source_url
=
repo
.
_url
,
yanked
=
False
,
)
],
)
poetry
.
pool
.
add_repository
(
repo
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment