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

Conversation

dfoulks1
Copy link

There were a few flake8 exceptions in pelican-gfm:

  • init.py imports gfm.* but does not call it.
  • a line in gfm.py is too long (left unshortened)

The python unittest ran without error

Created a Readme.md file for this plugin. 10k foot view

Updated the Readme.rst in the pelican-plugins root.

This plugin references getpelican/pelican#2387

There were a few flake8 exceptions in pelican-gfm:
  - __init__.py imports gfm.* but does not call it.
  - a line in gfm.py is too long (left unshortened)

The python unittest ran without error

Created a Readme.md file for this plugin. 10k foot view

Updated the Readme.rst in the pelican-plugins root.
Copy link
Contributor

@Lucas-C Lucas-C left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this plugin !
I made a quick review and asked a few questions.
Also, could you provide some tests please ?

LIBCMARKLOCATION = "/usr/lib/x86_64-linux-gnu"

ARCHIVES = "https://github.com/github/cmark-gfm/archive"
VERSION = "0.28.3.gfm.12"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make this a configurable setting maybe ?

Choose a reason for hiding this comment

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

I'd much prefer this path is configurable because I might not have those packages at /usr/lib/x86_64-linux-gnu

Copy link
Author

Choose a reason for hiding this comment

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

I've put these values in the Settings.py file so that we can update them without having to update any actual code.

# Optionally we can have the gfmSetup script run here
# as root and configure the system
# Probably just easier to run it independently tho.
sys.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Raising an exception would be best, and allow to specify an explicit error message

Copy link
Author

Choose a reason for hiding this comment

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

Done.


def apt_install(package):
# I need to be able to do this a better, in a less sudo + apt-y way
subprocess.call(["apt-get", "install", package, "-y"])
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think those kind of installation steps should be automatically done by plugins.
They'd better be detailed in the plugin README.
What if the those steps require sudo rights on the user machine ? What if he uses apt or yum as a package manager and not apt-get ??

Copy link
Author

Choose a reason for hiding this comment

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

I agree, this is a remnant of when this script was a part of something else. I had mistakenly left it in. It's since been removed.

ARCHIVES = "https://github.com/github/cmark-gfm/archive"
VERSION = "0.28.3.gfm.12"
LOCAL = "cmark-gfm.$VERSION.orig.tar.gz"
WORKSPACE = '/tmp/build-cmark'
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Used tempfile TemporaryDirectory

Requirements
============

pelican-gfm has no requirements that are outside of the python standard library aside from pelican itself.
Copy link
Contributor

@Lucas-C Lucas-C Oct 18, 2019

Choose a reason for hiding this comment

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

Out of curiosity, have you tried https://pypi.org/project/gfm/ or https://pypi.org/project/py-gfm/ ?
Do they provide what you need maybe, already bundled as a Python package ?

Copy link
Author

Choose a reason for hiding this comment

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

I believe that there were pieces of the github markup that those packages did not readily provide. I'm not 100% sure as I Inherited the base of this.

@@ -0,0 +1,22 @@
pelican-gfm
Copy link
Contributor

Choose a reason for hiding this comment

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

From my understanding, this plugin will only work on Debian systems.
Better mention this OS limitation in the README

OPTS = 0

# The GFM extensions that we want to use
EXTENSIONS = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be made configurable as a setting ?

Copy link
Author

Choose a reason for hiding this comment

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

this is also now a setting

trying to make it a little more terse and get rid of some of the junk
that was in there. Also putting better documentation in the functions.
did PEP8 verification on the scripts via pycodestyle. they all pass.
I also added a vars file so that we can set where the plugin will work.
made sure that the plugin still runs. looks great and serves up just
fine. I've pulled most of the configurables out of the script and put
it into a vars file. hopefully this will suffice for the pelican folks.
got tempfile.TemporaryDirectory to work out just fine.
also checks the config like a champ.

# Move the libcmark.so artifacts in place
print("Moving files")
subprocess.call([

Choose a reason for hiding this comment

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

Is there some reason you can't use shutil.move to move the files here?

Copy link
Author

Choose a reason for hiding this comment

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

good catch! I ended up going with shutil for these moves.

@@ -1,3 +1,3 @@
#!/usr/bin/environment python -B
#!/usr/bin/environment python333 -B

Choose a reason for hiding this comment

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

Is the python333 a typo?

Copy link
Author

Choose a reason for hiding this comment

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

Yes that was a typo.

also removed an erroneous interpreter typo
Will write some tests tomorrow
tried to get this to work when invoked with python or python3. currently
works best with python3. something about the
tempfile.TemporaryDirectory() call not working. I can handle that
another day.
Copy link

@shuttle1987 shuttle1987 left a comment

Choose a reason for hiding this comment

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

I feel as though we could use CFFI to handle the interaction with the C library and allow this plugin to be installable in a more cross platform manner. I might give this a go in a future PR, in the interim I've made a few suggestions about creating paths that could help this code be more cross platform.

ARCHIVES + "/" + VERSION + ".tar.gz", WORKSPACE,
"-P",
WORKSPACE])
subprocess.call(['tar',

Choose a reason for hiding this comment

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

Could we replace this subprocess.call to tar -xzf with using the standard library tarfile?

os.mkdir(WORKSPACE)
subprocess.call(["wget",
"--quiet",
ARCHIVES + "/" + VERSION + ".tar.gz", WORKSPACE,

Choose a reason for hiding this comment

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

I'd prefer if these paths were created with os.path.join such that we can be more easily able to make this cross platform in the future.

Copy link
Author

@dfoulks1 dfoulks1 Dec 18, 2019

Choose a reason for hiding this comment

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

the paths are now made with os.path.join

WORKSPACE + "/" + VERSION + ".tar.gz",
"-C",
WORKSPACE])
BUILDSPACE = WORKSPACE + "/" + "cmark-gfm-" + VERSION + "/build"

Choose a reason for hiding this comment

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

Likewise os.path.join would be good for creating the path here

Copy link
Author

Choose a reason for hiding this comment

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

and os.path.join is used here also

Choose a reason for hiding this comment

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

thanks for making these changes

unconfigured system will no instruct you as to how to configure the
system
Copy link

@shuttle1987 shuttle1987 left a comment

Choose a reason for hiding this comment

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

If you are looking to make the behavior of Python 2 and 3 consistent with regards to import semantics have a look at PEP 328 which introduced from __future__ import absolute_import. I think this is a better approach than the except ImportError way.

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.


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 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

to avoid the try / except for importing
Couldn't get thee imports to work consistently.
the format doesn't seem to gel with your contributing a plugin
documentation.

https://github.com/getpelican/pelican-plugins/blob/master/Contributing.rst
from . import gfmSetup
from . import Settings
import gfmSetup
import Settings
Copy link
Member

Choose a reason for hiding this comment

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

Can you show what's not working with:

from . import gfmSetup

That should work.

Copy link
Author

Choose a reason for hiding this comment

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

I'm sorry, I was making notes for myself there. I couldn't get the unittest to work and still have test content be generated. that seems to be corrected now.

Comment on lines 19 to 23
t2 = subprocess.Popen([
"grep",
"-q",
package
], stdout=subprocess.PIPE, stdin=t1.stdout)
Copy link
Member

Choose a reason for hiding this comment

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

So... you're running grep to check for a string in a bunch of lines from python? :)

Copy link
Author

Choose a reason for hiding this comment

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

yeah, that does seem silly. thanks for pointing that out.

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.

4 participants