-
Notifications
You must be signed in to change notification settings - Fork 845
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
base: master
Are you sure you want to change the base?
Added pelican-gfm plugin #1224
Conversation
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.
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.
Thanks for submitting this plugin !
I made a quick review and asked a few questions.
Also, could you provide some tests please ?
pelican-gfm/gfmSetup.py
Outdated
LIBCMARKLOCATION = "/usr/lib/x86_64-linux-gnu" | ||
|
||
ARCHIVES = "https://github.com/github/cmark-gfm/archive" | ||
VERSION = "0.28.3.gfm.12" |
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.
Could you make this a configurable setting maybe ?
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.
I'd much prefer this path is configurable because I might not have those packages at /usr/lib/x86_64-linux-gnu
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.
I've put these values in the Settings.py file so that we can update them without having to update any actual code.
pelican-gfm/gfm.py
Outdated
# 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) |
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.
Raising an exception would be best, and allow to specify an explicit error message
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.
Done.
pelican-gfm/gfmSetup.py
Outdated
|
||
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"]) |
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.
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
??
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.
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.
pelican-gfm/gfmSetup.py
Outdated
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' |
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.
Better use tempfile.TemporaryDirectiry
: https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory
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.
Used tempfile TemporaryDirectory
pelican-gfm/Readme.md
Outdated
Requirements | ||
============ | ||
|
||
pelican-gfm has no requirements that are outside of the python standard library aside from pelican itself. |
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.
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 ?
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.
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.
pelican-gfm/Readme.md
Outdated
@@ -0,0 +1,22 @@ | |||
pelican-gfm |
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.
From my understanding, this plugin will only work on Debian systems.
Better mention this OS limitation in the README
pelican-gfm/gfm.py
Outdated
OPTS = 0 | ||
|
||
# The GFM extensions that we want to use | ||
EXTENSIONS = ( |
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.
Could this be made configurable as a setting ?
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.
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.
pelican-gfm/gfmSetup.py
Outdated
|
||
# Move the libcmark.so artifacts in place | ||
print("Moving files") | ||
subprocess.call([ |
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.
Is there some reason you can't use shutil.move
to move the files here?
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.
good catch! I ended up going with shutil for these moves.
pelican-gfm/__init__.py
Outdated
@@ -1,3 +1,3 @@ | |||
#!/usr/bin/environment python -B | |||
#!/usr/bin/environment python333 -B |
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.
Is the python333
a typo?
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.
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.
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.
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.
pelican-gfm/gfmSetup.py
Outdated
ARCHIVES + "/" + VERSION + ".tar.gz", WORKSPACE, | ||
"-P", | ||
WORKSPACE]) | ||
subprocess.call(['tar', |
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.
Could we replace this subprocess.call
to tar -xzf
with using the standard library tarfile
?
pelican-gfm/gfmSetup.py
Outdated
os.mkdir(WORKSPACE) | ||
subprocess.call(["wget", | ||
"--quiet", | ||
ARCHIVES + "/" + VERSION + ".tar.gz", WORKSPACE, |
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.
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.
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.
the paths are now made with os.path.join
pelican-gfm/gfmSetup.py
Outdated
WORKSPACE + "/" + VERSION + ".tar.gz", | ||
"-C", | ||
WORKSPACE]) | ||
BUILDSPACE = WORKSPACE + "/" + "cmark-gfm-" + VERSION + "/build" |
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.
Likewise os.path.join
would be good for creating the path here
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.
and os.path.join is used here also
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.
thanks for making these changes
Updated the readme
unconfigured system will no instruct you as to how to configure the system
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.
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.
pelican-gfm/gfm.py
Outdated
from . import gfmSetup | ||
from . import Settings | ||
|
||
try: |
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.
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?
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.
I got the absolute imports working but now the plugin doesn't conform to your documentation.
pelican-gfm/gfm.py
Outdated
|
||
try: | ||
from . import Settings | ||
except: |
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.
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.
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.
I ended up removing this entirely.
pelican-gfm/test.py
Outdated
|
||
import unittest | ||
|
||
# python2 and python3 differ on how to do this it seems |
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.
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
pelican-gfm/gfm.py
Outdated
from . import gfmSetup | ||
from . import Settings | ||
import gfmSetup | ||
import Settings |
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.
Can you show what's not working with:
from . import gfmSetup
That should work.
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.
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.
pelican-gfm/gfmSetup.py
Outdated
t2 = subprocess.Popen([ | ||
"grep", | ||
"-q", | ||
package | ||
], stdout=subprocess.PIPE, stdin=t1.stdout) |
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.
So... you're running grep
to check for a string in a bunch of lines from python
? :)
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.
yeah, that does seem silly. thanks for pointing that out.
There were a few flake8 exceptions in pelican-gfm:
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