GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.stackstorm.com — Development — StackStorm 3.9.0 documentation DevelopmentThis page describes the StackStorm development processes and contains general guidelines and information on how to contribute to the project. ContributingWe welcome and appreciate contributions of any kind (code, tests, documentation, examples, use cases, …). If you need help or get stuck at any point during this process, stop by on our Slack Community and we will do our best to assist you. For information on contributing an integration pack, please refer to the Create and Contribute a Pack page. For an overview of core StackStorm code structure, please refer to Code structure. Setting up a Development EnvironmentThere are multiple ways for you to set up a development environment and get started with StackStorm development. The easiest approach is to use our Vagrant images which contain all the dependencies you need to get started. For more information, see Vagrant Install. Another approach is to install StackStorm and all the dependencies from source on a server or VM of your liking. For more information about this approach, see Installing StackStorm from sources. If you are already running Docker / Docker Desktop, another option to develop locally is to utilize the available extensions in VSCode to get setup. This works especially well for MacOS users. For more information, see Setting up VSCode & Docker Development General Contribution Guidelines
Code Style Guide
Most StackStorm repositories use shared Flake8 and PyLint configuration files, which you can get from the lint-configs repo. And most importantly, follow the existing style in the file you are editing and be consistent. Pre commit hookFor development, we strongly recommend installing and using a git pre-commit hook which is included in the StackStorm/st2 repository. This pre-commit hook automatically runs all the style checks (black formatting, flake8, pylint) on the modified / added code. This is much faster than running those targets on the whole code base. You can use the following commands to install the pre-commit hook: pip install pre-commit pre-commit install Now the defined hooks will automatically run each time you try to commit some code. You can also manually run it on any modified (but not yet committed) files using the following command: pre-commit Keep in mind that the pre-commit hook depends on development virtual environment
being created and present in Deprecation PolicySometimes we need to deprecate features. Usually this is because there is now a much better way of doing something. Where these changes affect users, we must ensure that we give ample warning, and a chance to migrate, before we remove the old features completely. Our general deprecation policy is to provide notice for at least two major (x.y) versions, before a feature is removed. This is an example of a typical deprecation timeline:
We may choose to have a longer notice period, but in general this will not be more than 4 major versions. There is a cost to maintaining legacy features. General Coding GuidelinesLoggingLogging is important because it increases the visibility and makes the project easier to debug and support. You are encouraged to generously use the log statements across the code base. You should log every event which increases the visibility and/or makes the product easier to debug and support. Every log statement should also include as much as useful additional context as possible. This
context should be included in the dictionary which is passed via the Default log formatters we use include this additional context as part of the message which makes it easier for users to find the relevant information. On top of that, we also offer GELF log formatters which outputs log messages in GELF format (structured JSON). This formatter can be used to ship structured logs to Graylog2, loggly, logstash or a similar service. Obtaining a Reference to the Logger ObjectTo obtain a reference to the logger instance you should use the In most cases, you should do this at the top of the module after the imports and reuse this logger throughout that module: from st2common import log as logging LOG = logging.getLogger(__name__) LOG.debug('....') Passing Context to the LoggerAs noted above, you should always include as much context as possible in the log messages.
Context is provided by passing a dictionary via the This dictionary should contain values which are relevant to the log message in question (e.g. created/modified database object, user who performed the action, etc.). If you are passing an instance of a custom class as a value, you should implement the Keep in mind that this method is already implemented for all of the StackStorm
database objects ( action_db = ... user_db = ... remote_addr = ... extra = {'action_db': action_db, 'user_db': user_db, 'remote_addr': remote_addr} LOG.debug('New action has been created. ActionDB.id=%s' % (action_db.id), extra=extra) Using the AUDIT Log LevelStackStorm code declares a custom For example: LOG.audit('KeyValuePair updated. KeyValuePair.id=%s' % (kvp_db.id), extra=extra) Dealing with Dates and Datetime ObjectsAll the If you want to store a timestamp with microsecond precision you should use the
If you want to retrieve a Instantiating Model ClassesWhen instantiating Good: action_db = ActionDB(pack='mypack', name='myaction', enabled=True) Bad: action_db = ActionDB() action_db.pack = 'mypack' action_db.name = 'myaction' action_db.enabled = True Passing all the fields as keyword arguments to the constructor means we can preserve the constructor functionality. On top of that it also makes it more clear and obvious to the developers when the values are available and allows us to perform basic “static” analysis on the code. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |