Skip to content

Commit

Permalink
Merge pull request #23 from davidomarf/serve
Browse files Browse the repository at this point in the history
Implement `ginpar serve` with livereload
  • Loading branch information
davidomarf committed Oct 24, 2019
2 parents 5bd3fb5 + f763999 commit 9439d2a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 11 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ black = "*"
Jinja2 = "*"
PyYAML = "*"
click = "*"
livereload = "*"

[requires]
python_version = "3.7"
Expand Down
31 changes: 29 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions ginpar/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
ginpar serve --port=3000
ginpar serve -p=3000
To force the initialization in case there is a directory with the same name
of the project to initialize::
ginpar force --force
ginpar force -f
"""
import click
import yaml
from livereload import Server, shell


## TODO: Move read_config into a shared library inside utils
def read_config(path):
"""Create a dictionary out of the YAML file received
Paremeters
----------
path : str
Path of the YAML file.
"""
with open(path, "r") as stream:
try:
config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
return config


def serve(port):
Expand All @@ -34,4 +47,9 @@ def serve(port):
port : int
The port of the server
"""
click.secho("You're serving", fg="blue")
site = read_config("config.yaml")

server = Server()

server.watch(site["content_path"], 'ginpar build')
server.serve(port=port, root=site["build_path"])
43 changes: 43 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
alabaster==0.7.12
appdirs==1.4.3
argh==0.26.2
astroid==2.3.2
attrs==19.3.0
Babel==2.7.0
black==19.3b0
certifi==2019.9.11
chardet==3.0.4
Click==7.0
doc8==0.8.0
docutils==0.15.2
idna==2.8
imagesize==1.1.0
importlib-metadata==0.23
isort==4.3.21
Jinja2==2.10.3
lazy-object-proxy==1.4.2
livereload==2.6.1
MarkupSafe==1.1.1
mccabe==0.6.1
more-itertools==7.2.0
packaging==19.2
Pallets-Sphinx-Themes==1.2.2
pathtools==0.1.2
pbr==5.4.3
port-for==0.3.1
Pygments==2.4.2
pylint==2.4.3
pyparsing==2.4.2
pytz==2019.3
PyYAML==5.1.2
requests==2.22.0
restructuredtext-lint==1.3.0
six==1.12.0
snowballstemmer==2.0.0
Sphinx==2.1.2
sphinx-autobuild==0.7.1
sphinx-click==2.3.0
sphinx-prompt==1.1.0
sphinxcontrib-applehelp==1.0.1
sphinxcontrib-devhelp==1.0.1
sphinxcontrib-htmlhelp==1.0.2
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-programoutput==0.15
sphinxcontrib-qthelp==1.0.2
sphinxcontrib-serializinghtml==1.1.3
stevedore==1.31.0
toml==0.10.0
tornado==6.0.3
typed-ast==1.4.0
urllib3==1.25.6
virtualenv==16.7.6
watchdog==0.9.0
wrapt==1.11.2
zipp==0.6.0
7 changes: 5 additions & 2 deletions tests/test_serve.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os

from click.testing import CliRunner
from ginpar import cli

def test_serve():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cli, ["serve"])
runner.invoke(cli, ["init", "-q"])
os.chdir("my-site")
result = runner.invoke(cli, ["serve", "--help"])
assert result.exit_code == 0
assert "You're serving" in result.output

0 comments on commit 9439d2a

Please sign in to comment.