Skip to content

Commit

Permalink
pylint continues on code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dozymoe committed Sep 24, 2022
1 parent 0b84776 commit 575a71c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/requirements.txt
/python_modules
/pybuildtool/.coverage
/.coverage


# waf
Expand Down
2 changes: 1 addition & 1 deletion README-Upload.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pip install --upgrade pip build
pip install --upgrade pip build twine
python -m build
python -m twine upload --repository testpypi dist/*
python -m twine upload --repository pypi dist/*
2 changes: 1 addition & 1 deletion lib/fireh_runner
88 changes: 48 additions & 40 deletions pybuildtool/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,44 @@ Summary
-------

PyBuildTool helps transform resources and run automated tests as you code, I
usually have it watched the project files while editing with vim.
usually have it watches the project files while editing with vim.

PyBuildTool is written in python as a higher level interface to `Waf
<http://waf.io>`_, a meta build system.

The configuration file you'd interact with: ``build.yml``, is declarative,
written in yaml. While the build tools which you could also write, were made to
The configuration file you'd interact with: **build.yml**, is declarative,
written in yaml. While the build tools, which you could also write, were made to
be simple, following a pattern.

The configuration file does not need to be named "build.yml", just change
the file ``wscript`` (this is something that waf needs). You need to create
``wscript`` file yourself, following the example here:
the file **wscript** (this is something that waf needs). You need to create
**wscript** file yourself, following the example here:
http://raw.githubusercontent.com/dozymoe/PyBuildTool/master/pybuildtool/wscript.example

There are builtin tools, you can use them as examples to build your own build
tools, see them here: http://github.com/dozymoe/PyBuildTool/tree/master/pybuildtool/tools.
See how they were imported by the ``wscript`` file.
There are builtin tools, you can use them as example to build your own build
tool, see them here: http://github.com/dozymoe/PyBuildTool/tree/master/pybuildtool/tools.
See how they were imported by the **wscript** file.

Since you control the ``wscript`` file, you control much of the aspect of the
Since you control the **wscript** file, you control much of the aspect of the
build process.

If you wanted to go deeper than just editing ``build.yml`` you could read
If you wanted to go deeper than just editing **build.yml** you could read
`introduction to waf and wscript <http://waf.io/apidocs/tutorial.html>`_, or
a more technical `waf project structure <http://waf.io/book/#_basic_project_structure>`_.

There're three stages predefined: "dev", "stage", and "prod" (see the
``wscript`` file), but the functionality isn't there yet, they have separate
**wscript** file), but the functionality isn't there yet, they have separate
temporary build directory of their own but they still share the same build
rules.

Currently stages were implemented like this: for ``clean-css`` tool, if the
Currently stages were implemented like this: for **clean-css** tool, if the
current stage was one of "dev" or "devel" or "development" it will do copy
operation instead of css file minification.

This is an example of ``build.yml``, pretend it's a django project:
This is an example of **build.yml**, pretend it's a Django project:

Note: If you see :code:`<s>` or :code:`</s>` that is a rendering bug from
pypi website.

.. code:: yaml
Expand Down Expand Up @@ -139,20 +142,22 @@ Several things to keep in mind:
- "djangoprj", "blogapp", "jshint", "concat" are group names.

- JSHINT_EXCLUDES is not a group name (it matches all capital letters and
underscore), pybuildtool will not recognize this entry, but ``yaml.load``
will.
underscore), pybuildtool will not recognize this entry, but
:code:`yaml.load` will.
It can be used as `yaml node anchor`_.

- ``{_1}`` is string replacement thingy for a group name based on its level.
- :code:`{_1}` is string replacement thingy for a group name based on its
level.

- Because group name can be used as string replacement for file
names, they can be used to represent directory structures.

- "@djangoprj/djangoprj/jshint" is a reference to files
generated by the rule "djangoprj"-"djangoprj"-"jshint", that is,
the combination of its ``file_out``, ``raw_file_out`` and ``extra_out``.
the combination of its :code:`file_out`, :code:`raw_file_out` and
:code:`extra_out`.

- You can use `ant glob`_ like this ``**/*.js``
- You can use `ant glob`_ like this :code:`**/*.js`.

- You can use directory as output, they must end with path separator, for
example: "minified_js/"
Expand All @@ -165,24 +170,24 @@ Several things to keep in mind:
specified before.
We don't support lazy loading of rules yet.

- The directive ``raw_file_in`` or ``raw_depend_in`` is used for ``waf watch``
to get list of files need to be monitored.
- The directive :code:`raw_file_in` or :code:`raw_depend_in` is used for
:code:`waf watch` to get list of files need to be monitored.

- The directive ``depend_in`` can be used to force the tool to process
``file_in`` if files in ``depend_in`` changes.
- The directive :code:`depend_in` can be used to force the tool to process
:code:`file_in` if files in :code:`depend_in` changes.

- The directive ``extra_out`` can be used to list auxiliary files produced by
the tool, it can be used with combination of ``@group:group`` directive as
inputs for other tools.
- The directive :code:`extra_out` can be used to list auxiliary files produced
by the tool, it can be used with combination of :code:`@group:group`
directive as inputs for other tools.

- The option field: ``_source_excluded_`` is list of files which will be
- The option field: :code:`_source_excluded_` is list of files which will be
excluded from inputs.

- The directive ``raw_file_out`` means this rule's outputs will be
- The directive :code:`raw_file_out` means this rule's outputs will be
written in the actual file system, by default it's generated inside
'.BUILD/stage/' directory.

- The option field: ``config_file`` is configuration item provided by each
- The option field: :code:`config_file` is configuration item provided by each
tools, in this case it was provided by "pylint", "jshint", and "jscs", and
they happened to have used the same name.
When option field is placed in higher group level, it's prefixed with the
Expand All @@ -192,34 +197,37 @@ Several things to keep in mind:
Warning
-------

``waf`` does not like it if the source and target existed in the same directory,
:code:`waf` does not like it if the source and target existed in the same
directory,
see: `Files are always built`_.

If you used `rule_in` you may need to run `waf build` multiple times until there
was nothing to build, when the system is first initialize with `waf configure`
or by `waf clean`.
If you used :code:`rule_in` you may need to run :code:`waf build` multiple times
until there was nothing to build, when the system is first initialize with
:code:`waf configure` or by :code:`waf clean`.

Install
-------

1. ``pip install pybuildtool``
1. :code:`pip install pybuildtool`


#. Install **waf** as executable binary, download from `Waf project
<http://waf.io>`_.

You could also ``pip install waftools`` and then run ``wafinstall``,
caution: this method will modify your ``~/.bashrc`` adding ``WAFDIR=???``.
You could also :code:`pip install waftools` and then run
:code:`wafinstall`.
Caution: this method will modify your **~/.bashrc** adding
:code:`WAFDIR=???`.

#. Copy and modify ``wscript`` in your project's root directory, specify the
build tools your are going to use.
#. Copy and modify **wscript** in your project's root directory, specify
the build tools your are going to use.

#. Create ``build.yml`` with content like our example, this will be
#. Create **build.yml** with content like our example, this will be
your build rules.

#. ``waf configure``
#. :code:`waf configure`

#. ``waf build_dev`` or ``waf watch_dev``
#. :code:`waf build_dev` or :code:`waf watch_dev`


.. _ant glob: http://ant.apache.org/manual/dirtasks.html
Expand Down
22 changes: 21 additions & 1 deletion pybuildtool/tools/pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,25 @@
to install, run `pip install pylint`
"""
from enum import Enum
from pybuildtool import BaseTask, expand_resource, make_list

tool_name = __name__


class PylintExitCode(Enum):
"""Exit codes for pylint
See: https://pylint.pycqa.org/en/latest/user_guide/usage/run.html#exit-codes
"""
FATAL = 1
ERROR = 2
WARNING = 4
REFACTOR = 8
CONVENTION = 16
USAGE = 32


class Task(BaseTask):

conf = {
Expand Down Expand Up @@ -87,14 +102,19 @@ def perform(self):
kwargs['cwd'] = self.workdir

executable = self.env['%s_BIN' % tool_name.upper()]
return self.exec_command(
ret = self.exec_command(
'{exe} {arg} {in_}'.format(
exe=executable,
arg=' '.join(self.args),
in_=' '.join(self.file_in),
),
**kwargs)

real_error = ret & PylintExitCode.FATAL.value \
or ret & PylintExitCode.ERROR.value \
or ret & PylintExitCode.USAGE.value
return real_error


def configure(conf):
conf.env['%s_BIN' % tool_name.upper()] = conf.find_program(tool_name)[0]
1 change: 1 addition & 0 deletions requirements-development.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-r requirements-production.txt

build
coverage
pylint
pytest
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pybuildtool
version = 2.0.38
version = 2.0.39
description = Build utility to manage web resources.
long_description = file: README.rst
url = https://github.com/dozymoe/PyBuildTool
Expand Down

0 comments on commit 575a71c

Please sign in to comment.