Skip to content

Commit

Permalink
feat!: add type hints on all system functions
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
* Python versions below or above 2.7.18 are not supported
* `system.date` and Java's Date are no longer using `datetime` functions
* remove deprecated functions from `system.tag`
  • Loading branch information
cesarcoatl committed Nov 23, 2021
1 parent 5b1da1f commit 51ed6a2
Show file tree
Hide file tree
Showing 64 changed files with 4,317 additions and 3,939 deletions.
3 changes: 2 additions & 1 deletion .flake8
@@ -1,4 +1,5 @@
[flake8]
ignore = F401, F821
ignore = E741, F401, F821
max-complexity = 10
max-doc-length = 72
max-line-length = 120
2 changes: 1 addition & 1 deletion .github/workflows/pypi_upload.yml
Expand Up @@ -5,7 +5,7 @@ on:
types: [published]

env:
PYTHON_VERSION: 3.9
PYTHON_VERSION: 2.7

jobs:
upload:
Expand Down
12 changes: 8 additions & 4 deletions .pylintrc
Expand Up @@ -20,7 +20,7 @@ fail-on=
fail-under=10.0

# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS
ignore=

# Add files or directories matching the regex patterns to the ignore-list. The
# regex matches against paths.
Expand Down Expand Up @@ -50,6 +50,10 @@ load-plugins=
# Pickle collected data for later comparisons.
persistent=yes

# Min Python version to use for version dependend checks. Will default to the
# version used to run pylint.
py-version=3.10

# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
suggestion-mode=yes
Expand Down Expand Up @@ -285,7 +289,7 @@ indent-after-paren=4
indent-string=" "

# Maximum number of characters on a single line.
max-line-length=79
max-line-length=120

# Maximum number of lines in a module.
max-module-lines=1500
Expand Down Expand Up @@ -400,7 +404,7 @@ good-names-rgxs=
include-naming-hint=no

# Naming style matching correct inline iteration names.
inlinevar-naming-style=snake_case
inlinevar-naming-style=any

# Regular expression matching correct inline iteration names. Overrides
# inlinevar-naming-style.
Expand Down Expand Up @@ -521,7 +525,7 @@ valid-metaclass-classmethod-first-arg=cls

[DESIGN]

# List of qualified class names to ignore when countint class parents (see
# List of qualified class names to ignore when counting class parents (see
# R0901)
ignored-parents=

Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -115,16 +115,16 @@ To use Ignition, you may install it by doing any of the following.

##### Installing with `pip`

The preferred method is to install it by running `pip`. It requires Python 2.7.18, or higher.
The preferred method is to install it by running `pip`. It requires Python 2.7.18.

```bash
python -m pip install ignition-api
python2 -m pip install ignition-api
```

This will install it as package to your Python installation, which will allow you to call Ignition Scripting functions from Python's REPL, and get code completion using an IDE (we recommend PyCharm).

```bash
$ python
$ python2
Python 2.7.18 (default, Nov 9 2020, 16:23:15)
[GCC Apple LLVM 12.0.0 (clang-1200.0.32.21)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Expand All @@ -143,7 +143,7 @@ Client data, as well as interact with other various systems.
And to uninstall:

```bash
python -m pip uninstall ignition-api
python2 -m pip uninstall ignition-api
```

###### Using Ignition as a dependency on PyCharm
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Expand Up @@ -9,7 +9,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
url = https://thecesrom.dev/Ignition
project_urls =
Documentation = https://docs.inductiveautomation.com/
Documentation = https://docs.inductiveautomation.com/display/DOC81/System+Functions
Funding = https://github.com/sponsors/thecesrom
Source = https://github.com/thecesrom/Ignition
Tracker = https://github.com/thecesrom/Ignition/issues
Expand All @@ -28,8 +28,8 @@ classifiers =
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2 :: Only
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Software Development :: Testing :: Mocking
keywords =
Expand All @@ -42,7 +42,7 @@ keywords =
package_dir =
=src
packages = find:
python_requires = >=2.7.18
python_requires = ==2.7.18

[options.packages.find]
where = src
@@ -1,4 +1,4 @@
from __future__ import print_function
from __future__ import print_function, unicode_literals

__all__ = [
"INavUtilities",
Expand Down
@@ -1,4 +1,4 @@
from __future__ import print_function
from __future__ import print_function, unicode_literals

__all__ = ["AlarmEvent", "PyAlarmEvent", "PyAlarmEventImpl"]

Expand Down
46 changes: 8 additions & 38 deletions src/com/inductiveautomation/ignition/common/model/__init__.py
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

__all__ = ["Version"]

import re
Expand All @@ -10,16 +12,6 @@ class Version(Object):
snapshot = False

def __init__(self, major=0, minor=0, rev=0, build=0, beta=0, rc=0):
"""Version initializer.
Args:
major (int): Major number.
minor (int): Minor number.
rev (int): Revision number.
build (int): Build number.
beta (int): Beta number.
rc (int): Release Candidate number.
"""
self.major = major
self.minor = minor
self.rev = rev
Expand Down Expand Up @@ -53,18 +45,6 @@ def __str__(self):
return self.toString()

def compareTo(self, that):
"""Compares two Versions.
Note that this comparison is stricter than we want for Gateway
restores or project imports. For those, isFutureVersion().
Args:
that (Version): The version to compare.
Returns:
int: 0 if self and that are equal, -1 if that is greater
than self, or 1 if self is greater than that.
"""
return self.__eq__(that, True)

def exists(self):
Expand All @@ -75,13 +55,11 @@ def fromXML(inputStream):
pass

def getBasicString(self):
if self.rc > 0:
ret = "{}.{}.{}-rc{}".format(
self.major, self.minor, self.rev, self.rc
)
else:
ret = "{}.{}.{}".format(self.major, self.minor, self.rev)
return ret
return (
"{}.{}.{}-rc{}".format(self.major, self.minor, self.rev, self.rc)
if self.rc > 0
else "{}.{}.{}".format(self.major, self.minor, self.rev)
)

def getBeta(self):
return self.beta
Expand Down Expand Up @@ -120,15 +98,7 @@ def parse(s):
return Version(sem_ver[0], sem_ver[1], sem_ver[2])

def toParseableString(self):
"""Returns the version as a compact, parseable (non-XML) string
that can be parsed with the 1-string constructor of this class.
Returns:
string: Compact, parseable (non-XML) string.
"""
return "{}.{}.{}.{}".format(
self.major, self.minor, self.rev, self.build
)
return "{}.{}.{}.{}".format(self.major, self.minor, self.rev, self.build)

def toString(self):
if self.rc > 0:
Expand Down
Expand Up @@ -121,6 +121,8 @@ def getValue(self):


class BasicQualifiedValue(QualifiedValue, Object):
"""The basic implementation of QualifiedValue."""

quality = QualityCode.Bad_Stale
timestamp = Date()
value = None
Expand Down
62 changes: 62 additions & 0 deletions src/com/inductiveautomation/ignition/common/opc/__init__.py
@@ -0,0 +1,62 @@
__all__ = ["BasicOPCBrowseElement", "OPCBrowseElement", "ServerBrowseElement"]

from java.lang import Object


class OPCBrowseElement(object):
def getDataType(self):
raise NotImplementedError

def getDescription(self):
raise NotImplementedError

def getDisplayName(self):
raise NotImplementedError

def getElementType(self):
raise NotImplementedError

def getServerNodeId(self):
raise NotImplementedError


class BasicOPCBrowseElement(Object, OPCBrowseElement):
def __init__(self, *args):
pass

def getDataType(self):
pass

def getDescription(self):
pass

def getDisplayName(self):
pass

def getElementType(self):
pass

def getServerNodeId(self):
pass


class ServerBrowseElement(Object, OPCBrowseElement):
_serverName = None

def __init__(self, serverName):
self._serverName = serverName

def getDataType(self):
pass

def getDescription(self):
pass

def getDisplayName(self):
pass

def getElementType(self):
pass

def getServerNodeId(self):
pass
@@ -1,4 +1,4 @@
from __future__ import print_function
from __future__ import print_function, unicode_literals

__all__ = ["PyJsonObjectAdapter"]

Expand Down

0 comments on commit 51ed6a2

Please sign in to comment.