-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Plone 5.2 / also refactor reindex helpers #17
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Plone 5.2 install - tests are currently not run | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.8"] | ||
steps: | ||
# git checkout | ||
- uses: actions/checkout@v4 | ||
|
||
# pin plone version (happens from make, but to be on the safe side) | ||
- name: Pin plone 5.2 | ||
run: | | ||
cp constraints-5.2.txt constraints.txt | ||
cp requirements-5.2.txt requirements.txt | ||
|
||
# python setup | ||
- name: Set up Python ${{ matrix.python-version }} with Plone 5.2.5 | ||
uses: plone/[email protected] | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
plone-version: "5.2.5" | ||
|
||
# python cache | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
|
||
# test | ||
# XXX cannot run pytests, version conflict. | ||
# - name: Run tests | ||
# run: bin/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-c https://dist.plone.org/release/5.2.5/constraints.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-c https://dist.plone.org/release/6.0.6/constraints.txt | ||
plone.restapi>=8.40.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-c https://dist.plone.org/release/6.0.6/constraints.txt | ||
plone.restapi>=8.40.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-c constraints.txt | ||
|
||
# Cannot install new testing framework with 5.2 | ||
# -e ".[test]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-c constraints.txt | ||
-e ".[test]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,20 @@ | ||
from collective.solr.interfaces import ISolrConnectionManager | ||
from plone.registry.interfaces import IRegistry | ||
from kitconcept.solr.reindex_helpers import activate_and_reindex | ||
from Testing.makerequest import makerequest | ||
from zope.component import getUtility | ||
from zope.component import queryUtility | ||
from zope.site.hooks import setSite | ||
|
||
import logging | ||
import sys | ||
import transaction | ||
|
||
|
||
logger = logging.getLogger("kitconcept.solr") | ||
logger.setLevel(logging.DEBUG) | ||
if __name__ == "__main__": | ||
app = makerequest(app) # noQA | ||
|
||
indexer_logger = logging.getLogger("collective.solr.indexer") | ||
# Set site to Plone | ||
site_id = "Plone" | ||
portal = app.unrestrictedTraverse(site_id) | ||
setSite(portal) | ||
|
||
activate_and_reindex(portal, clear="--clear" in sys.argv) | ||
|
||
def solr_is_running(portal): | ||
manager = queryUtility(ISolrConnectionManager, context=portal) | ||
schema = manager.getSchema() | ||
return schema is not None | ||
|
||
|
||
def solr_must_be_running(portal): | ||
if not solr_is_running(portal): | ||
logger.fatal("*** Solr must be running! (make solr-start) ***") | ||
sys.exit(1) | ||
|
||
|
||
def activate(active=True): | ||
"""(de)activate the solr integration""" | ||
registry = getUtility(IRegistry) | ||
registry["collective.solr.active"] = active | ||
|
||
|
||
def silence_logger(): | ||
orig_logger_exception = indexer_logger.exception | ||
|
||
def new_logger_exception(msg): | ||
if msg != "Error occured while getting data for indexing!": | ||
orig_logger_exception(msg) | ||
|
||
indexer_logger.exception = new_logger_exception | ||
|
||
def reactivate_logger(): | ||
indexer_logger.exception = orig_logger_exception | ||
|
||
return reactivate_logger | ||
|
||
|
||
def reindex(portal): | ||
"""reindex the existing content in solr""" | ||
maintenance = portal.unrestrictedTraverse("@@solr-maintenance") | ||
if "--clear" in sys.argv: | ||
logger.info("Clearing solr...") | ||
maintenance.clear() | ||
# Avoid throwing a lot of errors which are actually not errors, | ||
# but the indexer keeps throwing them when it tries to traverse everything. | ||
reactivate_logger = silence_logger() | ||
logger.info("Reindexing solr...") | ||
maintenance.reindex() | ||
reactivate_logger() | ||
|
||
|
||
app = makerequest(app) # noQA | ||
|
||
# Set site to Plone | ||
site_id = "Plone" | ||
portal = app.unrestrictedTraverse(site_id) | ||
setSite(portal) | ||
|
||
# Activate before confirming solr is running, | ||
# because the confirmation only works if solr is enabled in the registry. | ||
# If solr isn't running, we'll exit | ||
# before committing the transaction with the activation. | ||
activate() | ||
solr_must_be_running(portal) | ||
reindex(portal) | ||
|
||
transaction.commit() | ||
app._p_jar.sync() | ||
transaction.commit() | ||
app._p_jar.sync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from collective.solr.interfaces import ISolrConnectionManager | ||
from plone import api | ||
from zope.component import queryUtility | ||
|
||
import logging | ||
|
||
|
||
logger = logging.getLogger("kitconcept.solr") | ||
logger.setLevel(logging.DEBUG) | ||
|
||
indexer_logger = logging.getLogger("collective.solr.indexer") | ||
|
||
|
||
def solr_is_running(portal): | ||
manager = queryUtility(ISolrConnectionManager, context=portal) | ||
schema = manager.getSchema() | ||
return schema is not None | ||
|
||
|
||
def solr_must_be_running(portal): | ||
if not solr_is_running(portal): | ||
logger.fatal("*** Solr must be running! (make solr-start) ***") | ||
return False | ||
return True | ||
|
||
|
||
def activate(active=True): | ||
"""(de)activate the solr integration""" | ||
api.portal.set_registry_record("collective.solr.active", active) | ||
|
||
|
||
def silence_logger(): | ||
orig_logger_exception = indexer_logger.exception | ||
|
||
def new_logger_exception(msg): | ||
if msg != "Error occured while getting data for indexing!": | ||
orig_logger_exception(msg) | ||
|
||
indexer_logger.exception = new_logger_exception | ||
|
||
def reactivate_logger(): | ||
indexer_logger.exception = orig_logger_exception | ||
|
||
return reactivate_logger | ||
|
||
|
||
def reindex(portal, clear=False): | ||
"""reindex the existing content in solr""" | ||
maintenance = portal.unrestrictedTraverse("@@solr-maintenance") | ||
if clear: | ||
logger.info("Clearing solr...") | ||
maintenance.clear() | ||
# Avoid throwing a lot of errors which are actually not errors, | ||
# but the indexer keeps throwing them when it tries to traverse everything. | ||
reactivate_logger = silence_logger() | ||
logger.info("Reindexing solr...") | ||
maintenance.reindex() | ||
reactivate_logger() | ||
|
||
|
||
def activate_and_reindex(portal, clear=False): | ||
# Activate before confirming solr is running, | ||
# because the confirmation only works if solr is enabled in the registry. | ||
# If solr isn't running, we'll exit | ||
# before committing the transaction with the activation. | ||
activate() | ||
if solr_must_be_running(portal): | ||
reindex(portal, clear=clear) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have the workflow if we are not running the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least it runs the install and checks that the dependencies are correct, which is something because that was also breaking earlier.
The main problem is that the test dependencies conflict for me with the Plone 5.2 requirements.
I'd like to run the test but @ericof is it possible to install pytests with Plone 5.2? I'm getting version conflicts. If this is something that is resolvable I'm glad to put more time into it, but it's just a waste of time if the answer is "no".