diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..4c6bc56 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,45 @@ +name: Python Tests + +on: [push] + +jobs: + build: + defaults: + run: + working-directory: ./server + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + # You can test your matrix by printing the current Python version + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -r requirements.txt + - name: Install the code linting and formatting tool Ruff + run: pipx install ruff + - name: Lint code with Ruff + run: ruff check --output-format=github --target-version=${{ matrix.python-version }} + - name: Check code formatting with Ruff + run: ruff format --diff --target-version=${{ matrix.python-version }} + continue-on-error: true + - name: Install tox and any other packages + run: pip install tox + - name: Run tox + run: tox -e py + - name: Upload tox test results + uses: actions/upload-artifact@v4 + with: + name: pytest-results-${{ matrix.python-version }} + path: junit/test-results-${{ matrix.python-version }}.xml + # Use always() to always run this step to publish test results when there are test failures + if: ${{ always() }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a19790 --- /dev/null +++ b/.gitignore @@ -0,0 +1,174 @@ +# 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 + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.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/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# 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/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc diff --git a/README.md b/README.md index e772a82..7c0f312 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,39 @@ -# Wye Make Template +# Inventory -This repository is used as the base for all our other code. +An inventory platform for Wye Make. + +SnipeIT is overly complicated, Homebox doesn't have the features we need, so we're writing our own. + +## Goals + +This system has been written to adhere to the following goals: + +### 1. API-Driven + +If you're not a developer, this probably means nothing to you, but it enables us to talk to the system from just about anything else including our website, our membership system, Discord, and even Smart Assistants such as Amazon Alexa and Google Home. + +It means the system remains flexible and can be updated without worrying about how people access it. + +### 2. Tailored to our needs + +As a makerspace, we have a number of requirements that other systems either don't have or make overly complex. + +Whilst we will release the code "early and often", we will not release a version 1.0 until the following features are in place: + + - [ ] The ability to add and remove items + - [ ] The ability to add items to a specific location + - [ ] The ability to "nest" locations (i.e. "The hammer is in toolbox 01 which is stored in cupboard 9 in room 5 of the space") + - [ ] The ability to "loan" equipment to members + - [ ] The ability to track stock of consumables and who is using them + +### 3. Open Source + +The platform will use Open Source software. + +The backend will be written using the [Django](https://www.djangoproject.com/) framework and [Treebeard](https://django-treebeard.readthedocs.io/en/latest/tutorial.html) to deal with nested locations, the API is provided by the [Django Rest Framework (DRF)](https://www.django-rest-framework.org/). + +The platform is backed by the PostgreSQL database, and application performance is measured using the [Open Telemetry](https://opentelemetry.io) framework. + +The project itself is released under the [MIT Licence](https://choosealicense.com/licenses/mit/) and we hope that this will encourage anyone who uses the platform to donate their improvements back to the original code base. -## How do I use it? -Raise a PR against [the infrastructure repo](https://github.com/MakeMonmouth/wye-make-IaC) requesting a new git repository, and you'll get everything that's in here automatically! diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..fb27289 --- /dev/null +++ b/server/README.md @@ -0,0 +1,3 @@ +# Inventory Server + +This folder contains all of the source code for the server diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..db2ed80 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1 @@ +django-rest-framework diff --git a/server/tests/test_create_inventory_location.py b/server/tests/test_create_inventory_location.py new file mode 100644 index 0000000..36e9497 --- /dev/null +++ b/server/tests/test_create_inventory_location.py @@ -0,0 +1,9 @@ +# A dummy function to ensure github actions is working +def inc(x): + return x + 1 + +def test_positive(): + assert inc(3) == 4 + +def test_negative(): + assert inc(3) == 5 diff --git a/server/tox.ini b/server/tox.ini new file mode 100644 index 0000000..a75ec90 --- /dev/null +++ b/server/tox.ini @@ -0,0 +1,10 @@ +[tox] +requires = tox>=4 + +[testenv] +description = Run the unit tests +deps = + pytest>=8 + pytest-sugar +commands = + pytest {posargs:tests}