Skip to content
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

External Plugins v2 #1216

Merged
merged 60 commits into from May 30, 2021
Merged

Conversation

MinchinWeb
Copy link
Contributor

@MinchinWeb MinchinWeb commented Mar 17, 2021

(This is a follow up to #1115 because in that one I pushed directly to develop, plus it's been squashed and rebased, and it proved easier in my head to make a new branch.)

The open "issues" from #1115:

  • Tests: not included yet. Any ideas on how to change the installed Python packages in a "new" testing environment?
  • handling of name conflicts: Running jrnl --version will show you the list of active plugins, include where they came from.
  • display plugin version: Also on jrnl --version
  • documentation: Done!

Sample jrnl --version output:

λ jrnl --version
jrnl version v2.7.2-beta

Copyright (C) 2012-2021 jrnl contributors

This is free software, and you are welcome to redistribute it under certain
conditions; for details, see: https://www.gnu.org/licenses/gpl-3.0.html

Active Plugins:
    Importers:
        jrnl : v2.7.2-beta from jrnl.plugins.importer.jrnl_importer
    Exporters:
        boxed : v2.7.2-beta from jrnl.plugins.exporter.fancy_exporter
        fancy : v2.7.2-beta from jrnl.plugins.exporter.fancy_exporter
        json : v2.7.2-beta from jrnl.plugins.exporter.json_exporter
        markdown : v2.7.2-beta from jrnl.plugins.exporter.markdown_exporter
        md : v2.7.2-beta from jrnl.plugins.exporter.markdown_exporter
        tags : v2.7.2-beta from jrnl.plugins.exporter.tag_exporter
        text : v2.7.2-beta from jrnl.plugins.exporter.text_exporter
        txt : v2.7.2-beta from jrnl.plugins.exporter.text_exporter
        xml : v2.7.2-beta from jrnl.plugins.exporter.xml_exporter
        yaml : v2.7.2-beta from jrnl.plugins.exporter.yaml_exporter

For documentation, I would love to take insert the sample plugins from external files, and use those same external files as a base for the testing. Is the first part (inserting an external file) possible to MkDocs?

Also, the template exporter got dropped because I couldn't figure out how to make it work with displaying the version numbers... Is that okay?

@micahellison micahellison force-pushed the develop branch 2 times, most recently from 9eb9990 to f50b430 Compare March 20, 2021 19:25
@wren wren force-pushed the develop branch 5 times, most recently from 234e1f3 to de17222 Compare March 20, 2021 21:13
Check column widths

update gitignore

throw error when linewrap too small

simply check for large enough linewrap value
make exception more informative

update check_linewrap signature in src and test

make check_linewrap a free function
@MinchinWeb
Copy link
Contributor Author

OK, tests work and they pass! Hallelujah! I won't claim that it's beautiful, but it works, and I'm happy with that.

@wren

Why do we need to change the directory? I see a comment about plugins not being detected. Do we know why that is?

I think this is a combination of the plugins being namespace plugins and the main jrnl source being locally importable from the project root folder. Namespace plugins work be creating a "virtual" module out of several physical locations on disk; when importing the jrnl module from the project root (rather than from the site-packages folder where it's installed by pip), these namespace modules aren't recognized as namespace modules, and instead come up as empty.

To test this:

# navigate to the project root folder
# create a virtual environment and activate it
python -m venv .venv-test-plugins
source .venv-test-plugins/bin/activate
# on Windows: .\.venv-test-plugins\Scripts\activate
# install jrnl
pip install .
# install the test plugins
pip install ./tests/external_plugins_src/
# install behave
pip install behave
# run behave; note the number of steps completed
behave --format progress2
# 1738 steps passed, 0 failed, 163 skipped, 0 undefined
# now change up a folder and rerun behave
cd ..
behave --format progress2 ./jrnl/features
# 1664 steps passed, 0 failed, 237 skipped, 0 undefined

In any case, I think we're ready to merge! @micahellison

@MinchinWeb MinchinWeb changed the title [WIP] External Plugins v2 External Plugins v2 May 18, 2021
@micahellison
Copy link
Member

Thanks @MinchinWeb! I see this is ready for review, and I'll plan on diving into this in a week. Also, we won't merge anything big in before that so there won't be any more major merge conflicts to deal with.

# Conflicts:
#	poetry.lock
#	pyproject.toml
@micahellison
Copy link
Member

Hi @MinchinWeb, I'm reviewing this while educating myself on namespace packages here and I see that there are three different approaches for namespace packages, but I can't tell which is being used in this PR. Or is there a completely different approach that it's using, and if so, what's the advantages of it?

@MinchinWeb
Copy link
Contributor Author

Hi @micahellison These are "native namespace packages" (the first option mentioned on the page you link to).

Why this way? It seems to be the most "modern" option, and beyond getting the plugin files in the right place, there should be no packaging boilerplate for plugin authors.

@micahellison
Copy link
Member

Got it, thanks. I agree that it makes sense -- I was just confused that the form of the sample plugin looked a little different from the documentation I linked. Then I learned more about __init__.py than I ever thought there was to know...

Along those lines, I'm chatting about this with @wren and we think we have a solution to this folder issue you documented, by removing the two __init__.py files from jrnl and moving their functionality elsewhere. We should have a patch coming in a bit.

@micahellison
Copy link
Member

Actually, we're going to merge this into a feature branch so we can work on it a bit more asynchronously.

@micahellison micahellison changed the base branch from develop to feature-plugins May 30, 2021 00:19
Copy link
Member

@micahellison micahellison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨🔌✨

@micahellison micahellison merged commit 1a7e8d8 into jrnl-org:feature-plugins May 30, 2021
@MinchinWeb
Copy link
Contributor Author

@micahellison I'm curious about what more needs to be done/what else you want in place before merging this to master...

@MinchinWeb MinchinWeb deleted the external-plugins branch June 16, 2021 01:39
@wren
Copy link
Member

wren commented Jun 19, 2021

cc: #1006

@micahellison
Copy link
Member

Hi @MinchinWeb sorry for the slowness on this -- it's been a busy month. I just put my notes in the linked issue.

@wren
Copy link
Member

wren commented Jun 19, 2021

@MinchinWeb Quick note: jrnl doesn't have a branch named master anymore. We renamed our main branches a while back to develop and release (where develop is the default branch that all PRs are pointed to) to avoid using language that could be hurtful to some people.

wren pushed a commit that referenced this pull request Jul 17, 2021
* behavior outline
* FIrst pass at allow external plugins
* remove template exporter
* Add listing of active plugins to '--version' output
* Documentation for plugins
* [Docs] add custom imports and exporters to site TOC
* [Docs] better linewrapping
* enforce positive initial linewrap
  Check column widths
  update gitignore
  throw error when linewrap too small
  simply check for large enough linewrap value
* delete unused error message
* PR feedback
  make exception more informative
  update check_linewrap signature in src and test
  make check_linewrap a free function
* delete unused function
* delete else..pass block
* newline for make format
* Include dates_exporter
* Use Base classes for importer and exporters.
* [Docs] improve documentation of custom Importers and Exporters
* [Testing] separate run with external plugin!
* basic behavior test
* prototype unittest for JSON Exporter
  test for unimplemented method
* make format
  delete unused imports
* Remove 'importer' or 'exporter' from filenames where not needed
* [Test] run different tests with or without the external plugins installed
* [Test] move test rot13 plugin into git tree
  from MinchinWeb/jrnl-rot13-exporter@0dc912a
* consolidate demo plugins to common package
* [Docs] name page for plugins
* [Docs] include the sample plug in code files directly
* style fixes
* [test] determine whether to run external plug in tests based on installed packages
* improved code documentation
* style fixes for GitHub actions
* Convert "short" and "pretty" (and "default") formaters to plugins
  further to #1177
* more code clean up
  tests pass locally...now for GitHub...
* [tests] dynamically determine jrnl version for plugin tests
* [GitHub Actions] direct install of testing plugins
* Remove template code
* [plugins] meta --> collector
* [Docs] create scripted entries using an custom importer
* (closer to) being able to run behave tests outside project root directory
* We already know when exporter to use
  Don't re-calculate it!
* [Tests] don't name test plugin 'testing"
  If so named, pip won't install it.
* [Test] run behave tests with test plugins outside project root
* [Test] behave tests pass locally
* [Docs] fix typo
* [GitHub Actions] run test commands from poetry's shell
* black-ify code
* [GitHub Actions] move downstream (rather than up) to run tests
* [GitHub Actions] set shell to poetry
* [GitHub Workflows] Manually activate virtual environment
* [GitHub Actions] Skip Windows & Python 3.8
  Can't seem to find Python exe?
* [GiotHub Actions] explicitly use virtual env
* [GitHub Actions] create virutal env directly
* [GitHub Actions] better activate of Windows virtual env
* [GitHub Actions] create virtual env on Mac
* [Github Actions] install wheel and upgrade pip
* [GitHub Actions] skip virtual environments altogether
* [GitHub Actions] change directory for behave test
* Remove Windows exclusions from CI as per note -- they should be working now

Co-authored-by: Suhas <sugas182@gmail.com>
Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
wren pushed a commit that referenced this pull request Jul 17, 2021
* behavior outline
* FIrst pass at allow external plugins
* remove template exporter
* Add listing of active plugins to '--version' output
* Documentation for plugins
* [Docs] add custom imports and exporters to site TOC
* [Docs] better linewrapping
* enforce positive initial linewrap
  Check column widths
  update gitignore
  throw error when linewrap too small
  simply check for large enough linewrap value
* delete unused error message
* PR feedback
  make exception more informative
  update check_linewrap signature in src and test
  make check_linewrap a free function
* delete unused function
* delete else..pass block
* newline for make format
* Include dates_exporter
* Use Base classes for importer and exporters.
* [Docs] improve documentation of custom Importers and Exporters
* [Testing] separate run with external plugin!
* basic behavior test
* prototype unittest for JSON Exporter
  test for unimplemented method
* make format
  delete unused imports
* Remove 'importer' or 'exporter' from filenames where not needed
* [Test] run different tests with or without the external plugins installed
* [Test] move test rot13 plugin into git tree
  from MinchinWeb/jrnl-rot13-exporter@0dc912a
* consolidate demo plugins to common package
* [Docs] name page for plugins
* [Docs] include the sample plug in code files directly
* style fixes
* [test] determine whether to run external plug in tests based on installed packages
* improved code documentation
* style fixes for GitHub actions
* Convert "short" and "pretty" (and "default") formaters to plugins
  further to #1177
* more code clean up
  tests pass locally...now for GitHub...
* [tests] dynamically determine jrnl version for plugin tests
* [GitHub Actions] direct install of testing plugins
* Remove template code
* [plugins] meta --> collector
* [Docs] create scripted entries using an custom importer
* (closer to) being able to run behave tests outside project root directory
* We already know when exporter to use
  Don't re-calculate it!
* [Tests] don't name test plugin 'testing"
  If so named, pip won't install it.
* [Test] run behave tests with test plugins outside project root
* [Test] behave tests pass locally
* [Docs] fix typo
* [GitHub Actions] run test commands from poetry's shell
* black-ify code
* [GitHub Actions] move downstream (rather than up) to run tests
* [GitHub Actions] set shell to poetry
* [GitHub Workflows] Manually activate virtual environment
* [GitHub Actions] Skip Windows & Python 3.8
  Can't seem to find Python exe?
* [GiotHub Actions] explicitly use virtual env
* [GitHub Actions] create virutal env directly
* [GitHub Actions] better activate of Windows virtual env
* [GitHub Actions] create virtual env on Mac
* [Github Actions] install wheel and upgrade pip
* [GitHub Actions] skip virtual environments altogether
* [GitHub Actions] change directory for behave test
* Remove Windows exclusions from CI as per note -- they should be working now

Co-authored-by: Suhas <sugas182@gmail.com>
Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
MinchinWeb added a commit to MinchinWeb/minchin.jrnl that referenced this pull request Sep 22, 2023
MinchinWeb added a commit to MinchinWeb/minchin.jrnl that referenced this pull request Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants