Skip to content

Commit

Permalink
Initial python code from internal repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hewlett committed May 21, 2021
1 parent 5e8f612 commit a05000d
Show file tree
Hide file tree
Showing 72 changed files with 6,001 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto
*.py text
*.yaml text
*.md text
38 changes: 38 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python Quality Control

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-api.txt
- name: Run integrity checks
run: |
export PYTHONPATH=samples:${PYTHONPATH}
pycodestyle --format=pylint samples
python3 -m pylint --rcfile=pylintrc samples
black samples
modified=$(git status -s | wc -l)
if [ $modified -gt 0 ]
then
echo "there are $modified files that must be reformatted"
exit 1
fi
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/__pycache__
build/
dist/
*egg-info/
.coverage
*,cover
*.xml
htmlcov/
.pylint.d/
.cache/
.eggs/
.task/
40 changes: 40 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Jitsuin observes the [CNCF Community Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md), reproduced below for emphasis.

### Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering
an open and welcoming community, we pledge to respect all people who contribute
through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age,
religion, or nationality.

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing others' private information, such as physical or electronic addresses,
without explicit permission
* Other unethical or unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are not
aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers
commit themselves to fairly and consistently applying these principles to every aspect
of managing this project. Project maintainers who do not follow or enforce the Code of
Conduct may be permanently removed from the project team.

This code of conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a Jitsuin administrator on <[email protected]>.

This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.2.0, available at
http://contributor-covenant.org/version/1/2/0/

38 changes: 38 additions & 0 deletions DCO
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

14 changes: 14 additions & 0 deletions Dockerfile-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG VERSION=3.6
FROM python:${VERSION}-buster

COPY requirements-api.txt /tmp/

RUN pip3 install -r /tmp/requirements-api.txt \
&& rm -f /tmp/requirements-api.txt

ENV USER=api
ENV HOME=/home/${USER}
RUN mkdir -p ${HOME}
ENV PYTHONPATH=${HOME}/samples:${PYTHONPATH}
ENV PATH=${HOME}/.local/bin:${PATH}
WORKDIR ${HOME}
146 changes: 145 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,146 @@
# archivist-samples
Sample python code that uses the archivist python SDK to manage particular types of assest such as 'doors', 'cards', 'containers etc.

Sample python code that uses the archivist python SDK to manage particular types of assets
such as 'doors', 'cards', 'containers etc.

# Pre-requisites

Required tools for this repo are task-runner and docker-ce.

- Install task runner: https://github.com/go-task/task
- Install docker-ce: https://docs.docker.com/get-docker/

# Running the samples code

Add a token to the file credentials/.auth_token and set some environment vars to
specify the archivist endpoint:

```bash
export TEST_ARCHIVIST=https://dev-paul-0-avid.scratch-6.dev.wild.jitsuin.io
export TEST_AUTHTOKEN=credentials/.auth_token
export TEST_NAMESPACE="unique label"
export TEST_VERBOSE=-v
```

If TEST_VERBOSE is "-v" debugging output will appear when running the tests.

## TEST_NAMESPACE

If TEST_NAMESPACE is blank or unspecified then each execution of 'task samples' will not be
independent. Any assets events, locations will be visible to other users running the same tests
on the same URL.

Each example test creates assets,events,locations that are not visible to other example tests.
For example the door_entry assets,events etc are not visible to the synsation example tests.

Assets and locations are only created if they do not already exist according to namespace.

Due to restrictions attachments are always uploaded during every test execution.

Events are created every execution of a test - currently no check is done if the event already exists.

A special value of TEST_NAMESPACE:

```bash
export TEST_NAMESPACE=date
```

will set the namespace to the result of `date +%s` i.e. no of seconds since epoch. This effectively makes
each test run independent of every other test run.

## TESTS

To see what tests are available specify the help option:

```bash
TEST_SELECTOR=help task samples

Available functional tests are:

TEST_SELECTOR=door_entry task samples
TEST_SELECTOR=estate_info task samples
TEST_SELECTOR=signed_records task samples
TEST_SELECTOR=synsation_initialise task samples
TEST_SELECTOR=synsation_analyze task samples
TEST_SELECTOR=synsation_charger task samples
TEST_SELECTOR=synsation_jitsuinator task samples
TEST_SELECTOR=synsation_wanderer task samples

To run more than one test use a comma-separated list:

TEST_SELECTOR=door_entry,estate_info task samples

To run all tests:

TEST_SELECTOR=all task samples
```

and follow the instructions.

For example:

```bash
TEST_SELECTOR=door_entry,estate_info task samples
TEST_SELECTOR=all task samples
```

Note that the synsation example tests all share the same NAMESPACE.

# Development

To see what options are available simply execute:

```bash
task
```

## Default python 3.6

Dependencies are defined in requirements-api.txt

To build the docker api image:
```bash
task api
```

Make a change to the code and validate the changes:

```bash
task check
```

## Python 3.7

To build the docker api image with Python 3.7:
```bash
task api-3.7
```

To check the style
```bash
task check
```

## Python 3.8

To build the docker api image with Python 3.8:
```bash
task api-3.8
```

To check the style
```bash
task check
```

## Python 3.9

To build the docker api image with Python 3.9:
```bash
task api-3.9
```

To check the style
```bash
task check
```
47 changes: 47 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3'

tasks:

api:
desc: Build a docker environment with the right dependencies and utilities
cmds:
- docker build --no-cache --build-arg 3.6 -f Dockerfile-api -t jitsuin-samples-api .

api-3.7:
desc: Build a docker environment with the right dependencies and utilities
cmds:
- docker build --no-cache --build-arg 3.7 -f Dockerfile-api -t jitsuin-samples-api .

api-3.8:
desc: Build a docker environment with the right dependencies and utilities
cmds:
- docker build --no-cache --build-arg 3.8 -f Dockerfile-api -t jitsuin-samples-api .

api-3.9:
desc: Build a docker environment with the right dependencies and utilities
cmds:
- docker build --no-cache --build-arg 3.9 -f Dockerfile-api -t jitsuin-samples-api .

check:
desc: Check the style, bug and quality of the code
cmds:
- ./scripts/api.sh python3 --version
- ./scripts/api.sh pycodestyle --format=pylint samples
- ./scripts/api.sh python3 -m pylint --rcfile=pylintrc samples

clean:
desc: Clean git repo
cmds:
- git clean -fdX

format:
desc: Format code using black
cmds:
- ./scripts/api.sh black samples

samples:
desc: Run samples tests
cmds:
- ./scripts/api.sh ./scripts/samples.sh


2 changes: 2 additions & 0 deletions credentials/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Loading

0 comments on commit a05000d

Please sign in to comment.