Skip to content

Commit dc8af4e

Browse files
authoredDec 1, 2023
Merge pull request #84 from linkml/issue-81
Rewrite README instructions to use pipx
2 parents 50134ee + 2ff1c80 commit dc8af4e

File tree

4 files changed

+91
-116
lines changed

4 files changed

+91
-116
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
.idea
132+
.vscode

‎README.md

+82-108
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
11
# LinkML Project Cookiecutter
22

3-
A [Cookiecutter](https://cookiecutter.readthedocs.io/en/stable/) template for
4-
projects using [LinkML](https://github.com/linkml/linkml).
3+
A [Cookiecutter](https://cookiecutter.readthedocs.io/en/stable/) template for projects using [LinkML](https://github.com/linkml/linkml).
54

6-
## Standard Protocol
5+
## Prerequisites
76

8-
### Step 1: Create a virtual environment
7+
The following are required and recommended tools for using this cookiecutter and the LinkML project that it generates. This is all one-time setup, so if you have already done it skip to the [next section]()!
98

10-
Create a Python virtual environment.
11-
You can read [this guide](https://realpython.com/python-virtual-environments-a-primer/)
12-
to learn more about them and how to create one. We suggest using poetry, but
13-
you can use any tool you like. Please note, most LinkML tools work best in
14-
Python 3.8 or higher.
9+
* **Python >= 3.8**
10+
11+
LinkML tools are mainly written in Python, so you will need a recent Python interpreter to run this generator and to use the generated project.
1512

16-
An example using poetry:
1713

18-
```bash
19-
curl -sSL https://install.python-poetry.org | python3 -
20-
```
14+
* **pipx**
15+
16+
pipx is a tool for managing isolated Python-based applications. It is the recommended way to install Poetry and cruft. To install pipx follow the instructions here: https://pypa.github.io/pipx/installation/
2117

22-
```bash
23-
mkdir linkml-projects
24-
cd linkml-projects
25-
poetry init # creates a new poetry project with pyproject.toml
26-
# Note this is not a new linkml project,
27-
# it is just a virtual environment to install cruft.
28-
poetry add click==8.1.3 # this creates your virtual environment.
29-
```
3018

31-
Add `poetry-dynamic-versioning` as a plugin
19+
* **Poetry**
20+
21+
Poetry is a Python project management tool. You will use it in your generated project to manage dependencies and build distribution files. If you have pipx installed you can install Poetry by running:
22+
```shell
23+
pipx install poetry
24+
```
25+
For other installation methods see: https://python-poetry.org/docs/#installation
26+
3227

33-
```bash
34-
poetry self add "poetry-dynamic-versioning[plugin]"
35-
```
28+
* **Poetry Dynamic Versioning Plugin**:
3629

37-
### Step 2: Install the cruft tool in your virtual environment
30+
This plugin automatically updates certain version strings in your generated project when you publish it. Your generated project will automatically be set up to use it. Install it by running:
31+
```shell
32+
poetry self add "poetry-dynamic-versioning[plugin]"
33+
```
3834

39-
This tool will help you keep your project up to date with the latest LinkML
40-
tools and best practices.
4135

42-
In your poetry virtual environment:
36+
* **cruft**
4337

44-
```bash
45-
poetry shell
46-
poetry add cruft
47-
```
38+
cruft is a tool for generating projects based on a cookiecutter (like this one!) as well as keeping those projects updated if the original cookiecutter changes. Install it with pipx by running:
39+
```shell
40+
pipx install cruft
41+
```
42+
You may also choose to not have a persistent installation of cruft, in which case you would replace any calls to the `cruft` command below with `pipx run cruft`.
43+
44+
## Creating a new project
4845

49-
### Step 3: Use cruft to create your brand new LinkML project
46+
### Step 1: Generate the project files
5047

51-
In your poetry virtual environment:
48+
To generate a new LinkML project run the following:
5249

5350
```bash
5451
cruft create https://github.com/linkml/linkml-project-cookiecutter
@@ -58,115 +55,95 @@ You will be prompted for a few values. The defaults are fine for most
5855
projects, but do name your project something that makes sense to you!
5956
The interactive session will guide you through the process:
6057

61-
- `project_name`: Name of the project, use kebab-case with no spaces.
62-
Suggestions:
63-
- `patient-observation-schema`
64-
- `sample-collection-metadata`
65-
- `resume-standard`
66-
- `project_description`: Description of the project.
67-
- A single brief sentence is recommended
68-
- Can easily be modified later
69-
- `full_name`: Your name
70-
- `email`: your email
71-
- `main_schema_class`:
72-
- This is used to generate an example schema which you can edit
73-
- The value of this field is ignored if this is a schemasheets project
74-
- You can always change this later
58+
1. `project_name`: Name of the project, use kebab-case with no spaces.
59+
Suggestions:
60+
- `patient-observation-schema`
61+
- `sample-collection-metadata`
62+
- `resume-standard`
63+
2. `github_org`: Your github username or organization name. This is used to construct links to documentation pages.
64+
3. `project_description`: Description of the project.
65+
- A single brief sentence is recommended
66+
- Can easily be modified later
67+
4. `full_name`: Your name
68+
5. `email`: Your email
69+
6. `license`: Choose a license for the project. If your desired license is not listed you can update or remove the `LICNSE` file in the generated project.
70+
7. `main_schema_class`:
71+
- This is used to generate an example schema which you can edit
72+
- The value of this field is ignored if this is a schemasheets project
73+
- You can always change this later
7574
- Examples: `Person`, `Observation`, `Sample`, `Entry`, `Gene`, `Event`
76-
- `create_python_project`
77-
- If "Yes", set this up as a python project
78-
- Select Yes if you want to make data classes that can be used by developers
79-
- `use_schemasheets`
80-
- If "Yes", set this to obtain your schema from
75+
8. `create_python_project`
76+
- If "Yes", set this up as a python project
77+
- Select Yes if you want to make data classes that can be used by developers
78+
9. `use_schemasheets`
79+
- If "Yes", set this to obtain your schema from
8180
[schemasheets](https://linkml.io/schemasheets)
82-
- `google_sheet_id`
83-
- Ignore/use default value if answer to previous question was "No"
84-
- If you are using schemasheets then enter your google doc ID here
85-
- If you like you can leave the default value, and this will use the demo
86-
schema
87-
- `google_sheet_tabs`
88-
- Ignore/use default value if not using schemasheets
89-
- If you are using schemasheets, enter a space-separated list of tabs
90-
- your tabs in your sheet MUST NOT have spaces in them
91-
- `github_token_for_pypi_deployment`:
92-
- The github token name which aligns with your autogenerated PyPI token for
93-
making releases.
94-
- This helps automated releases to PyPI
95-
- This should be ignored if this is not a python project
96-
- Even if this is a python project, you can leave blank and fill in later
97-
98-
This will generate the project folder abiding by the template configuration
99-
specified by `linkml-project-cookiecutter` in the
100-
[`cookiecutter.json`](https://github.com/linkml/linkml-project-cookiecutter/blob/main/cookiecutter.json)
101-
file.
102-
103-
This will generate the project folder very similar to what is mentioned in the
104-
[linkml-project-template](https://github.com/linkml/linkml-project-template)
105-
project.
106-
107-
For more docs, see
108-
[linkml/linkml-project-cookiecutter](https://github.com/linkml/linkml-project-cookiecutter).
109-
110-
### Step 4: Setup the LinkML project
81+
10. `google_sheet_id`
82+
- Ignore/use default value if answer to previous question was "No"
83+
- If you are using schemasheets then enter your google doc ID here
84+
- If you like you can leave the default value, and this will use the demo schema
85+
11. `google_sheet_tabs`
86+
- Ignore/use default value if not using schemasheets
87+
- If you are using schemasheets, enter a space-separated list of tabs
88+
- your tabs in your sheet MUST NOT have spaces in them
89+
12. `github_token_for_pypi_deployment`:
90+
- The github token name which aligns with your autogenerated PyPI token for making releases.
91+
- This helps automated releases to PyPI
92+
- This should be ignored if this is not a python project
93+
- Even if this is a python project, you can leave blank and fill in later
94+
95+
### Step 2: Set up the LinkML project
11196

11297
Optionally, pass custom configuration to linkml generators by tuning the global configuration file 'config.yaml' with preferred options. An example file is supplied by the project to illustrate interface and defaults.
11398

11499
Additionally, pass command-line arguments to linkml generators inside the Makefile via environment variables in 'config.env' file. An example file is supplied by the project, passing '--config-file config.yaml' to gen-project.
115100

116-
117101
Change to the folder your generated project is in
118102

119103
```bash
120104
cd my-awesome-schema # using the folder example above
121105
make setup
122106
```
123107

124-
### Step 5: Edit the schema
108+
### Step 3: Edit the schema
125109

126110
Edit the schema (the .yaml file) in the
127-
`linkml-projects/my-awesome-schema/src/my_awesome_schema/schema` folder
111+
`src/my_awesome_schema/schema` folder
128112

129113
```bash
130114
nano src/my_awesome_schema/schema/my_awesome_schema.yaml
131115
```
132116

133-
### Step 6: Validate the schema
117+
### Step 4: Validate the schema
134118

135119
```bash
136120
make test
137121
```
138122

139-
### Step 7: Auto-generate your documentation locally
123+
### Step 5: Generate documentation locally
140124

141-
LinkML generates schema documentation automatically. Step 7 here, allows you to
142-
preview the documentation that LinkML generates before pushing to GitHub.
143-
Note, this template comes with GitHub Actions that autogenerate this
144-
documentation on release of your schema repository at a URL like this one:
145-
[https://my-user-or-organization.github.io/my-awesome-schema/]
125+
LinkML generates schema documentation automatically. The template comes with GitHub Actions that generate and publish the documentation when you push schema changes to GitHub. The published documentation can be found at a URL like this one:
126+
`https://{github-user-or-organization}.github.io/{project-name}/`
127+
128+
You can also preview the documentation locally before pushing to GitHub by running:
146129

147130
```bash
148131
make serve
149132
```
150133

151-
### Step 8: Create a github project
134+
### Step 6: Create a GitHub project
152135

153-
1. Go to [https://github.com/new] and follow the instructions, being sure to
154-
NOT add a README or .gitignore file (this cookiecutter template will take
155-
care of this for you)
136+
1. Go to https://github.com/new and follow the instructions, being sure to NOT add a `README` or `.gitignore` file (this cookiecutter template will take care of those files for you)
156137

157138
2. Add the remote to your local git repository
158139

159140
```bash
160-
git remote add origin https://github.com/my-user-or-organization/my-awesome-schema.git
141+
git remote add origin https://github.com/{github-user-or-organization}/{project-name}.git
161142
git branch -M main
162143
git push -u origin main
163144
```
164145

165-
### Step 9: Deploy documentation
166-
167-
`make deploy`
168-
169-
### Step 10: Register the schema
146+
### Step 7: Register the schema
170147

171148
See [How to register a schema](https://linkml.io/linkml/faq/contributing.html#how-do-i-register-my-schema)
172149

@@ -176,7 +153,6 @@ In order to be up-to-date with the template, first check if there is a mismatch
176153
between the project's boilerplate code and the template by running:
177154
178155
```bash
179-
poetry shell
180156
cruft check
181157
```
182158
@@ -195,8 +171,6 @@ up-to-date by the following:
195171
FAILURE: Project's cruft is out of date! Run `cruft update` to clean this mess up.
196172
```
197173
198-
For viewing the difference, run `cruft diff`. This shows the difference between
199-
the project's boilerplate code and the template's latest version.
174+
For viewing the difference, run `cruft diff`. This shows the difference between the project's boilerplate code and the template's latest version.
200175
201-
After running `cruft update`, the project's boilerplate code will be updated to
202-
the latest version of the template.
176+
After running `cruft update`, the project's boilerplate code will be updated to the latest version of the template.

‎{{cookiecutter.project_name}}/Makefile

+3-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ endif
3636

3737

3838
# basename of a YAML file in model/
39-
.PHONY: all clean
39+
.PHONY: all clean setup gen-project gen-examples gendoc git-init-add git-init git-add git-commit git-status
4040

4141
# note: "help" MUST be the first target in the file,
4242
# when the user types "make" they should get help info
@@ -58,11 +58,10 @@ status: check-config
5858
@echo "Source: $(SOURCE_SCHEMA_PATH)"
5959

6060
# generate products and add everything to github
61-
setup: install gen-project gen-examples gendoc git-init-add
61+
setup: git-init install gen-project gen-examples gendoc git-add git-commit
6262

6363
# install any dependencies required for building
6464
install:
65-
git init
6665
poetry install
6766
.PHONY: install
6867

@@ -172,8 +171,7 @@ git-init-add: git-init git-add git-commit git-status
172171
git-init:
173172
git init
174173
git-add: .cruft.json
175-
git add .gitignore .github .cruft.json Makefile LICENSE *.md examples utils about.yaml mkdocs.yml poetry.lock project.Makefile pyproject.toml src/{{cookiecutter.__project_slug}}/schema/*yaml src/*/datamodel/*py src/data src/docs tests src/*/_version.py
176-
git add $(patsubst %, project/%, $(PROJECT_FOLDERS))
174+
git add .
177175
git-commit:
178176
git commit -m 'chore: initial commit' -a
179177
git-status:

‎{{cookiecutter.project_name}}/tests/test_data.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import unittest
55

66
from linkml_runtime.loaders import yaml_loader
7-
from {{cookiecutter.__project_slug}}.datamodel.{{cookiecutter.__project_slug}} import {{cookiecutter.main_schema_class}}
7+
from {{cookiecutter.__project_slug}}.datamodel.{{cookiecutter.__project_slug}} import {{cookiecutter.main_schema_class}}Collection
88

99
ROOT = os.path.join(os.path.dirname(__file__), '..')
1010
DATA_DIR = os.path.join(ROOT, "src", "data", "examples")
@@ -16,7 +16,7 @@ class TestData(unittest.TestCase):
1616
"""Test data and datamodel."""
1717

1818
def test_data(self):
19-
"""Date test."""
19+
"""Data test."""
2020
for path in EXAMPLE_FILES:
21-
obj = yaml_loader.load(path, target_class={{cookiecutter.main_schema_class}})
21+
obj = yaml_loader.load(path, target_class={{cookiecutter.main_schema_class}}Collection)
2222
assert obj

0 commit comments

Comments
 (0)
Please sign in to comment.