Skip to content

Commit

Permalink
Merge branch 'main' into snyk-fix-c5dfec6a07a6a9020e6762d9384e1fa9
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieFero authored Nov 15, 2024
2 parents 37caed7 + 5b2a613 commit 019978b
Show file tree
Hide file tree
Showing 192 changed files with 11,018 additions and 5,282 deletions.
68 changes: 68 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!--
Thanks for contributing! This template has some checkboxes that help keep track of what changes go into a release.
To check (tick) a list item, replace the space between square brackets with an x, like this:
- [x] I have checked the box
You can find more information and tips for BookWyrm contributors at https://docs.joinbookwyrm.com/contributing.html
-->
## Description
<!--
Describe what your pull request does here
-->


<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).
For example having the text: "closes #1234" would connect the current pull
request to issue 1234. And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #

## What type of Pull Request is this?
<!-- Check all that apply -->

- [ ] Bug Fix
- [ ] Enhancement
- [ ] Plumbing / Internals / Dependencies
- [ ] Refactor

## Does this PR change settings or dependencies, or break something?
<!-- Check all that apply -->

- [ ] This PR changes or adds default settings, configuration, or .env values
- [ ] This PR changes or adds dependencies
- [ ] This PR introduces other breaking changes

### Details of breaking or configuration changes (if any of above checked)


## Documentation
<!--
Documentation for users, admins, and developers is an important way to keep the BookWyrm community welcoming and make Bookwyrm easy to use.
Our documentation is maintained in a separate repository at https://github.com/bookwyrm-social/documentation
-->

<!-- Check all that apply -->

- [ ] New or amended documentation will be required if this PR is merged
- [ ] I have created a matching pull request in the Documentation repository
- [ ] I intend to create a matching pull request in the Documentation repository after this PR is merged

<!-- Amazing! Thanks for filling that out. Your PR will need to have passing tests and happy linters before we can merge
You will need to check your code with `black`, `pylint`, and `mypy`, or `./bw-dev formatters`
-->

### Tests
<!-- Check one -->

- [ ] My changes do not need new tests
- [ ] All tests I have added are passing
- [ ] I have written tests but need help to make them pass
- [ ] I have not written tests and need help to write them
26 changes: 26 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: ‼️ Breaking Changes & New Settings ⚙️
labels:
- breaking-change
- config-change
- title: Updated Dependencies 🧸
labels:
- dependencies
- title: New Features 🎉
labels:
- enhancement
- title: Bug Fixes 🐛
labels:
- fix
- bug
- title: Internals/Plumbing 👩‍🔧
- plumbing
- tests
- deployment
- title: Other Changes
labels:
- "*"
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Set up .env
run: cp .env.example .env
- name: Check migrations up-to-date
run: python ./manage.py makemigrations --check
run: python ./manage.py makemigrations --check -v 3
- name: Run Tests
run: pytest -n 3

Expand Down
14 changes: 13 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ ignore=migrations
load-plugins=pylint.extensions.no_self_use

[MESSAGES CONTROL]
disable=E1101,E1135,E1136,R0903,R0901,R0902,W0707,W0511,W0406,R0401,R0801,C3001,import-error
disable =
cyclic-import,
duplicate-code,
fixme,
no-member,
raise-missing-from,
too-few-public-methods,
too-many-ancestors,
too-many-instance-attributes,
unnecessary-lambda-assignment,
unsubscriptable-object,
enable =
useless-suppression

[FORMAT]
max-line-length=88
25 changes: 12 additions & 13 deletions bookwyrm/activitypub/base_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ def serialize(self, **kwargs):
pass
data = {k: v for (k, v) in data.items() if v is not None and k not in omit}
if "@context" not in omit:
data["@context"] = "https://www.w3.org/ns/activitystreams"
data["@context"] = [
"https://www.w3.org/ns/activitystreams",
{"Hashtag": "as:Hashtag"},
]
return data


Expand Down Expand Up @@ -366,17 +369,13 @@ def resolve_remote_id(

# load the data and create the object
try:
data = get_data(remote_id)
data = get_activitypub_data(remote_id)
except ConnectionError:
logger.info("Could not connect to host for remote_id: %s", remote_id)
return None
except requests.HTTPError as e:
if (e.response is not None) and e.response.status_code == 401:
# This most likely means it's a mastodon with secure fetch enabled.
data = get_activitypub_data(remote_id)
else:
logger.info("Could not connect to host for remote_id: %s", remote_id)
return None
logger.exception("HTTP error - remote_id: %s - error: %s", remote_id, e)
return None
# determine the model implicitly, if not provided
# or if it's a model with subclasses like Status, check again
if not model or hasattr(model.objects, "select_subclasses"):
Expand All @@ -400,11 +399,11 @@ def get_representative():
to sign outgoing HTTP GET requests"""
return models.User.objects.get_or_create(
username=f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}",
defaults=dict(
email="bookwyrm@localhost",
local=True,
localname=INSTANCE_ACTOR_USERNAME,
),
defaults={
"email": "bookwyrm@localhost",
"local": True,
"localname": INSTANCE_ACTOR_USERNAME,
},
)[0]


Expand Down
1 change: 0 additions & 1 deletion bookwyrm/activitypub/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Edition(Book):
type: str = "Edition"


# pylint: disable=invalid-name
@dataclass(init=False)
class Work(Book):
"""work instance of a book object"""
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/activitypub/ordered_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class OrderedCollection(ActivityObject):
type: str = "OrderedCollection"


# pylint: disable=invalid-name
@dataclass(init=False)
class OrderedCollectionPrivate(OrderedCollection):
"""an ordered collection with privacy settings"""
Expand Down
4 changes: 0 additions & 4 deletions bookwyrm/activitypub/verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def action(self, allow_external_connections=True):
self.object.to_model(allow_external_connections=allow_external_connections)


# pylint: disable=invalid-name
@dataclass(init=False)
class Create(Verb):
"""Create activity"""
Expand All @@ -33,7 +32,6 @@ class Create(Verb):
type: str = "Create"


# pylint: disable=invalid-name
@dataclass(init=False)
class Delete(Verb):
"""Create activity"""
Expand Down Expand Up @@ -63,7 +61,6 @@ def action(self, allow_external_connections=True):
# if we can't find it, we don't need to delete it because we don't have it


# pylint: disable=invalid-name
@dataclass(init=False)
class Update(Verb):
"""Update activity"""
Expand Down Expand Up @@ -227,7 +224,6 @@ def action(self, allow_external_connections=True):
self.to_model(allow_external_connections=allow_external_connections)


# pylint: disable=invalid-name
@dataclass(init=False)
class Announce(Verb):
"""boosting a status"""
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/activitystreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def unread_by_status_type_id(self, user_id):
stream_id = self.stream_id(user_id)
return f"{stream_id}-unread-by-type"

def get_rank(self, obj): # pylint: disable=no-self-use
def get_rank(self, obj):
"""statuses are sorted by date published"""
return obj.published_date.timestamp()

Expand Down
1 change: 0 additions & 1 deletion bookwyrm/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class BookwyrmConfig(AppConfig):
name = "bookwyrm"
verbose_name = "BookWyrm"

# pylint: disable=no-self-use
def ready(self):
"""set up OTLP and preview image files, if desired"""
if settings.OTEL_EXPORTER_OTLP_ENDPOINT or settings.OTEL_EXPORTER_CONSOLE:
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/book_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def search(
...


# pylint: disable=arguments-differ
def search(
query: str,
*,
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/connectors/abstract_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def get_results(
),
"User-Agent": USER_AGENT,
}
params = {"min_confidence": min_confidence}
params = {"min_confidence": str(min_confidence)}
try:
async with session.get(url, headers=headers, params=params) as response:
if not response.ok:
Expand Down
8 changes: 6 additions & 2 deletions bookwyrm/connectors/connector_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def load_more_data(connector_id: str, book_id: str) -> None:
"""background the work of getting all 10,000 editions of LoTR"""
connector_info = models.Connector.objects.get(id=connector_id)
connector = load_connector(connector_info)
book = models.Book.objects.select_subclasses().get(id=book_id)
book = models.Book.objects.select_subclasses().get( # type: ignore[no-untyped-call]
id=book_id
)
connector.expand_book_data(book)


Expand All @@ -156,7 +158,9 @@ def create_edition_task(
"""separate task for each of the 10,000 editions of LoTR"""
connector_info = models.Connector.objects.get(id=connector_id)
connector = load_connector(connector_info)
work = models.Work.objects.select_subclasses().get(id=work_id)
work = models.Work.objects.select_subclasses().get( # type: ignore[no-untyped-call]
id=work_id
)
connector.create_edition_from_data(work, data)


Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/connectors/inventaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def get_description(self, links: JsonDict) -> str:
data = get_data(url)
except ConnectorException:
return ""
return data.get("extract", "")
return str(data.get("extract", ""))

def get_remote_id_from_model(self, obj: models.BookDataModel) -> str:
"""use get_remote_id to figure out the link from a model obj"""
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bookwyrm import models, settings


def site_settings(request): # pylint: disable=unused-argument
def site_settings(request):
"""include the custom info about the site"""
request_protocol = "https://"
if not request.is_secure():
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/forms/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def __init__(self, *args, **kwargs):
css_classes["number"] = "input"
css_classes["checkbox"] = "checkbox"
css_classes["textarea"] = "textarea"
# pylint: disable=super-with-arguments
super().__init__(*args, **kwargs)
for visible in self.visible_fields():
input_type = ""
if hasattr(visible.field.widget, "input_type"):
input_type = visible.field.widget.input_type
if isinstance(visible.field.widget, Textarea):
Expand Down
1 change: 1 addition & 0 deletions bookwyrm/forms/edit_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Meta:
"email",
"summary",
"show_goal",
"show_ratings",
"show_suggested_users",
"manually_approves_followers",
"default_post_privacy",
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/forms/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def infer_username(self):

def add_invalid_password_error(self):
"""We don't want to be too specific about this"""
# pylint: disable=attribute-defined-outside-init
self.non_field_errors = _("Username or password are incorrect")


Expand Down
2 changes: 0 additions & 2 deletions bookwyrm/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
class ArrayWidget(forms.widgets.TextInput):
"""Inputs for postgres array fields"""

# pylint: disable=unused-argument
# pylint: disable=no-self-use
def value_from_datadict(self, data, files, name):
"""get all values for this name"""
return [i for i in data.getlist(name) if i]
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/importers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" import classes """

from .importer import Importer
from .bookwyrm_import import BookwyrmImporter
from .bookwyrm_import import BookwyrmImporter, BookwyrmBooksImporter
from .calibre_import import CalibreImporter
from .goodreads_import import GoodreadsImporter
from .librarything_import import LibrarythingImporter
Expand Down
15 changes: 15 additions & 0 deletions bookwyrm/importers/bookwyrm_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from bookwyrm.models import User
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob
from . import Importer


class BookwyrmImporter:
Expand All @@ -22,3 +23,17 @@ def process_import(
user=user, archive_file=archive_file, required=required
)
return job


class BookwyrmBooksImporter(Importer):
"""
Handle reading a csv from BookWyrm.
Goodreads is the default importer, we basically just use the same structure
But BookWyrm has additional attributes in the csv
"""

service = "BookWyrm"
row_mappings_guesses = Importer.row_mappings_guesses + [
("shelf_name", ["shelf_name"]),
("review_published", ["review_published"]),
]
13 changes: 4 additions & 9 deletions bookwyrm/importers/calibre_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ class CalibreImporter(Importer):
def __init__(self, *args: Any, **kwargs: Any):
# Add timestamp to row_mappings_guesses for date_added to avoid
# integrity error
row_mappings_guesses = []

for field, mapping in self.row_mappings_guesses:
if field in ("date_added",):
row_mappings_guesses.append((field, mapping + ["timestamp"]))
else:
row_mappings_guesses.append((field, mapping))

self.row_mappings_guesses = row_mappings_guesses
self.row_mappings_guesses = [
(field, mapping + (["timestamp"] if field == "date_added" else []))
for field, mapping in self.row_mappings_guesses
]
super().__init__(*args, **kwargs)

def get_shelf(self, normalized_row: dict[str, Optional[str]]) -> Optional[str]:
Expand Down
Loading

0 comments on commit 019978b

Please sign in to comment.