Skip to content

Commit

Permalink
Merge branch 'release-0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sinoroc committed Jun 12, 2019
2 parents 7eedc1c + 204cd04 commit c19f9d7
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 207 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

'test py38 dev':
<<: *job_test_common
allow_failure: true
image: 'python:3.8-rc'
variables:
'TOXENV': 'py38'
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,29 @@

.. Keep the current version number on line number 5
0.0.1
=====

2019-06-12

* Add action as CLI optional argument. The action has to be specified on the
command line. Either one of:

* ``--build``, ``-b`` to build (existing tools are skipped);
* ``--rebuild``, ``-r`` to rebuild (existing tools are rebuilt);
* ``--delete``, ``-d`` to delete (tool target file is deleted if it exists,
its parent directory is deleted if it is empty).

* Replace CLI calls to external tools in virtual environment with API calls to
external libraries.


0.0.0
=====

2019-05-13

Release initial version.


.. EOF
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ develop:


.PHONY: package
package: sdist wheel check zapp
package: sdist wheel zapp


.PHONY: sdist
sdist:
python3 setup.py sdist
python3 -m twine check dist/*.tar.gz


.PHONY: wheel
wheel:
python3 setup.py bdist_wheel
python3 -m twine check dist/*.whl


.PHONY: zapp
Expand All @@ -33,9 +35,8 @@ zapp:


.PHONY: check
check: sdist wheel
python3 -m twine check dist/*.tar.gz
python3 -m twine check dist/*.whl
check:
python3 setup.py check


.PHONY: lint
Expand Down Expand Up @@ -63,7 +64,7 @@ pytest:


.PHONY: review
review:
review: check
python3 -m pytest --pep8 --pylint


Expand Down
74 changes: 71 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,74 @@
..

Introduction
============

This tool automates the build of Python tools according to a configuration
file. The tools can be built with `zapp`_, `shiv`_, or `pex`_.


Repositories
------------

Binary distributions:

* http://pypi.org/project/toolmaker/

Source code:

* https://gitlab.com/sinoroc/toolmaker
* https://github.com/sinoroc/toolmaker


Usage
=====

Place in a subdirectory of your ``bin`` directory and use in combination with
*GNU stow*.
Configuration
-------------

By default this tool looks for a configuration file ``toolmaker.cfg`` in the
current working directory.

.. code::
[http.pex]
entry_point = http.server
output_file = http
requirements =
[pipdeptree.zapp]
entry_point = pipdeptree:main
output_file = pipdeptree
requirements =
pipdeptree
setuptools
[shiv.shiv]
console_script = shiv
output_file = shiv
requirements =
shiv
Action
------

The action can be specified on the command line. Either one of:

* ``--build``, ``-b`` to build (already existing tools are skipped);
* ``--rebuild``, ``-r`` to rebuild (already existing tools are rebuilt);
* ``--delete``, ``-d`` to delete (tool target file is deleted if it exists, then
its parent directory is deleted if it is empty).

The default action when no flag is specified is to build the tools.


Tips
----

Place in a subdirectory of a directory that is available on your ``PATH``
(typically your ``~/bin`` directory) and use in combination with `GNU Stow`_.


Details
Expand All @@ -14,7 +77,7 @@ Details
Similar projects
----------------

* https://github.com/Valassis-Digital-Media/Zapper
* `Zapper`_


Hacking
Expand Down Expand Up @@ -64,8 +127,13 @@ Outside of a Python virtual environment run the following command::
.. Links
.. _`GNU Make`: https://www.gnu.org/software/make/
.. _`GNU Stow`: https://www.gnu.org/software/stow/
.. _`pex`: https://pypi.org/project/pex/
.. _`pytest`: https://pytest.org/
.. _`shiv`: https://pypi.org/project/shiv/
.. _`tox`: https://tox.readthedocs.io/
.. _`zapp`: https://pypi.org/project/zapp/
.. _`Zapper`: https://github.com/Valassis-Digital-Media/Zapper


.. EOF
25 changes: 25 additions & 0 deletions example.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#


[http.pex]
entry_point = http.server
output_file = http
requirements =


[pipdeptree.zapp]
entry_point = pipdeptree:main
output_file = pipdeptree
requirements =
pipdeptree
setuptools


[shiv.shiv]
entry_point = shiv.cli:main
output_file = shiv
requirements =
shiv


# EOF
11 changes: 10 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
entry_point = toolmaker.cli:main


[check]
metadata = 1
strict = 1


[metadata]
name = toolmaker
author = sinoroc
author_email = [email protected]
description = toolmaker application
license = Apache-2.0
long_description = file: README.rst
long_description_content_type = text/x-rst
url = https://pypi.org/project/toolmaker


[options]
install_requires =
setuptools
importlib_metadata
pex
shiv
zapp
package_dir =
= src
packages = find:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3


""" Setup script """
Expand Down
47 changes: 24 additions & 23 deletions src/toolmaker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,25 @@ def _create_args_parser(default_config_path, tools_names=None):
default=str(default_config_path),
type=argparse.FileType('r'),
)
group = args_parser.add_mutually_exclusive_group(required=True)
group.add_argument(
action_group = args_parser.add_mutually_exclusive_group()
action_group.add_argument(
'--build', '-b',
action='store_true',
)
action_group.add_argument(
'--rebuild', '-r',
action='store_true',
)
action_group.add_argument(
'--delete', '-d',
action='store_true',
)
tools_group = args_parser.add_mutually_exclusive_group(required=True)
tools_group.add_argument(
'--all', '-a',
action='store_true',
)
group.add_argument(
tools_group.add_argument(
'--tools', '-t',
choices=tools_names,
metavar='tool',
Expand All @@ -46,6 +59,7 @@ def main():
"""
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

cwd_path = pathlib.Path.cwd()
default_config_path = cwd_path.joinpath('toolmaker.cfg')

Expand All @@ -54,6 +68,7 @@ def main():

config = None
if args.config:
logger.info("Reading configuration from file '%s'", args.config)
config = configparser.ConfigParser()
try:
config.read_file(args.config)
Expand All @@ -68,26 +83,12 @@ def main():
if args.tools:
tools_names = args.tools

logger.info("Preparing to build tools %s", tools_names)

venv_path = cwd_path.joinpath('venv')

logger.info("Creating virtual environment '%s'...", venv_path)
venv_context = core.venv_create(venv_path)

logger.info("Updating virtual environment")
core.venv_update(venv_context)

for tool_name in tools_names:
if tool_name.endswith('.pex'):
logger.info("Building pex tool '%s'", tool_name)
core.build_pex(cwd_path, venv_context, config, tool_name)
if tool_name.endswith('.shiv'):
logger.info("Building shiv tool '%s'", tool_name)
core.build_shiv(cwd_path, venv_context, config, tool_name)
if tool_name.endswith('.zapp'):
logger.info("Building zapp tool '%s'", tool_name)
core.build_zapp(cwd_path, venv_context, config, tool_name)
if args.delete:
core.delete(cwd_path, config, tools_names)
elif args.rebuild:
core.build(cwd_path, config, tools_names, force=True)
else:
core.build(cwd_path, config, tools_names)


# EOF
Loading

0 comments on commit c19f9d7

Please sign in to comment.