prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Missing Purges
  Noticed this while setting up new mirror. We don't seem to be purging `project/<normalized_name>` key when projects are deleted.
  
  This leads bandersnatch to get confused and fall behind until the key is purged so the JSON api returns a 404
  
  </issue>
  <code>
  [start of warehouse/packaging/__init__.py]
  1 # Licensed under the Apache License, Version 2.0 (the "License");
  2 # you may not use this file except in compliance with the License.
  3 # You may obtain a copy of the License at
  4 #
  5 # http://www.apache.org/licenses/LICENSE-2.0
  6 #
  7 # Unless required by applicable law or agreed to in writing, software
  8 # distributed under the License is distributed on an "AS IS" BASIS,
  9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10 # See the License for the specific language governing permissions and
  11 # limitations under the License.
  12 
  13 from celery.schedules import crontab
  14 from sqlalchemy.orm.base import NO_VALUE
  15 
  16 from warehouse import db
  17 from warehouse.accounts.models import User, Email
  18 from warehouse.cache.origin import key_factory, receive_set
  19 from warehouse.packaging.interfaces import IFileStorage
  20 from warehouse.packaging.models import Project, Release
  21 from warehouse.packaging.tasks import compute_trending
  22 
  23 
  24 @db.listens_for(User.name, 'set')
  25 def user_name_receive_set(config, target, value, oldvalue, initiator):
  26     if oldvalue is not NO_VALUE:
  27         receive_set(User.name, config, target)
  28 
  29 
  30 @db.listens_for(Email.primary, 'set')
  31 def email_primary_receive_set(config, target, value, oldvalue, initiator):
  32     if oldvalue is not NO_VALUE:
  33         receive_set(Email.primary, config, target)
  34 
  35 
  36 def includeme(config):
  37     # Register whatever file storage backend has been configured for storing
  38     # our package files.
  39     storage_class = config.maybe_dotted(
  40         config.registry.settings["files.backend"],
  41     )
  42     config.register_service_factory(storage_class.create_service, IFileStorage)
  43 
  44     # Register our origin cache keys
  45     config.register_origin_cache_keys(
  46         Project,
  47         cache_keys=["project/{obj.normalized_name}"],
  48         purge_keys=[
  49             key_factory("project/{obj.normalized_name}"),
  50             key_factory("user/{itr.username}", iterate_on='users'),
  51             key_factory("all-projects"),
  52         ],
  53     )
  54     config.register_origin_cache_keys(
  55         Release,
  56         cache_keys=["project/{obj.project.normalized_name}"],
  57         purge_keys=[
  58             key_factory("project/{obj.project.normalized_name}"),
  59             key_factory("user/{itr.username}", iterate_on='project.users'),
  60             key_factory("all-projects"),
  61         ],
  62     )
  63     config.register_origin_cache_keys(
  64         User,
  65         cache_keys=["user/{obj.username}"],
  66     )
  67     config.register_origin_cache_keys(
  68         User.name,
  69         purge_keys=[
  70             key_factory("user/{obj.username}"),
  71             key_factory("project/{itr.normalized_name}", iterate_on='projects')
  72         ],
  73     )
  74     config.register_origin_cache_keys(
  75         Email.primary,
  76         purge_keys=[
  77             key_factory("user/{obj.user.username}"),
  78             key_factory(
  79                 "project/{itr.normalized_name}",
  80                 iterate_on='user.projects',
  81             )
  82         ],
  83     )
  84 
  85     # Add a periodic task to compute trending once a day, assuming we have
  86     # been configured to be able to access BigQuery.
  87     if config.get_settings().get("warehouse.trending_table"):
  88         config.add_periodic_task(crontab(minute=0, hour=3), compute_trending)
  89
  [end of warehouse/packaging/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/warehouse/packaging/__init__.py b/warehouse/packaging/__init__.py
  --- a/warehouse/packaging/__init__.py
  +++ b/warehouse/packaging/__init__.py
  @@ -17,7 +17,7 @@
   from warehouse.accounts.models import User, Email
   from warehouse.cache.origin import key_factory, receive_set
   from warehouse.packaging.interfaces import IFileStorage
  -from warehouse.packaging.models import Project, Release
  +from warehouse.packaging.models import Project, Release, Role
   from warehouse.packaging.tasks import compute_trending
   
   
  @@ -60,6 +60,13 @@
               key_factory("all-projects"),
           ],
       )
  +    config.register_origin_cache_keys(
  +        Role,
  +        purge_keys=[
  +            key_factory("user/{obj.user.username}"),
  +            key_factory("project/{obj.project.normalized_name}")
  +        ],
  +    )
       config.register_origin_cache_keys(
           User,
           cache_keys=["user/{obj.username}"],
  
verification_info: {"golden_diff": "diff --git a/warehouse/packaging/__init__.py b/warehouse/packaging/__init__.py\n--- a/warehouse/packaging/__init__.py\n+++ b/warehouse/packaging/__init__.py\n@@ -17,7 +17,7 @@\n from warehouse.accounts.models import User, Email\n from warehouse.cache.origin import key_factory, receive_set\n from warehouse.packaging.interfaces import IFileStorage\n-from warehouse.packaging.models import Project, Release\n+from warehouse.packaging.models import Project, Release, Role\n from warehouse.packaging.tasks import compute_trending\n \n \n@@ -60,6 +60,13 @@\n             key_factory(\"all-projects\"),\n         ],\n     )\n+    config.register_origin_cache_keys(\n+        Role,\n+        purge_keys=[\n+            key_factory(\"user/{obj.user.username}\"),\n+            key_factory(\"project/{obj.project.normalized_name}\")\n+        ],\n+    )\n     config.register_origin_cache_keys(\n         User,\n         cache_keys=[\"user/{obj.username}\"],\n", "issue": "Missing Purges\nNoticed this while setting up new mirror. We don't seem to be purging `project/<normalized_name>` key when projects are deleted.\r\n\r\nThis leads bandersnatch to get confused and fall behind until the key is purged so the JSON api returns a 404\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom celery.schedules import crontab\nfrom sqlalchemy.orm.base import NO_VALUE\n\nfrom warehouse import db\nfrom warehouse.accounts.models import User, Email\nfrom warehouse.cache.origin import key_factory, receive_set\nfrom warehouse.packaging.interfaces import IFileStorage\nfrom warehouse.packaging.models import Project, Release\nfrom warehouse.packaging.tasks import compute_trending\n\n\n@db.listens_for(User.name, 'set')\ndef user_name_receive_set(config, target, value, oldvalue, initiator):\n    if oldvalue is not NO_VALUE:\n        receive_set(User.name, config, target)\n\n\n@db.listens_for(Email.primary, 'set')\ndef email_primary_receive_set(config, target, value, oldvalue, initiator):\n    if oldvalue is not NO_VALUE:\n        receive_set(Email.primary, config, target)\n\n\ndef includeme(config):\n    # Register whatever file storage backend has been configured for storing\n    # our package files.\n    storage_class = config.maybe_dotted(\n        config.registry.settings[\"files.backend\"],\n    )\n    config.register_service_factory(storage_class.create_service, IFileStorage)\n\n    # Register our origin cache keys\n    config.register_origin_cache_keys(\n        Project,\n        cache_keys=[\"project/{obj.normalized_name}\"],\n        purge_keys=[\n            key_factory(\"project/{obj.normalized_name}\"),\n            key_factory(\"user/{itr.username}\", iterate_on='users'),\n            key_factory(\"all-projects\"),\n        ],\n    )\n    config.register_origin_cache_keys(\n        Release,\n        cache_keys=[\"project/{obj.project.normalized_name}\"],\n        purge_keys=[\n            key_factory(\"project/{obj.project.normalized_name}\"),\n            key_factory(\"user/{itr.username}\", iterate_on='project.users'),\n            key_factory(\"all-projects\"),\n        ],\n    )\n    config.register_origin_cache_keys(\n        User,\n        cache_keys=[\"user/{obj.username}\"],\n    )\n    config.register_origin_cache_keys(\n        User.name,\n        purge_keys=[\n            key_factory(\"user/{obj.username}\"),\n            key_factory(\"project/{itr.normalized_name}\", iterate_on='projects')\n        ],\n    )\n    config.register_origin_cache_keys(\n        Email.primary,\n        purge_keys=[\n            key_factory(\"user/{obj.user.username}\"),\n            key_factory(\n                \"project/{itr.normalized_name}\",\n                iterate_on='user.projects',\n            )\n        ],\n    )\n\n    # Add a periodic task to compute trending once a day, assuming we have\n    # been configured to be able to access BigQuery.\n    if config.get_settings().get(\"warehouse.trending_table\"):\n        config.add_periodic_task(crontab(minute=0, hour=3), compute_trending)\n", "path": "warehouse/packaging/__init__.py"}]}