Skip to content

Commit

Permalink
service: dev: create: blank: Create a blank python project
Browse files Browse the repository at this point in the history
For creating non-DFFML plugin Python packages

Fixes: #1245
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
  • Loading branch information
pdxjohnny committed Oct 7, 2021
1 parent 63956df commit 8b6d000
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ function run_plugin() {
plugin_creation_dir="$(mktemp -d)"
TEMP_DIRS+=("${plugin_creation_dir}")
cd "${plugin_creation_dir}"
# Run the create command to create a non-dffml package
plugin="blank"
dffml service dev create "${plugin}" "ci-test-${plugin}"
cd "ci-test-${plugin}"
"${PYTHON}" -m pip install -U .
"${PYTHON}" -m unittest discover -v
# Build the docs
"${PYTHON}" -c 'import os, pkg_resources; [e.load() for e in pkg_resources.iter_entry_points("console_scripts") if e.name.startswith("sphinx-build")][0]()' -W -b html docs/ built_html_docs/
cd "${plugin_creation_dir}"
# Plugins we know how to make
PLUGINS=(\
"model" \
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Examples of using data cleanup operations
https://intel.github.io/dffml/examples/data_cleanup/index.html
- Dev CMD to remove unused imports, `$ dffml service dev lint imports`
- Helper for creating a blank generic Python package
`$ dffml service dev create blank mypackage`
### Changed
- Calls to hashlib now go through helper functions
- Build docs using `dffml service dev docs`
Expand Down
1 change: 1 addition & 0 deletions dffml/service/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class Create(CMD):
service = create_from_skel("service")
source = create_from_skel("source")
config = create_from_skel("config")
blank = create_from_skel("blank")


class Link(CMD):
Expand Down
41 changes: 41 additions & 0 deletions dffml/skel/blank/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[metadata]
name = REPLACE_PACKAGE_NAME
description = REPLACE_DESCRIPTION
long_description = file: README.rst
author = REPLACE_AUTHOR_NAME
author_email = REPLACE_AUTHOR_EMAIL
maintainer = REPLACE_AUTHOR_NAME
maintainer_email = REPLACE_AUTHOR_EMAIL
url = https://github.com/REPLACE_ORG_NAME/REPLACE_PACKAGE_NAME
license = MIT
# keywords = dffml
classifiers =
Development Status :: 3 - Alpha
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy

[options]
zip_safe = False
include_package_data = True
packages = find:
# entry_points = file: entry_points.txt
setup_requires =
setuptools_scm[toml]>=3.4.3
# install_requires =
# dffml>=REPLACE_DFFML_VERSION

[options.extras_require]
dev =
coverage
codecov
sphinx
twine
setuptools_scm[toml]>=3.4.3
black==19.10b0
importlib_metadata>=4.8.1;python_version<"3.8"
3 changes: 2 additions & 1 deletion dffml/util/skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def create_symlinks(self, plugin):
if not linkpath.parent.is_dir():
linkpath.parent.mkdir(parents=True)
# Resolving first gives more helpful error message if it fails
linkpath.resolve().symlink_to(filepath)
if not linkpath.resolve().is_file():
linkpath.resolve().symlink_to(filepath)

def copy_template(self, plugin, target):
# Recursive copy (shutil.copytree doesn't do the right thing if
Expand Down
8 changes: 7 additions & 1 deletion docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ Create
++++++

You can create a new python package and start implementing a new plugin for
DFFML right away with the ``create`` command of ``dev``.
DFFML right away with the ``create`` command of ``dev``. Use ``-h`` to see all
the plugin types (``dffml service dev create -h``).

.. code-block:: console
:test:
Expand All @@ -568,6 +569,11 @@ DFFML right away with the ``create`` command of ``dev``.
$ python -m pip install -e .[dev]
$ python -m unittest discover -v
.. note::

If you want to create a Python package that is not a dffml plugin, you can
use ``dffml service dev create blank mypackage``.

When you're done you can upload it to PyPi and it'll be ``pip`` installable so
that other DFFML users can use it in their code or via the CLI. If you don't
want to mess with uploading to ``PyPi``, you can install it from your git repo
Expand Down
4 changes: 4 additions & 0 deletions tests/service/test_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ async def test_run(self):
self.assertGreater(len(plugins), 3)
for plugin in plugins:
for check in COMMON_FILES:
# We skip the setup.cfg symlink check for blank because it has a
# custom setup.cfg
if plugin.name == "blank" and check.name == "setup.cfg":
continue
with chdir(plugin):
self.assertTrue(
check.is_symlink(),
Expand Down

0 comments on commit 8b6d000

Please sign in to comment.