Skip to content

Commit

Permalink
Merge pull request #44 from uniqueg/upgrade-python
Browse files Browse the repository at this point in the history
Towards v0.5.0
  • Loading branch information
kellrott authored Feb 9, 2023
2 parents a9ac295 + 1abde51 commit a90cd3e
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 237 deletions.
1 change: 0 additions & 1 deletion .coverage

This file was deleted.

37 changes: 23 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
name: py-test_file

on: [ pull_request ]
on: [pull_request]

jobs:

test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- name: Check out code
uses: actions/checkout@v2
- name: Check out code
uses: actions/checkout@v3

- name: Requirements
run: pip install -r requirements.txt
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version }}

- name: Test Requirements
run: pip install -r tests/requirements.txt
- name: Install requirements
run: |
pip install -r requirements.txt
pip install -r tests/requirements.txt
- name: Install
run: python setup.py install --user
- name: Install app
run: pip install .

- name: Flake
run: flake8 .
- name: Lint with Flake8
run: flake8 .

- name: Test
run: python -m nose tests --with-coverage --cover-package tes --cover-min-percentage 80
- name: Run unit tests
run: coverage run --source tes -m pytest -W ignore::DeprecationWarning
177 changes: 176 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,180 @@ eggs/
\#*\#
.desktop

# Misc
test_tmp
*venv*
*venv*

# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# End of https://www.toptal.com/developers/gitignore/api/python
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

122 changes: 119 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ pip install py-tes

### Example

```
```python
import tes

# define task
task = tes.Task(
executors=[
tes.Executor(
Expand All @@ -30,8 +31,123 @@ task = tes.Task(
]
)

cli = tes.HTTPClient("http://funnel.example.com", timeout=5)
# create client
cli = tes.HTTPClient("https://funnel.example.com", timeout=5)

# access endpoints
service_info = cli.get_service_info()
task_id = cli.create_task(task)
res = cli.get_task(task_id)
task_info = cli.get_task(task_id, view="BASIC")
cli.cancel_task(task_id)
tasks_list = cli.list_tasks(view="MINIMAL") # default view
```

### How to...

> Makes use of the objects above...
#### ...export a model to a dictionary

```python
task_dict = task.as_dict(drop_empty=False)
```

`task_dict` contents:

```console
{'id': None, 'state': None, 'name': None, 'description': None, 'inputs': None, 'outputs': None, 'resources': None, 'executors': [{'image': 'alpine', 'command': ['echo', 'hello'], 'workdir': None, 'stdin': None, 'stdout': None, 'stderr': None, 'env': None}], 'volumes': None, 'tags': None, 'logs': None, 'creation_time': None}
```

#### ...export a model to JSON

```python
task_json = task.as_json() # also accepts `drop_empty` arg
```

`task_json` contents:

```console
{"executors": [{"image": "alpine", "command": ["echo", "hello"]}]}
```

#### ...pretty print a model

```python
print(task.as_json(indent=3)) # keyword args are passed to `json.dumps()`
```

Output:

```json
{
"executors": [
{
"image": "alpine",
"command": [
"echo",
"hello"
]
}
]
}
```

#### ...access a specific task from the task list

```python
specific_task = tasks_list.tasks[5]
```

`specific_task` contents:

```console
Task(id='393K43', state='COMPLETE', name=None, description=None, inputs=None, outputs=None, resources=None, executors=None, volumes=None, tags=None, logs=None, creation_time=None)
```

#### ...iterate over task list items

```python
for t in tasks_list[:3]:
print(t.as_json(indent=3))
```

Output:

```console
{
"id": "task_A2GFS4",
"state": "RUNNING"
}
{
"id": "task_O8G1PZ",
"state": "CANCELED"
}
{
"id": "task_W246I6",
"state": "COMPLETE"
}
```

#### ...instantiate a model from a JSON representation

```python
task_from_json = tes.client.unmarshal(task_json, tes.Task)
```

`task_from_json` contents:

```console
Task(id=None, state=None, name=None, description=None, inputs=None, outputs=None, resources=None, executors=[Executor(image='alpine', command=['echo', 'hello'], workdir=None, stdin=None, stdout=None, stderr=None, env=None)], volumes=None, tags=None, logs=None, creation_time=None)
```

Which is equivalent to `task`:

```python
print(task_from_json == task)
```

Output:

```console
True
```
Loading

0 comments on commit a90cd3e

Please sign in to comment.