Skip to content

Commit

Permalink
Merge pull request #21 from smarie/feature/19_packaging
Browse files Browse the repository at this point in the history
Feature/19 packaging
  • Loading branch information
smarie authored Jan 27, 2022
2 parents f2fc74a + 87a6843 commit c3f2389
Show file tree
Hide file tree
Showing 29 changed files with 38 additions and 15 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 0.7.1 - Packaging is now correct

- Fixed packaging issue: static resources were not included in wheel. Adopted `src/` layout. Fixed [#19](https://github.com/smarie/mkdocs-gallery/issues/19).

### 0.7.0 - Code output max height + updated one example

- Code output now have a correct height limit. Fixed [#7](https://github.com/smarie/mkdocs-gallery/issues/7)
Expand Down
26 changes: 13 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,30 @@ def tests(session: PowerSession, coverage, pkg_specs):
# Fail if the assumed python version is not the actual one
session.run2("python ci_tools/check_python_version.py %s" % session.python)

# install self so that it is recognized by pytest
session.run2("pip install -e . --no-deps")
# session.install("-e", ".", "--no-deps")

# check that it can be imported even from a different folder
# Important: do not surround the command into double quotes as in the shell !
session.run('python', '-c', 'import os; os.chdir(\'./docs/\'); import %s' % pkg_name)

# finally run all tests
if not coverage:
# install self so that it is recognized by pytest
session.run2("pip install . --no-deps")

# simple: pytest only
session.run2("python -m pytest --cache-clear -v tests/")
else:
# install self in "develop" mode so that coverage can be measured
session.run2("pip install -e . --no-deps")

# coverage + junit html reports + badge generation
session.install_reqs(phase="coverage",
phase_reqs=["coverage", "pytest-html", "genbadge[tests,coverage]", "mkdocs"]
+ MKDOCS_GALLERY_EXAMPLES_REQS,
versions_dct=pkg_specs)

# --coverage + junit html reports
session.run2("coverage run --source {pkg_name} "
session.run2("coverage run --source src/{pkg_name} "
"-m pytest --cache-clear --junitxml={test_xml} --html={test_html} -v tests/"
"".format(pkg_name=pkg_name, test_xml=Folders.test_xml, test_html=Folders.test_html))

# -- use the doc generation for coverage
session.run2("coverage run --append --source {pkg_name} -m mkdocs build"
session.run2("coverage run --append --source src/{pkg_name} -m mkdocs build"
"".format(pkg_name=pkg_name, test_xml=Folders.test_xml, test_html=Folders.test_html))

session.run2("coverage report")
Expand All @@ -146,12 +144,14 @@ def flake8(session: PowerSession):

session.install("-r", str(Folders.ci_tools / "flake8-requirements.txt"))
session.install("genbadge[flake8]")
session.run2("pip install -e .[flake8]")
session.run2("pip install .")

rm_folder(Folders.flake8_reports)
Folders.flake8_reports.mkdir(parents=True, exist_ok=True)
rm_file(Folders.flake8_intermediate_file)

session.cd("src")

# Options are set in `setup.cfg` file
session.run("flake8", pkg_name, "--exit-zero", "--format=html", "--htmldir", str(Folders.flake8_reports),
"--statistics", "--tee", "--output-file", str(Folders.flake8_intermediate_file))
Expand All @@ -177,7 +177,7 @@ def docs(session: PowerSession):
session.install_reqs(phase="docs", phase_reqs=["mkdocs"] + MKDOCS_GALLERY_EXAMPLES_REQS)

# Install the plugin
session.run2("pip install -e .")
session.run2("pip install .")

if session.posargs:
# use posargs instead of "serve"
Expand All @@ -196,7 +196,7 @@ def publish(session: PowerSession):
)

# Install the plugin
session.run2("pip install -e .")
session.run2("pip install .")

# possibly rebuild the docs in a static way (mkdocs serve does not build locally)
session.run2("mkdocs build")
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ tests_require =
zip_safe = False
# explicitly setting zip_safe=False to avoid downloading `ply` see https://github.com/smarie/python-getversion/pull/5
# and makes mypy happy see https://mypy.readthedocs.io/en/latest/installed_packages.html
package_dir=
=src
packages = find:
# see [options.packages.find] below
# IMPORTANT: DO NOT set the `include_package_data` flag !! It triggers inclusion of all git-versioned files
# see https://github.com/pypa/setuptools_scm/issues/190#issuecomment-351181286
# include_package_data = True
[options.packages.find]
where=src
exclude =
contrib
docs
*tests*

[options.package_data]
* = py.typed, *.pyi
* = py.typed, *.pyi, static/*


# Optional dependencies that can be installed with e.g. $ pip install -e .[dev,test]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
setup(
download_url=DOWNLOAD_URL,
use_scm_version={
"write_to": "mkdocs_gallery/_version.py"
"write_to": "src/mkdocs_gallery/_version.py"
}, # we can't put `use_scm_version` in setup.cfg yet unfortunately
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path

import pkg_resources

from mkdocs_gallery import glr_path_static
from mkdocs_gallery.scrapers import _find_image_ext


def test_packaged_static():
"""Test that the static resources can be found in the package."""
binder_badge = pkg_resources.resource_string("mkdocs_gallery", "static/binder_badge_logo.svg").decode("utf-8")
assert binder_badge.startswith("<svg")

thumb_source_path = Path(glr_path_static()) / 'broken_example.png'
thumb_image_path, ext = _find_image_ext(thumb_source_path)
assert ext == ".png"

0 comments on commit c3f2389

Please sign in to comment.