Skip to content

Commit a10d75d

Browse files
authored
Feat 2 slims ephys (#3)
* wip * models for SLIMS tables * wip restart * unit tests (wip) * unit tests * renames workflows dir * moves workflows dir into .github * code cleanup (wip) * adds missing docstrings * models cleanup * moves alias, fixes * flake8 linter * fixing tests (wip) * finish up tests, flake8 * add missing docstrings * test fix * cleanup * updates service readme * reverts models * staticmethods * adds missing changes from last commit * table handler class methods * AwareDatetime
1 parent d6d9a9f commit a10d75d

32 files changed

+2103
-237
lines changed

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
# aind-service-template
2-
A template repo that can be used for rapid development of FastAPI services.
1+
# aind-slims-service
2+
REST service to connect to SLIMS and return information.
33

44
## Usage
55

6-
### Initialize a repo
6+
### Create the server.
77

8-
- Click the green "Use This Template" button
9-
- Once the repo is created, please wait several seconds for the github action to initialize the files. You can check the status in the "Actions" tab.
10-
- Update the main README and *-server/README files if desired
11-
- It's recommended to update the repo settings to require Pull Requests and Reviews.
8+
- The server code is developed in the aind-slims-service-server package.
9+
- On a push to main, a docker image will be built and published to GitHub's container registry.
10+
- You can then run the server in a docker container or k8s pod.
11+
- More details can be found in the [service README](aind-slims-service-server/README.md) file
1212

13-
### Auto-run tests, publish docker image, and create client code
13+
### Auto-generated client code.
1414

15-
- In the repo settings, add `svc-aindscicomp` as an admin to the list of Collaborators.
16-
- Move the yaml files from `workflow_templates` to `.github/workflows/`
17-
- When a PR is opened, the server code will be tested.
18-
- When a PR is merged into main:
19-
- The tag will be incremented
20-
- The server code will be published as a docker image
21-
- The client code will be autogenerated from the openapi specification and published to PyPI
15+
- The client code is autogenerated using an openapi generator.
16+
- On a push to main, a python library will be built and published to PyPI.
17+
- The client can then be pip installed as `pip install aind-slims-service-client`
Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# aind-service-template-server
1+
# aind-slims-service-server
22

33
[![License](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)
44
![Code Style](https://img.shields.io/badge/code%20style-black-black)
@@ -7,5 +7,74 @@
77
![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen?logo=codecov)
88
![Python](https://img.shields.io/badge/python->=3.10-blue?logo=python)
99

10-
REST service to retrieve data from an backend.
10+
REST service to retrieve data from SLIMS.
11+
12+
## Local Development
13+
14+
Requires docker to build and run package locally.
15+
16+
- Create a file called env/webapp.env with appropriate env variables.
17+
- Run `docker build -t aind-slims-service-server-local:latest .`
18+
- Run `docker run -p 58350:58350 -p 5000:80 --env-file=env/webapp.env aind-slims-service-server-local:latest`
19+
- Service will be available at `http://localhost:5000`
20+
- Check docs at `http://localhost:5000/docs`
21+
22+
### Linters and testing
23+
24+
There are several libraries used to run linters, check documentation, and run
25+
tests.
26+
27+
- Please test your changes using the **coverage** library, which will run the
28+
tests and log a coverage report:
29+
30+
```
31+
coverage run -m pytest && coverage report
32+
```
33+
34+
- Use **interrogate** to check that modules, methods, etc. have been documented
35+
thoroughly:
36+
37+
```
38+
interrogate .
39+
```
40+
41+
- Use **flake8** to check that code is up to standards
42+
(no unused imports, etc.):
43+
```
44+
flake8 .
45+
```
46+
47+
- Use **black** to automatically format the code into PEP standards:
48+
```
49+
black .
50+
```
51+
52+
- Use **isort** to automatically sort import statements:
53+
```
54+
isort .
55+
```
56+
57+
### Pull requests
58+
59+
For internal members, please create a branch. For external members, please fork
60+
the repo and open a pull request from the fork. We'll primarily use
61+
[Angular](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit)
62+
style for commit messages. Roughly, they should follow the pattern:
63+
```
64+
<type>(<scope>): <short summary>
65+
```
66+
67+
where scope (optional) describes the packages affected by the code changes and
68+
type (mandatory) is one of:
69+
70+
- **build**: Changes that affect the build system or external dependencies
71+
(example scopes: pyproject.toml, setup.py)
72+
- **ci**: Changes to our CI configuration files and scripts
73+
(examples: .github/workflows/ci.yml)
74+
- **docs**: Documentation only changes
75+
- **feat**: A new feature
76+
- **fix**: A bug fix
77+
- **perf**: A code change that improves performance
78+
- **refactor**: A code change that neither fixes a bug nor adds a feature
79+
- **test**: Adding missing tests or correcting existing tests
1180

aind-slims-service-server/pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "aind-slims-service-server"
7-
description = "Package to serve data from backend."
7+
description = "Package to serve data from SLIMS."
88
license = {text = "MIT"}
99
requires-python = ">=3.10"
1010
authors = [
@@ -17,10 +17,12 @@ readme = "README.md"
1717
dynamic = ["version"]
1818

1919
dependencies = [
20-
'requests-toolbelt', # Used for example. Remove if not needed.
2120
'pydantic>=2.0',
2221
'pydantic-settings>=2.0',
2322
'fastapi[standard]>=0.114.0',
23+
'slims-python-api',
24+
'networkx',
25+
'aind-settings-utils>=0.0.3',
2426
]
2527

2628
[project.optional-dependencies]
@@ -90,5 +92,8 @@ fail-under = 100
9092
asyncio_mode="auto"
9193
asyncio_default_fixture_loop_scope="function"
9294
env = [
93-
"MYENV_HOST=example"
95+
"SLIMS_USERNAME=slims_user",
96+
"SLIMS_PASSWORD=slims_password",
97+
"SLIMS_HOST=slims_host",
98+
"SLIMS_DB=slims_db"
9499
]
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
"""Module for settings to connect to backend"""
1+
"""Module for settings to connect to SLIMS backend"""
22

3-
from pydantic import Field
4-
from pydantic_settings import BaseSettings, SettingsConfigDict
3+
from aind_settings_utils.aws import (
4+
ParameterStoreAppBaseSettings,
5+
)
6+
from pydantic import Field, SecretStr
7+
from pydantic_settings import SettingsConfigDict
58

69

7-
class Settings(BaseSettings):
8-
"""
9-
### Settings needed to connect to a database or website.
10-
We will just connect to an example website.
11-
"""
10+
class Settings(ParameterStoreAppBaseSettings):
11+
"""Settings for connecting to SLIMS Database."""
1212

13-
model_config = SettingsConfigDict(env_prefix="MYENV_")
14-
host: str = Field(
15-
...,
16-
title="Host",
17-
description="Host address of example.com",
13+
username: str = Field(..., description="User name")
14+
password: SecretStr = Field(..., description="Password")
15+
host: str = Field(..., description="host")
16+
db: str = Field(default="slims", description="Database")
17+
model_config = SettingsConfigDict(
18+
env_prefix="SLIMS_",
19+
case_sensitive=False,
1820
)

aind-slims-service-server/src/aind_slims_service_server/handler.py

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Handlers for the AIND SLIMS Service Server."""

0 commit comments

Comments
 (0)