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

Added pelican-gfm plugin #1224

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pelican-gfm/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Before Pelican GFM run it checks:
If Pelican GFM finds that there is a configuration issue it will recommend that you run the following:
`python gfmSetup.py`

## Testing

There is a unittest written for gfm. the test will register and spawn a new reader and return true if there were no issues.

Syntax
======
This plugin leverages [GitHub Flavored Markdown](https://github.github.com/gfm/) in `md, markdown, mkd, mdown` files to generate html pages.
Expand Down
20 changes: 15 additions & 5 deletions pelican-gfm/gfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@
import pelican.utils
import pelican.signals
import pelican.readers
from . import gfmSetup
from . import Settings

try:

Choose a reason for hiding this comment

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

What is the purpose of this block with the relative import? If you are trying to maintain some compatibility with ancient Python versions can you solve this problem with the PEP 328 from __future__ import absolute_import approach?

Copy link
Author

Choose a reason for hiding this comment

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

I got the absolute imports working but now the plugin doesn't conform to your documentation.

from . import gfmSetup
except ImportError:
import gfmSetup

try:
from . import Settings
except:

Choose a reason for hiding this comment

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

If you want to use this approach for imports I think this should only catch an ImportError.
See my above comment about other potential approaches.

Copy link
Author

Choose a reason for hiding this comment

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

I ended up removing this entirely.

import Settings

_LIBDIR = Settings.LIBCMARKLOCATION
_LIBCMARK = 'libcmark-gfm.so'
Expand Down Expand Up @@ -204,13 +212,15 @@ def render(self, text):

def add_readers(readers):
msg = "GFM plugin cannot find the required libcmark files.\
Please run python gfmSetup.py to build and\
configure the appropriate libcmark files"
Please run python3 gfmSetup.py as a user with write permission \
to the directory into which the libcmark files will be placed."
if gfmSetup.test_configuration():
readers.reader_classes['md'] = GFMReader
return True
else:
raise Exception(msg)


def register():
pelican.signals.readers_init.connect(add_readers)
reader = pelican.signals.readers_init.connect(add_readers)
return(reader)
15 changes: 6 additions & 9 deletions pelican-gfm/gfmSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import subprocess
import shutil
import tarfile

# Importing in python2 and python3 is different
# for these for some reason. this should catch
Expand Down Expand Up @@ -89,20 +90,16 @@ def setup():
subprocess.call([
"wget",
"--quiet",
Settings.ARCHIVES + "/" + Settings.VERSION + ".tar.gz",
os.path.join(Settings.ARCHIVES, Settings.VERSION + ".tar.gz"),
WORKSPACE,
"-P",
WORKSPACE
])

# Untar the files
subprocess.call([
'tar',
'zxf',
WORKSPACE + "/" + Settings.VERSION + ".tar.gz",
"-C",
WORKSPACE
]
)
tf = tarfile.open(os.path.join(WORKSPACE, Settings.VERSION + ".tar.gz"))
tf.extractall(path=WORKSPACE)

# Create a buildspace for your cmake operation
BUILDSPACE = WORKSPACE + "/cmark-gfm-" + Settings.VERSION + "/build"

Expand Down
17 changes: 17 additions & 0 deletions pelican-gfm/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python -B

import unittest

# python2 and python3 differ on how to do this it seems

Choose a reason for hiding this comment

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

See my other comment about from __future__ import absolute_import

try:
from .gfm import *
except ImportError:
import gfm

class gfmTest(unittest.TestCase):

def test_for_gfm(self):
self.assertTrue(gfm.register())

if __name__ == '__main__':
unittest.main()