Skip to content

Commit

Permalink
Add the file structure for this project, the basics of tests, github …
Browse files Browse the repository at this point in the history
…actions, documentation
  • Loading branch information
lizgzil committed Jul 26, 2024
1 parent 8e72832 commit 83e6722
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy docs to gh-pages

on:
workflow_dispatch:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest
name: Deploy docs to gh-pages
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Deploy
uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONFIG_FILE: docs/mkdocs.yml
REQUIREMENTS: docs/site_assets/requirements.txt
57 changes: 57 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Unit Tests

on: [push]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: ["3.9", "3.10"]
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install additional dependencies
run: |
poetry install --no-interaction
#----------------------------------------------
# add matrix specifics and run test suite
#----------------------------------------------
- name: Run tests
run: poetry run pytest tests/ --verbose
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Mac OS-specific storage files
.DS_Store

__pycache__/
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# nlp-link
A python package to semantically link two lists of texts.


## Set-up

In setting up this project we ran:
```
conda create --name nlp-link pip python=3.9
conda activate nlp-link
pip install poetry
```

```
poetry init
```

```
poetry install
```

## Tests

To run tests:

```
poetry run pytest tests/
```

## Documentation

Docs for this repo are automatically published to gh-pages branch via. Github actions after a PR is merged into dev. We use Material for MkDocs for these. Nothing needs to be done to update these.

However, if you are editing the docs you can test them out locally by running

```
cd guidelines
pip install -r docs/requirements.txt
mkdocs serve
```
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# nlp-link

Documentation for NLP Link

- [Page1](./page1.md)
44 changes: 44 additions & 0 deletions docs/mkdocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
site_name: NLP Link
site_description: A python package to semantically link two lists of texts..
site_url: https://nestauk.github.io/nlp-link
repo_name: nestauk/nlp-link
repo_url: https://github.com/nestauk/nlp-link
extra:
homepage: https://nestauk.github.io/nlp-link
docs_dir: .
extra_css:
- site_assets/style.css
theme:
name: material
# disable_nav_previous_next: true
# disable_footer: false
logo: site_assets/nesta_logo.png
favicon: site_assets/nesta_logo.png
features:
- navigation.instant
- navigation.tracking
# - navigation.tabs
- navigation.sections
- navigation.top
font:
text: Century Gothic
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
primary: custom
accent: custom
toggle:
icon: material/weather-night
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: amber
accent: pink
toggle:
icon: material/weather-sunny
name: Switch to light mode
nav:
- Home: README.md
- Page 1: page1.md
plugins:
- same-dir
1 change: 1 addition & 0 deletions docs/page1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Title
Binary file added docs/site_assets/nesta_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/site_assets/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdocs
mkdocs-material
mkdocs-same-dir
10 changes: 10 additions & 0 deletions docs/site_assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import url('https://fonts.cdnfonts.com/css/century-gothic');
html,
body,
[class*="css"] {
font-family: "Century Gothic";
}
:root {
--md-primary-fg-color: #18A48C;
--md-accent-fg-color: #EB003B;
}
Empty file added nlp_link/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions nlp_link/linker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pandas as pd

import random

def link_lists(list_1, list_2):
"""
Mock linker
"""
list_1_index = list(range(len(list_1)))
list_2_index = list(range(len(list_2)))

return [(i, random.choice(list_1_index)) for i in list_2_index]
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "nlp-link"
version = "0.1.0"
description = "A python package to semantically link two lists of texts."
authors = ["Nesta <[email protected]>"]
readme = "README.md"
packages = [{include = "nlp_link"}]

[tool.poetry.dependencies]
python = "^3.9"
scikit-learn = "^1.4.2"
pandas = "^2.2.2"
sentence-transformers = "^2.1.0"
torch = "^1.10.0"
pytest = "^8.2.0"
tqdm = "^4.64.1"
numpy = "^1.24.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/test_linker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from nlp_link.linker import link_lists

def test_link_lists():

list_1 = ["dog", "cat"]
list_2 = ["kitten", "puppy"]
linked = link_lists(list_1, list_2)

assert len(linked) == len(list_1)

0 comments on commit 83e6722

Please sign in to comment.