From 7c84447730350975e7df53b37f3feeceb720d039 Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Fri, 10 May 2024 17:04:12 +0200 Subject: [PATCH] global: initial commit --- .dockerignore | 15 + .editorconfig | 40 +++ .eslintrc.yml | 3 + .github/workflows/pypi-publish.yml | 38 +++ .github/workflows/tests.yml | 74 ++++ .gitignore | 65 ++++ .tx/config | 32 ++ AUTHORS.rst | 12 + CHANGES.rst | 12 + CONTRIBUTING.rst | 118 +++++++ INSTALL.rst | 8 + LICENSE | 21 ++ MANIFEST.in | 25 ++ README.rst | 26 ++ babel.ini | 22 ++ docs/Makefile | 192 +++++++++++ docs/api.rst | 18 + docs/authors.rst | 8 + docs/changes.rst | 8 + docs/conf.py | 320 ++++++++++++++++++ docs/configuration.rst | 12 + docs/contributing.rst | 8 + docs/index.rst | 46 +++ docs/installation.rst | 8 + docs/license.rst | 10 + docs/make.bat | 263 ++++++++++++++ docs/requirements.txt | 1 + docs/usage.rst | 11 + invenio_jobs/__init__.py | 14 + invenio_jobs/administration/__init__.py | 8 + invenio_jobs/administration/jobs.py | 101 ++++++ .../js/invenio_jobs/administration/index.js | 7 + invenio_jobs/config.py | 8 + invenio_jobs/ext.py | 53 +++ invenio_jobs/models.py | 81 +++++ invenio_jobs/resources/__init__.py | 16 + invenio_jobs/resources/config.py | 51 +++ invenio_jobs/resources/resources.py | 208 ++++++++++++ invenio_jobs/services/__init__.py | 18 + invenio_jobs/services/config.py | 61 ++++ invenio_jobs/services/links.py | 40 +++ invenio_jobs/services/permissions.py | 23 ++ invenio_jobs/services/schema.py | 39 +++ invenio_jobs/services/services.py | 33 ++ invenio_jobs/tasks.py | 16 + invenio_jobs/views.py | 22 ++ invenio_jobs/webpack.py | 32 ++ run-js-linter.sh | 32 ++ run-tests.sh | 31 ++ setup.cfg | 113 +++++++ setup.py | 12 + tests/conftest.py | 27 ++ tests/test_invenio_jobs.py | 32 ++ 53 files changed, 2494 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .eslintrc.yml create mode 100644 .github/workflows/pypi-publish.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 .tx/config create mode 100644 AUTHORS.rst create mode 100644 CHANGES.rst create mode 100644 CONTRIBUTING.rst create mode 100644 INSTALL.rst create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 README.rst create mode 100644 babel.ini create mode 100644 docs/Makefile create mode 100644 docs/api.rst create mode 100644 docs/authors.rst create mode 100644 docs/changes.rst create mode 100644 docs/conf.py create mode 100644 docs/configuration.rst create mode 100644 docs/contributing.rst create mode 100644 docs/index.rst create mode 100644 docs/installation.rst create mode 100644 docs/license.rst create mode 100644 docs/make.bat create mode 100644 docs/requirements.txt create mode 100644 docs/usage.rst create mode 100644 invenio_jobs/__init__.py create mode 100644 invenio_jobs/administration/__init__.py create mode 100644 invenio_jobs/administration/jobs.py create mode 100644 invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/index.js create mode 100644 invenio_jobs/config.py create mode 100644 invenio_jobs/ext.py create mode 100644 invenio_jobs/models.py create mode 100644 invenio_jobs/resources/__init__.py create mode 100644 invenio_jobs/resources/config.py create mode 100644 invenio_jobs/resources/resources.py create mode 100644 invenio_jobs/services/__init__.py create mode 100644 invenio_jobs/services/config.py create mode 100644 invenio_jobs/services/links.py create mode 100644 invenio_jobs/services/permissions.py create mode 100644 invenio_jobs/services/schema.py create mode 100644 invenio_jobs/services/services.py create mode 100644 invenio_jobs/tasks.py create mode 100644 invenio_jobs/views.py create mode 100644 invenio_jobs/webpack.py create mode 100755 run-js-linter.sh create mode 100755 run-tests.sh create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 tests/conftest.py create mode 100644 tests/test_invenio_jobs.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..231f82c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +*.gitignore + +*.mo +*.pyc +*.swp +*.swo +*.~ + +.dockerignore +Dockerfile +docker-compose.yml +docker-compose-dev.yml + +Procfile* diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1a6ff78 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +root = true + +[*] +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +# Python files +[*.py] +indent_size = 4 +# isort plugin configuration +known_first_party = invenio_jobs +multi_line_output = 2 +default_section = THIRDPARTY +skip = .eggs + +# RST files (used by sphinx) +[*.rst] +indent_size = 4 + +# CSS, HTML, JS, JSON, YML +[*.{css,html,js,json,yml}] +indent_size = 2 + +# Matches the exact files either package.json or .github/workflows/*.yml +[{package.json,.github/workflows/*.yml}] +indent_size = 2 + +# Dockerfile +[Dockerfile] +indent_size = 4 diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..6c0476f --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,3 @@ +extends: + - '@inveniosoftware/eslint-config-invenio' + - '@inveniosoftware/eslint-config-invenio/prettier' diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml new file mode 100644 index 0000000..68068ab --- /dev/null +++ b/.github/workflows/pypi-publish.yml @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + + +name: Publish + +on: + push: + tags: + - v* + +jobs: + build-n-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.7 + uses: actions/setup-python@v5 + with: + python-version: 3.7 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel babel + - name: Build package + run: | + python setup.py compile_catalog sdist bdist_wheel + - name: pypi-publish + uses: pypa/gh-action-pypi-publish@v1.3.1 + with: + user: __token__ + + password: ${{ secrets.pypi_token }} + diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..1930e7d --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + + +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + - "maint-**" + schedule: + # * is a special character in YAML so you have to quote this string + - cron: "0 3 * * 6" + workflow_dispatch: + inputs: + reason: + description: "Reason" + required: false + default: "Manual trigger" + +jobs: + Tests: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: ['3.9', '3.12'] + db-service: [postgresql14] + search-service: [opensearch2] + node-version: [18.x, 20.x] + include: + - search-service: opensearch2 + SEARCH_EXTRAS: "opensearch2" + + env: + DB: ${{ matrix.db-service }} + SEARCH: ${{ matrix.search-service }} + EXTRAS: tests,${{ matrix.search-service }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Run eslint test + run: ./run-js-linter.sh -i + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: setup.cfg + + - name: Install dependencies + run: | + pip install ".[$EXTRAS]" + pip freeze + docker --version + docker-compose --version + + - name: Run tests + run: ./run-tests.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad69498 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# Idea software family +.idea/ + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +Pipfile +Pipfile.lock +pyproject.toml + +# 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/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Vim swapfiles +.*.sw? diff --git a/.tx/config b/.tx/config new file mode 100644 index 0000000..7511330 --- /dev/null +++ b/.tx/config @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +# TODO: Transifex integration +# +# 1) Create message catalog: +# $ python setup.py extract_messages +# $ python setup.py init_catalog -l +# $ python setup.py compile_catalog +# 2) Ensure project has been created on Transifex under the inveniosoftware +# organisation. +# 3) Install the transifex-client +# $ pip install transifex-client +# 4) Push source (.pot) and translations (.po) to Transifex +# $ tx push -s -t +# 5) Pull translations for a single language from Transifex +# $ tx pull -l +# 6) Pull translations for all languages from Transifex +# $ tx pull -a + +[main] +host = https://www.transifex.com + +[invenio.invenio-jobs-messages] +file_filter = invenio_jobs/translations//LC_MESSAGES/messages.po +source_file = invenio_jobs/translations/messages.pot +source_lang = en +type = PO diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..91dddc1 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,12 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + +Authors +======= + +InvenioRDM module for jobs management + +- CERN diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 0000000..2de82f0 --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,12 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + +Changes +======= + +Version 0.1.0 (released TBD) + +- Initial public release. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..c37a17d --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,118 @@ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every +little bit helps, and credit will always be given. + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/inveniosoftware/invenio-jobs/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +Fix Bugs +~~~~~~~~ + +Look through the GitHub issues for bugs. Anything tagged with "bug" +is open to whoever wants to implement it. + +Implement Features +~~~~~~~~~~~~~~~~~~ + +Look through the GitHub issues for features. Anything tagged with "feature" +is open to whoever wants to implement it. + +Write Documentation +~~~~~~~~~~~~~~~~~~~ + +Invenio-Jobs could always use more documentation, whether as part of the +official Invenio-Jobs docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Submit Feedback +~~~~~~~~~~~~~~~ + +The best way to send feedback is to file an issue at +https://github.com/inveniosoftware/invenio-jobs/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +Get Started! +------------ + +Ready to contribute? Here's how to set up `invenio-jobs` for local development. + +1. Fork the `inveniosoftware/invenio-jobs` repo on GitHub. +2. Clone your fork locally: + + .. code-block:: console + + $ git clone git@github.com:your_name_here/invenio-jobs.git + +3. Install your local copy into a virtualenv. Assuming you have + virtualenvwrapper installed, this is how you set up your fork for local + development: + + .. code-block:: console + + $ mkvirtualenv invenio-jobs + $ cd invenio-jobs/ + $ pip install -e .[all] + +4. Create a branch for local development: + + .. code-block:: console + + $ git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass tests: + + .. code-block:: console + + $ ./run-tests.sh + + The tests will provide you with test coverage and also check PEP8 + (code style), PEP257 (documentation), flake8 as well as build the Sphinx + documentation and run doctests. + +6. Commit your changes and push your branch to GitHub: + + .. code-block:: console + + $ git add . + $ git commit -s + -m "component: title without verbs" + -m "* NEW Adds your new feature." + -m "* FIX Fixes an existing issue." + -m "* BETTER Improves and existing feature." + -m "* Changes something that should not be visible in release notes." + $ git push origin name-of-your-bugfix-or-feature + +7. Submit a pull request through the GitHub website. + +Pull Request Guidelines +----------------------- + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests and must not decrease test coverage. +2. If the pull request adds functionality, the docs should be updated. Put + your new functionality into a function with a docstring. +3. The pull request should work for Python 3.6, 3.7, 3.8 and 3.9. Check + https://github.com/inveniosoftware/inveniosoftware/invenio-jobs/actions?query=event%3Apull_request + and make sure that the tests pass for all supported Python versions. diff --git a/INSTALL.rst b/INSTALL.rst new file mode 100644 index 0000000..27e6c8e --- /dev/null +++ b/INSTALL.rst @@ -0,0 +1,8 @@ +Installation +============ + +Invenio-Jobs is on PyPI so all you need is: + +.. code-block:: console + + $ pip install invenio-jobs diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..772bfb8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (C) 2024 CERN. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..2bf49f4 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +include .dockerignore +include .editorconfig +include .tx/config +include *.rst +include *.sh +include *.yml +include babel.ini +prune docs/_build +recursive-include .github/workflows *.yml +recursive-include docs *.bat +recursive-include docs *.py +recursive-include docs *.rst +recursive-include docs *.txt +recursive-include docs Makefile +recursive-include invenio_jobs *.html +recursive-include invenio_jobs *.js +recursive-include invenio_jobs/translations *.po *.pot *.mo +recursive-include tests *.py diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..766822b --- /dev/null +++ b/README.rst @@ -0,0 +1,26 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + +============== + Invenio-Jobs +============== + +.. image:: https://github.com/inveniosoftware/invenio-jobs/workflows/CI/badge.svg + :target: https://github.com/inveniosoftware/invenio-jobs/actions?query=workflow%3ACI + +.. image:: https://img.shields.io/github/tag/inveniosoftware/invenio-jobs.svg + :target: https://github.com/inveniosoftware/invenio-jobs/releases + +.. image:: https://img.shields.io/pypi/dm/invenio-jobs.svg + :target: https://pypi.python.org/pypi/invenio-jobs + +.. image:: https://img.shields.io/github/license/inveniosoftware/invenio-jobs.svg + :target: https://github.com/inveniosoftware/invenio-jobs/blob/master/LICENSE + +InvenioRDM module for jobs management + +Further documentation is available on +https://invenio-jobs.readthedocs.io/ diff --git a/babel.ini b/babel.ini new file mode 100644 index 0000000..8f5aa3e --- /dev/null +++ b/babel.ini @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +# Extraction from Python source files + +[python: **.py] +encoding = utf-8 + +# Extraction from Jinja2 templates + +[jinja2: **/templates/**.html] +encoding = utf-8 + +# Extraction from JavaScript files + +[javascript: **.js] +encoding = utf-8 +extract_messages = $._, jQuery._ diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..168f0a8 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,192 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Invenio-Jobs.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Invenio-Jobs.qhc" + +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/Invenio-Jobs" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Invenio-Jobs" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/api.rst b/docs/api.rst new file mode 100644 index 0000000..aa5c736 --- /dev/null +++ b/docs/api.rst @@ -0,0 +1,18 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +API Docs +======== + +.. automodule:: invenio_jobs.ext + :members: + +Views +----- + +.. automodule:: invenio_jobs.views + :members: diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 0000000..fe32dad --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1,8 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +.. include:: ../AUTHORS.rst diff --git a/docs/changes.rst b/docs/changes.rst new file mode 100644 index 0000000..10a20c9 --- /dev/null +++ b/docs/changes.rst @@ -0,0 +1,8 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +.. include:: ../CHANGES.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..6a90b8b --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,320 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Sphinx configuration.""" + +from invenio_jobs import __version__ + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# needs_sphinx = "1.0" + +# Do not warn on external images. +suppress_warnings = ["image.nonlocal_uri"] + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named "sphinx.ext.*") or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = [".rst", ".md"] +source_suffix = ".rst" + +# The encoding of source files. +# source_encoding = "utf-8-sig" + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = "Invenio-Jobs" +copyright = "2024, CERN" +author = "CERN" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. + +# The full version, including alpha/beta/rc tags. +release = __version__ + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = "en" + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = "" +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = "%B %d, %Y" + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, "()" will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + +# -- Options for HTML output ---------------------------------------------- +html_theme = "alabaster" + +html_theme_options = { + "description": "InvenioRDM module for jobs management", + "github_user": "inveniosoftware", + "github_repo": "invenio-jobs", + "github_button": False, + "github_banner": True, + "show_powered_by": False, + "extra_nav_links": { + "invenio-jobs@GitHub": ("https://github.com/inveniosoftware/invenio-jobs"), + "invenio-jobs@PyPI": ("https://pypi.python.org/pypi/invenio-jobs/"), + }, +} + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not "", a "Last updated on:" timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = "%b %d, %Y" + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +html_sidebars = { + "**": [ + "about.html", + "navigation.html", + "relations.html", + "searchbox.html", + "donate.html", + ] +} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = "" + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# "da", "de", "en", "es", "fi", "fr", "hu", "it", "ja" +# "nl", "no", "pt", "ro", "ru", "sv", "tr" +# html_search_language = "en" + +# A dictionary with options for the search language support, empty by default. +# Now only "ja" uses this config value +# html_search_options = {"type": "default"} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = "scorer.js" + +# Output file base name for HTML help builder. +htmlhelp_basename = "invenio-jobs_namedoc" + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ("letterpaper" or "a4paper"). + # "papersize": "letterpaper", + # The font size ("10pt", "11pt" or "12pt"). + # "pointsize": "10pt", + # Additional stuff for the LaTeX preamble. + # "preamble": "", + # Latex figure (float) alignment + # "figure_align": "htbp", +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + master_doc, + "invenio-jobs.tex", + "invenio-jobs Documentation", + "CERN", + "manual", + ), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + master_doc, + "invenio-jobs", + "invenio-jobs Documentation", + [author], + 1, + ), +] + +# If true, show URL addresses after external links. +# man_show_urls = False + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "invenio-jobs", + "Invenio-Jobs Documentation", + author, + "invenio-jobs", + "InvenioRDM module for jobs management", + "Miscellaneous", + ), +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: "footnote", "no", or "inline". +# texinfo_show_urls = "footnote" + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("https://docs.python.org/", None), +} + +# Autodoc configuraton. +autoclass_content = "both" diff --git a/docs/configuration.rst b/docs/configuration.rst new file mode 100644 index 0000000..403a3d8 --- /dev/null +++ b/docs/configuration.rst @@ -0,0 +1,12 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +Configuration +============= + +.. automodule:: invenio_jobs.config + :members: diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 0000000..7e38bd2 --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1,8 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +.. include:: ../CONTRIBUTING.rst diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..4dcba9f --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,46 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +.. include:: ../README.rst + +User's Guide +------------ + +This part of the documentation will show you how to get started in using +Invenio-Jobs. + +.. toctree:: + :maxdepth: 2 + + installation + configuration + usage + +API Reference +------------- + +If you are looking for information on a specific function, class or method, +this part of the documentation is for you. + +.. toctree:: + :maxdepth: 2 + + api + +Additional Notes +---------------- + +Notes on how to contribute, legal information and changes are here for the +interested. + +.. toctree:: + :maxdepth: 1 + + contributing + changes + license + authors diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..e5e5517 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,8 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +.. include:: ../INSTALL.rst diff --git a/docs/license.rst b/docs/license.rst new file mode 100644 index 0000000..a17c4d4 --- /dev/null +++ b/docs/license.rst @@ -0,0 +1,10 @@ +License +======= + +.. include:: ../LICENSE + +.. note:: + In applying this license, CERN does not waive the privileges and immunities + granted to it by virtue of its status as an Intergovernmental Organization or + submit itself to any jurisdiction. + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..bb0ac22 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,263 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +REM Check if sphinx-build is available and fallback to Python version if any +%SPHINXBUILD% 2> nul +if errorlevel 9009 goto sphinx_python +goto sphinx_ok + +:sphinx_python + +set SPHINXBUILD=python -m sphinx.__init__ +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +:sphinx_ok + + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Invenio-Jobs.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Invenio-Jobs.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "coverage" ( + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ +results in %BUILDDIR%/coverage/python.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..c037791 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1 @@ +-e .[docs,tests] diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 0000000..33fd060 --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,11 @@ +.. + Copyright (C) 2024 CERN. + + Invenio-Jobs is free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. + + +Usage +===== + +.. automodule:: invenio_jobs diff --git a/invenio_jobs/__init__.py b/invenio_jobs/__init__.py new file mode 100644 index 0000000..e9352f4 --- /dev/null +++ b/invenio_jobs/__init__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""InvenioRDM module for jobs management.""" + +from .ext import InvenioJobs + +__version__ = "0.1.0" + +__all__ = ("__version__", "InvenioJobs") diff --git a/invenio_jobs/administration/__init__.py b/invenio_jobs/administration/__init__.py new file mode 100644 index 0000000..c21c04a --- /dev/null +++ b/invenio_jobs/administration/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Administration views for jobs.""" diff --git a/invenio_jobs/administration/jobs.py b/invenio_jobs/administration/jobs.py new file mode 100644 index 0000000..c4279db --- /dev/null +++ b/invenio_jobs/administration/jobs.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or +# modify it under the terms of the MIT License; see LICENSE file for more +# details. + +"""Invenio administration view module.""" + +from functools import partial + +from flask import current_app +from invenio_administration.views.base import ( + AdminResourceDetailView, + AdminResourceListView, +) +from invenio_search_ui.searchconfig import search_app_config + + +class JobListView(AdminResourceListView): + """Search admin view for jobs.""" + + api_endpoint = "/jobs" + name = "jobs" + resource_config = "jobs_resource" + search_request_headers = {"Accept": "application/vnd.inveniordm.v1+json"} + title = "Jobs" + menu_label = "Jobs" + category = "System" + pid_path = "id" + icon = "cogs" + template = "invenio_administration/search.html" + + display_search = True + display_delete = False + display_create = True + display_edit = True + + item_field_list = { + "title": {"text": "Title", "order": 1, "width": 4}, + } + + actions = { + # TODO: Define actions + # "delete": { + # "text": "Delete", + # "payload_schema": None, + # "order": 2, + # }, + } + # TODO: Define search config for jobs + # search_config_name = "JOBS_SEARCH" + # search_facets_config_name = "JOBS_FACETS" + # search_sort_config_name = "JOBS_SORT_OPTIONS" + + # def init_search_config(self): + # """Build search view config.""" + # return partial( + # search_app_config, + # config_name=self.get_search_app_name(), + # available_facets=current_app.config.get(self.search_facets_config_name), + # sort_options=current_app.config[self.search_sort_config_name], + # endpoint=self.get_api_endpoint(), + # headers=self.get_search_request_headers(), + # initial_filters=[["status", "P"]], + # hidden_params=[ + # ["include_deleted", "1"], + # ], + # page=1, + # size=30, + # ) + + @staticmethod + def disabled(): + """Disable the view on demand.""" + return current_app.config["JOBS_ADMINISTRATION_DISABLED"] + + +class JobDetailView(AdminResourceDetailView): + """Admin job detail view.""" + + url = "/jobs/" + api_endpoint = "/jobs" + name = "job-details" + resource_config = "JOBS_resource" + title = "Job" + + template = "invenio_administration/details.html" + display_delete = True + display_edit = True + + list_view_name = "jobs" + pid_path = "id" + request_headers = {"Accept": "application/vnd.inveniordm.v1+json"} + + actions = {} + + item_field_list = { + "title": {"text": "Title", "order": 1}, + } diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/index.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/index.js new file mode 100644 index 0000000..8d9db34 --- /dev/null +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/index.js @@ -0,0 +1,7 @@ +// This file is part of InvenioCommunities +// Copyright (C) 2022 CERN. +// +// Invenio-Jobs is free software; you can redistribute it and/or modify it +// under the terms of the MIT License; see LICENSE file for more details. + +console.log("jobs administration"); diff --git a/invenio_jobs/config.py b/invenio_jobs/config.py new file mode 100644 index 0000000..f63408c --- /dev/null +++ b/invenio_jobs/config.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Configuration.""" diff --git a/invenio_jobs/ext.py b/invenio_jobs/ext.py new file mode 100644 index 0000000..b174dee --- /dev/null +++ b/invenio_jobs/ext.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Jobs extension.""" + +from invenio_i18n import gettext as _ + +from . import config +from .resources import JobResource, JobResourceConfig +from .services import JobService, JobServiceConfig + + +class InvenioJobs: + """Invenio-Jobs extension.""" + + def __init__(self, app=None): + """Extension initialization.""" + if app: + self.init_app(app) + + def init_app(self, app): + """Flask application initialization.""" + self.init_config(app) + self.init_services(app) + self.init_resource(app) + app.extensions["invenio-jobs"] = self + + def init_config(self, app): + """Initialize configuration.""" + for k in dir(config): + if k.startswith("JOBS_"): + app.config.setdefault(k, getattr(config, k)) + + def init_services(self, app): + """Initialize services.""" + self.service = JobService(JobServiceConfig.build(app)) + + def init_resource(self, app): + """Initialize resources.""" + self.jobs_resource = JobResource(JobResourceConfig.build(app), self.service) + + +def finalize_app(app): + """Finalize app.""" + rr_ext = app.extensions["invenio-records-resources"] + ext = app.extensions["invenio-jobs"] + + # services + rr_ext.registry.register(ext.service, service_id="jobs") diff --git a/invenio_jobs/models.py b/invenio_jobs/models.py new file mode 100644 index 0000000..5fbec8e --- /dev/null +++ b/invenio_jobs/models.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Models.""" + +import enum + +from invenio_accounts.models import User +from invenio_db import db +from sqlalchemy.dialects import postgresql +from sqlalchemy_utils import Timestamp +from sqlalchemy_utils.types import ChoiceType, JSONType, UUIDType + +JSON = ( + db.JSON() + .with_variant(postgresql.JSONB(none_as_null=True), "postgresql") + .with_variant(JSONType(), "sqlite") + .with_variant(JSONType(), "mysql") +) + + +class Job(db.Model, Timestamp): + """Job model.""" + + id = db.Column(UUIDType, primary_key=True) + active = db.Column(db.Boolean, default=True, nullable=False) + title = db.Column(db.String(255), nullable=False) + description = db.Column(db.Text) + + celery_tasks = db.Column(db.String(255)) + default_queue = db.Column(db.String(64)) + default_args = db.Column(JSON, default=lambda: dict(), nullable=True) + schedule = db.Column(JSON, default=lambda: dict(), nullable=True) + + # TODO: See if we move this to an API class + @property + def last_run(self): + """Last run of the job.""" + return self.runs.order_by(Run.created.desc()).first() + + +class RunStatusEnum(enum.Enum): + """Enumeration of a run's possible states.""" + + PENDING = "P" + RUNNING = "R" + SUCCESS = "S" + FAILURE = "F" + WARNING = "W" + CANCELLED = "C" + + +class Run(db.Model, Timestamp): + """Run model.""" + + id = db.Column(UUIDType, primary_key=True) + + job_id = db.Column(UUIDType, db.ForeignKey(Job.id)) + job = db.relationship(Job, backref=db.backref("runs", lazy="dynamic")) + + started_by_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=True) + started_by = db.relationship(User) + + started_at = db.Column(db.DateTime, nullable=True) + finished_at = db.Column(db.DateTime, nullable=False) + + status = db.Column( + ChoiceType(RunStatusEnum, impl=db.String(1)), + nullable=False, + default=RunStatusEnum.PENDING.value, + ) + + message = db.Column(db.Text, nullable=True) + + task_id = db.Column(UUIDType, nullable=True) + args = db.Column(JSON, default=lambda: dict(), nullable=True) + queue = db.Column(db.String(64), nullable=True) diff --git a/invenio_jobs/resources/__init__.py b/invenio_jobs/resources/__init__.py new file mode 100644 index 0000000..52cc69a --- /dev/null +++ b/invenio_jobs/resources/__init__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Jobs resources.""" + +from .config import JobResourceConfig +from .resources import JobResource + +__all__ = ( + "JobResource", + "JobResourceConfig", +) diff --git a/invenio_jobs/resources/config.py b/invenio_jobs/resources/config.py new file mode 100644 index 0000000..c648ab9 --- /dev/null +++ b/invenio_jobs/resources/config.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Resources config.""" + +import marshmallow as ma +from flask_resources import HTTPJSONException, ResourceConfig, create_error_handler +from invenio_records_resources.resources.errors import ErrorHandlersMixin +from invenio_records_resources.resources.records.args import SearchRequestArgsSchema +from invenio_records_resources.services.base.config import ConfiguratorMixin + + +class TasksResourceConfig(ResourceConfig, ConfiguratorMixin): + """Celery tasks resource config.""" + + # Blueprint configuration + blueprint_name = "tasks" + url_prefix = "/tasks" + routes = {"list": ""} + + +class JobSearchRequestArgsSchema(SearchRequestArgsSchema): + """Jobs search request parameters.""" + + active = ma.fields.Boolean() + + +class JobResourceConfig(ResourceConfig, ConfiguratorMixin): + """Jobs resource config.""" + + # Blueprint configuration + blueprint_name = "jobs" + url_prefix = "/jobs" + routes = { + "list": "", + "item": "/", + } + + # Request parsing + request_read_args = {} + request_view_args = {"id": ma.fields.Int()} + request_search_args = JobSearchRequestArgsSchema + + error_handlers = { + **ErrorHandlersMixin.error_handlers, + # TODO: Add custom error handlers here + } diff --git a/invenio_jobs/resources/resources.py b/invenio_jobs/resources/resources.py new file mode 100644 index 0000000..7d96765 --- /dev/null +++ b/invenio_jobs/resources/resources.py @@ -0,0 +1,208 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Resources definitions.""" + +from flask import g +from flask_resources import Resource, resource_requestctx, response_handler, route +from invenio_records_resources.resources.errors import ErrorHandlersMixin +from invenio_records_resources.resources.records.resource import ( + request_data, + request_headers, + request_search_args, + request_view_args, +) + + +class TasksResource(ErrorHandlersMixin, Resource): + """Tasks resource.""" + + def __init__(self, config, service): + """Constructor.""" + super().__init__(config) + self.service = service + + def create_url_rules(self): + """Create the URL rules for the OAI-PMH server resource.""" + routes = self.config.routes + url_rules = [ + route("GET", routes["list"], self.search), + ] + + return url_rules + + # + # Primary Interface + # + @request_search_args + @response_handler(many=True) + def search(self): + """Perform a search.""" + identity = g.identity + hits = self.service.search( + identity=identity, + params=resource_requestctx.args, + ) + return hits.to_dict(), 200 + + +class JobResource(ErrorHandlersMixin, Resource): + """Jobs resource.""" + + def __init__(self, config, service): + """Constructor.""" + super().__init__(config) + self.service = service + + def create_url_rules(self): + """Create the URL rules for the OAI-PMH server resource.""" + routes = self.config.routes + url_rules = [ + route("GET", routes["list"], self.search), + route("POST", routes["list"], self.create), + route("GET", routes["item"], self.read), + route("PUT", routes["item"], self.update), + route("DELETE", routes["item"], self.delete), + ] + + return url_rules + + # + # Primary Interface + # + @request_search_args + @response_handler(many=True) + def search(self): + """Perform a search.""" + identity = g.identity + hits = self.service.search( + identity=identity, + params=resource_requestctx.args, + ) + return hits.to_dict(), 200 + + @request_data + @response_handler() + def create(self): + """Create an item.""" + item = self.service.create( + g.identity, + resource_requestctx.data or {}, + ) + return item.to_dict(), 201 + + @request_view_args + @response_handler() + def read(self): + """Read an item.""" + item = self.service.read( + g.identity, + resource_requestctx.view_args["id"], + ) + return item.to_dict(), 200 + + @request_headers + @request_view_args + @request_data + @response_handler() + def update(self): + """Update an item.""" + item = self.service.update( + g.identity, + resource_requestctx.view_args["id"], + resource_requestctx.data, + ) + return item.to_dict(), 200 + + @request_headers + @request_view_args + def delete(self): + """Delete an item.""" + self.service.delete( + g.identity, + resource_requestctx.view_args["id"], + ) + return "", 204 + + +class RunsResource(ErrorHandlersMixin, Resource): + """Runs resource.""" + + def __init__(self, config, service): + """Constructor.""" + super().__init__(config) + self.service = service + + def create_url_rules(self): + """Create the URL rules for the OAI-PMH server resource.""" + routes = self.config.routes + url_rules = [ + route("GET", routes["list"], self.search), + route("POST", routes["list"], self.create), + route("GET", routes["item"], self.read), + route("PUT", routes["item"], self.update), + route("DELETE", routes["item"], self.delete), + ] + + return url_rules + + # + # Primary Interface + # + @request_search_args + @response_handler(many=True) + def search(self): + """Perform a search.""" + identity = g.identity + hits = self.service.search( + identity=identity, + params=resource_requestctx.args, + ) + return hits.to_dict(), 200 + + @request_data + @response_handler() + def create(self): + """Create an item.""" + item = self.service.create( + g.identity, + resource_requestctx.data or {}, + ) + return item.to_dict(), 201 + + @request_view_args + @response_handler() + def read(self): + """Read an item.""" + item = self.service.read( + g.identity, + resource_requestctx.view_args["id"], + ) + return item.to_dict(), 200 + + @request_headers + @request_view_args + @request_data + @response_handler() + def update(self): + """Update an item.""" + item = self.service.update( + g.identity, + resource_requestctx.view_args["id"], + resource_requestctx.data, + ) + return item.to_dict(), 200 + + @request_headers + @request_view_args + def delete(self): + """Delete an item.""" + self.service.delete( + g.identity, + resource_requestctx.view_args["id"], + ) + return "", 204 diff --git a/invenio_jobs/services/__init__.py b/invenio_jobs/services/__init__.py new file mode 100644 index 0000000..7eeac32 --- /dev/null +++ b/invenio_jobs/services/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Services.""" + +from .config import JobServiceConfig +from .schema import JobSchema +from .services import JobService + +__all__ = ( + "JobSchema", + "JobService", + "JobServiceConfig", +) diff --git a/invenio_jobs/services/config.py b/invenio_jobs/services/config.py new file mode 100644 index 0000000..6e6d906 --- /dev/null +++ b/invenio_jobs/services/config.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Services config.""" + +from invenio_i18n import gettext as _ +from invenio_records_resources.services.base import ServiceConfig +from invenio_records_resources.services.base.config import ConfiguratorMixin +from invenio_records_resources.services.records.config import ( + SearchOptions as SearchOptionsBase, +) +from invenio_records_resources.services.records.links import pagination_links +from invenio_records_resources.services.records.results import RecordItem, RecordList + +from ..models import Job, Run +from .links import JobLink +from .permissions import JobPermissionPolicy +from .schema import JobSchema + + +class JobSearchOptions(SearchOptionsBase): + """Job search options.""" + + # TODO: See what we need to override + + +class JobServiceConfig(ServiceConfig, ConfiguratorMixin): + """Service factory configuration.""" + + # Common configuration + service_id = "jobs" + permission_policy_cls = JobPermissionPolicy + + # TODO: See if we need to define custom Job result item and list classes + result_item_cls = RecordItem + result_list_cls = RecordList + + # Record specific configuration + record_cls = Job + + # TODO: See if these are needed since we don't index jobs + # indexer_cls = None + # indexer_queue_name = None + # index_dumper = None + + # Search configuration + search = JobSearchOptions + + # Service schema + schema = JobSchema + + links_item = { + "self": JobLink("{+api}/jobs/{id}"), + "runs": JobLink("{+api}/jobs/{id}/runs"), + } + + links_search = pagination_links("{+api}/jobs{?args*}") diff --git a/invenio_jobs/services/links.py b/invenio_jobs/services/links.py new file mode 100644 index 0000000..c8cecf8 --- /dev/null +++ b/invenio_jobs/services/links.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service links.""" + +from invenio_records_resources.services.base import Link + + +class JobLink(Link): + """Short cut for writing record links.""" + + @staticmethod + def vars(record, vars): + """Variables for the URI template.""" + vars.update({"id": str(record.id)}) + + +def pagination_links(tpl): + """Create pagination links (prev/selv/next) from the same template.""" + return { + "prev": Link( + tpl, + when=lambda pagination, ctx: pagination.has_prev, + vars=lambda pagination, vars: vars["args"].update( + {"page": pagination.prev_page.page} + ), + ), + "self": Link(tpl), + "next": Link( + tpl, + when=lambda pagination, ctx: pagination.has_next, + vars=lambda pagination, vars: vars["args"].update( + {"page": pagination.next_page.page} + ), + ), + } diff --git a/invenio_jobs/services/permissions.py b/invenio_jobs/services/permissions.py new file mode 100644 index 0000000..6c258f1 --- /dev/null +++ b/invenio_jobs/services/permissions.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service permissions.""" + +from invenio_administration.generators import Administration +from invenio_records_permissions.policies import BasePermissionPolicy + + +class JobPermissionPolicy(BasePermissionPolicy): + """Access control configuration for jobs.""" + + can_search = [Administration()] + can_create = [Administration()] + can_read = [Administration()] + can_update = [Administration()] + can_delete = [Administration()] + + # TODO: Should run permissions reuse the above or we make a new class? diff --git a/invenio_jobs/services/schema.py b/invenio_jobs/services/schema.py new file mode 100644 index 0000000..b77be58 --- /dev/null +++ b/invenio_jobs/services/schema.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service schemas.""" + +from invenio_i18n import lazy_gettext as _ +from marshmallow import EXCLUDE, Schema, fields, validate +from marshmallow_utils.fields import SanitizedUnicode +from marshmallow_utils.permissions import FieldPermissionsMixin + + +def _not_blank(**kwargs): + """Returns a non-blank validation rule.""" + max_ = kwargs.get("max", "") + return validate.Length( + error=_( + "Field cannot be blank or longer than {max_} characters.".format(max_=max_) + ), + min=1, + **kwargs, + ) + + +class JobSchema(Schema, FieldPermissionsMixin): + """Base schema for a job.""" + + class Meta: + """Meta attributes for the schema.""" + + unknown = EXCLUDE + + id = fields.UUID(dump_only=True) + + title = SanitizedUnicode(required=True, validate=_not_blank(max=250)) + description = SanitizedUnicode() diff --git a/invenio_jobs/services/services.py b/invenio_jobs/services/services.py new file mode 100644 index 0000000..9257899 --- /dev/null +++ b/invenio_jobs/services/services.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service definitions.""" + +from invenio_records_resources.services.records import RecordService +from invenio_records_resources.services.uow import unit_of_work + + +class JobService(RecordService): + """Jobs service.""" + + def search(self, identity, **kwargs): + """Search for jobs.""" + raise NotImplementedError() + + def read(self, identity, id_): + """Retrieve a job.""" + raise NotImplementedError() + + @unit_of_work() + def update(self, identity, id_, data, uow=None): + """Update a job.""" + raise NotImplementedError() + + @unit_of_work() + def delete(self, identity, id_, uow=None): + """Delete a job.""" + raise NotImplementedError() diff --git a/invenio_jobs/tasks.py b/invenio_jobs/tasks.py new file mode 100644 index 0000000..aed98ed --- /dev/null +++ b/invenio_jobs/tasks.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Tasks.""" + +from celery import shared_task + + +@shared_task(ignore_result=True) +def run_job(job_id, args=None): + """Run a job.""" + pass diff --git a/invenio_jobs/views.py b/invenio_jobs/views.py new file mode 100644 index 0000000..4944496 --- /dev/null +++ b/invenio_jobs/views.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""InvenioRDM module for jobs management.""" + +from flask import Blueprint + +blueprint = Blueprint( + "invenio_jobs", + __name__, + template_folder="templates", +) + + +def create_jobs_bp(app): + """Create jobs blueprint.""" + ext = app.extensions["invenio-jobs"] + return ext.jobs_resource.as_blueprint() diff --git a/invenio_jobs/webpack.py b/invenio_jobs/webpack.py new file mode 100644 index 0000000..e5a4b44 --- /dev/null +++ b/invenio_jobs/webpack.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""JS/CSS Webpack bundles for jobs.""" + +from invenio_assets.webpack import WebpackThemeBundle + +administration = WebpackThemeBundle( + __name__, + "assets", + default="semantic-ui", + themes={ + "semantic-ui": dict( + entry={ + "invenio-jobs-administration": "./js/invenio_jobs/administration/index.js", + }, + dependencies={ + "react-invenio-forms": "^3.0.0", + "react-searchkit": "^2.0.0", + }, + aliases={ + "@less/invenio_jobs": "less/invenio_jobs", + "@js/invenio_jobs": "js/invenio_jobs", + "@translations/invenio_jobs": "translations/invenio_jobs", + }, + ), + }, +) diff --git a/run-js-linter.sh b/run-js-linter.sh new file mode 100755 index 0000000..2971aaa --- /dev/null +++ b/run-js-linter.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +# Usage: +# ./run-js-linter.sh [args] + +# Arguments +# -i|--install: installs eslint-config-invenio +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +for arg in $@; do + case ${arg} in + -i|--install) + npm install --no-save --no-package-lock @inveniosoftware/eslint-config-invenio@^2.0.0;; + -f|--fix) + printf "${GREEN}Run eslint${NC}\n"; + npx eslint -c .eslintrc.yml invenio_jobs/**/*.js --fix;; + *) + printf "Argument ${RED}$arg${NC} not supported\n" + exit;; + esac +done + +printf "${GREEN}Run eslint${NC}\n" +npx eslint -c .eslintrc.yml invenio_jobs/**/*.js diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..c5ac215 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + + +# Usage: +# env DB=postgresql12 SEARCH=elasticsearch7 CACHE=redis MQ=rabbitmq ./run-tests.sh + +# Quit on errors +set -o errexit + +# Quit on unbound symbols +set -o nounset + +# Always bring down docker services +function cleanup() { + eval "$(docker-services-cli down --env)" +} +trap cleanup EXIT + +python -m check_manifest +python -m sphinx.cmd.build -qnNW docs docs/_build/html +eval "$(docker-services-cli up --db ${DB:-postgresql} --search ${SEARCH:-elasticsearch} --cache ${CACHE:-redis} --mq ${MQ:-rabbitmq} --env)" +python -m pytest +tests_exit_code=$? +python -m sphinx.cmd.build -qnNW -b doctest docs docs/_build/doctest +exit "$tests_exit_code" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2ba5bb6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + + +[metadata] +name = invenio-jobs +version = attr: invenio_jobs.__version__ +description = InvenioRDM module for jobs management +long_description = file: README.rst, CHANGES.rst +keywords = invenio rdm celery jobs +license = MIT +author = CERN +author_email = info@inveniosoftware.org +platforms = any +url = https://github.com/inveniosoftware/invenio-jobs +classifiers = + Development Status :: 3 - Alpha + +[options] +include_package_data = True +packages = find: +python_requires = >=3.7 +zip_safe = False +install_requires = + invenio-administration>=2.0.0,<3.0.0 + invenio-base>=1.3.0,<2.0.0 + invenio-celery>=1.2.4,<2.0.0 + invenio-i18n>=2.0.0,<3.0.0 + invenio-records-resources>=5.0.0,<6.0.0 + +[options.extras_require] +tests = + invenio-app>=1.4.0,<2.0.0 + invenio-db[postgresql,mysql]>=1.1.0,<2.0.0 + pytest-invenio>=2.1.0,<3.0.0 + pytest-black-ng>=0.4.0 + sphinx>=4.5.0 +elasticsearch7 = + invenio-search[elasticsearch7]>=2.1.0,<3.0.0 +opensearch1 = + invenio-search[opensearch1]>=2.1.0,<3.0.0 +opensearch2 = + invenio-search[opensearch2]>=2.1.0,<3.0.0 + +[options.entry_points] +invenio_base.apps = + jobs = invenio_jobs:InvenioJobs +invenio_base.blueprints = + jobs = invenio_jobs.views:blueprint +invenio_i18n.translations = + messages = invenio_jobs +invenio_db.models = + jobs = invenio_jobs.records.models +invenio_assets.webpack = + jobs = invenio_jobs.webpack:administration +invenio_administration.views = + jobs_list = invenio_jobs.administration.jobs:JobListView + jobs_details = invenio_jobs.administration.jobs:JobDetailView +invenio_base.api_apps = + jobs = invenio_jobs:InvenioJobs +invenio_base.api_blueprints = + jobs = invenio_jobs.views:create_jobs_bp +invenio_base.finalize_app = + jobs = invenio_jobs.ext:finalize_app +invenio_base.api_finalize_app = + jobs = invenio_jobs.ext:finalize_app +invenio_celery.tasks = + jobs = invenio_jobs.tasks + +[build_sphinx] +source-dir = docs/ +build-dir = docs/_build +all_files = 1 + +[bdist_wheel] +universal = 1 + +[pydocstyle] +add_ignore = D401,D403 + +[isort] +profile=black + +[check-manifest] +ignore = + *-requirements.txt + +[tool:pytest] +addopts = --black --isort --pydocstyle --doctest-glob="*.rst" --doctest-modules --cov=invenio_jobs --cov-report=term-missing +testpaths = docs tests invenio_jobs + +[compile_catalog] +directory = invenio_jobs/translations/ +use-fuzzy = True + +[extract_messages] +copyright_holder = CERN +msgid_bugs_address = info@inveniosoftware.org +mapping-file = babel.ini +output-file = invenio_jobs/translations/messages.pot +add-comments = NOTE + +[init_catalog] +input-file = invenio_jobs/translations/messages.pot +output-dir = invenio_jobs/translations/ + +[update_catalog] +input-file = invenio_jobs/translations/messages.pot +output-dir = invenio_jobs/translations/ diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..53ac52a --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""InvenioRDM module for jobs management.""" + +from setuptools import setup + +setup() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..1ef3935 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Pytest configuration. + +See https://pytest-invenio.readthedocs.io/ for documentation on which test +fixtures are available. +""" + +import pytest +from invenio_app.factory import create_app as _create_app + + +@pytest.fixture(scope="module") +def app_config(app_config): + """Application config override.""" + return app_config + + +@pytest.fixture(scope="module") +def create_app(instance_path): + """Application factory fixture.""" + return _create_app diff --git a/tests/test_invenio_jobs.py b/tests/test_invenio_jobs.py new file mode 100644 index 0000000..35d42e0 --- /dev/null +++ b/tests/test_invenio_jobs.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# Invenio-Jobs is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Module tests.""" + +from flask import Flask + +from invenio_jobs import InvenioJobs + + +def test_version(): + """Test version import.""" + from invenio_jobs import __version__ + + assert __version__ + + +def test_init(): + """Test extension initialization.""" + app = Flask("testapp") + ext = InvenioJobs(app) + assert "invenio-jobs" in app.extensions + + app = Flask("testapp") + ext = InvenioJobs() + assert "invenio-jobs" not in app.extensions + ext.init_app(app) + assert "invenio-jobs" in app.extensions