|
| 1 | +=========== |
| 2 | +Development |
| 3 | +=========== |
| 4 | + |
| 5 | +This section provides an overview of the development and deployment process for the project. |
| 6 | + |
| 7 | +The application requires a configuration file in INI format. The configuration file format can be found in the |
| 8 | +:ref:`config file section <configuration-file>`. |
| 9 | + |
| 10 | +Build for Production |
| 11 | +==================== |
| 12 | + |
| 13 | +.. _dockerizing: |
| 14 | + |
| 15 | +Dockerizing the Application |
| 16 | +--------------------------- |
| 17 | +To containerize the application using Docker, use the `Dockerfile` at the root of the project. You can build the Docker image with the following command: |
| 18 | + |
| 19 | +.. code-block:: console |
| 20 | +
|
| 21 | + $ docker build -t getmarcapi . |
| 22 | +
|
| 23 | +
|
| 24 | +Run Locally for Development |
| 25 | +=========================== |
| 26 | + |
| 27 | +Prerequisites |
| 28 | +------------- |
| 29 | +Preinstalled Development dependencies: |
| 30 | + |
| 31 | + * uv (manage Python e) |
| 32 | + * Node.js and npm (for building static assets) |
| 33 | + |
| 34 | +.. Note:: |
| 35 | + |
| 36 | + You should be using `uv <https://docs.astral.sh/uv/>`_ to manage your virtual environments and dependencies. These |
| 37 | + directions are going to assume that you have uv installed. If you do not have |
| 38 | + `uv` installed, you *can* use `pip` but **uv is HIGHLY RECOMMENDED**. |
| 39 | + |
| 40 | + `See uv installation instructions <https://docs.astral.sh/uv/getting-started/installation/>`_. |
| 41 | + |
| 42 | +Getting Development Environment Set Up |
| 43 | +-------------------------------------- |
| 44 | + |
| 45 | +To run the application locally for development purposes, follow these steps: |
| 46 | + |
| 47 | +1. Clone the repository: |
| 48 | + |
| 49 | + .. code-block:: console |
| 50 | +
|
| 51 | + $ git clone https://github.com/UIUCLibrary/getmarcapi.git |
| 52 | + Cloning into 'getmarcapi'... |
| 53 | + remote: Enumerating objects: 986, done. |
| 54 | + remote: Counting objects: 100% (364/364), done. |
| 55 | + remote: Compressing objects: 100% (157/157), done. |
| 56 | + remote: Total 986 (delta 271), reused 210 (delta 207), pack-reused 622 (from 2) |
| 57 | + Receiving objects: 100% (986/986), 441.69 KiB | 7.36 MiB/s, done. |
| 58 | + Resolving deltas: 100% (468/468), done. |
| 59 | +
|
| 60 | + $ cd getmarcapi |
| 61 | +
|
| 62 | +2. Create and activate a Python virtual environment using uv with the development dependencies: |
| 63 | + |
| 64 | + On Unix Environments: |
| 65 | + |
| 66 | + .. code-block:: console |
| 67 | +
|
| 68 | + $ uv sync --dev |
| 69 | + Resolved 119 packages in 33ms |
| 70 | + Audited 106 packages in 46ms |
| 71 | +
|
| 72 | + $ source .venv/bin/activate |
| 73 | +
|
| 74 | + On Windows Environments: |
| 75 | + |
| 76 | + .. code-block:: pwsh-session |
| 77 | +
|
| 78 | + > uv sync --dev |
| 79 | + Resolved 119 packages in 33ms |
| 80 | + Audited 106 packages in 46ms |
| 81 | +
|
| 82 | + > .venv\Scripts\activate |
| 83 | +
|
| 84 | +3. Gather and build the static assets: |
| 85 | + |
| 86 | + There are some nice CSS libraries used in the top-level API documentation page. During development, you will need to |
| 87 | + install them to getmarcapi/static. |
| 88 | + |
| 89 | + .. code-block:: console |
| 90 | +
|
| 91 | + (getmarcapi) $ npm install |
| 92 | + (getmarcapi) $ npm run env -- webpack --output-path=./getmarcapi/static |
| 93 | +
|
| 94 | +4. Start the Flask development server: |
| 95 | + |
| 96 | + |
| 97 | + .. code-block:: console |
| 98 | +
|
| 99 | + (getmarcapi) $ FLASK_APP=getmarcapi/app.py uv run flask run |
| 100 | + * Serving Flask app 'getmarcapi/app.py' |
| 101 | + * Debug mode: off |
| 102 | + WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. |
| 103 | + * Running on http://127.0.0.1:5000 |
| 104 | + Press CTRL+C to quit |
| 105 | +
|
| 106 | + .. important:: |
| 107 | + |
| 108 | + You need to have the api url and api key. |
| 109 | + |
| 110 | + For development, you can set the **ALMA_API_DOMAIN** and **API_KEY** environment variables in your shell. |
| 111 | + |
| 112 | + |
| 113 | +Running Tests |
| 114 | +============= |
| 115 | + |
| 116 | +To run tests, you need to have pytest installed. If you are using the development environment, it should already be |
| 117 | +installed. Tests are run by executing the pytest command. |
| 118 | + |
| 119 | +.. code-block:: shell-session |
| 120 | +
|
| 121 | + (getmarcapi) $ pytest |
| 122 | + ============================== test session starts ============================== |
| 123 | + platform darwin -- Python 3.11.10, pytest-8.4.2, pluggy-1.6.0 -- .venv/bin/python |
| 124 | + cachedir: .pytest_cache |
| 125 | + rootdir: /Users/mydev/pythonprojects/getmarcapi |
| 126 | + configfile: pyproject.toml |
| 127 | + testpaths: tests |
| 128 | + plugins: anyio-4.12.1, typeguard-4.4.4 |
| 129 | + collected 27 items |
| 130 | +
|
| 131 | + tests/test_api.py::test_root PASSED |
| 132 | + tests/test_api.py::test_get_record_xml PASSED |
| 133 | + tests/test_api.py::test_get_record_missing_param PASSED |
| 134 | + tests/test_api.py::test_api_documentation PASSED |
| 135 | + ... |
| 136 | + ============================== 27 passed in 0.34s =============================== |
0 commit comments