Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/tips.md β†’ .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ WARNING: do not name this file as README.md since it will be rendered in the mai
- ``PULL_REQUEST_TEMPLATE.md``
- ``ISSUE_TEMPLATE`` folder:
- Add [top-level syntax](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms#top-level-syntax) to ISSUE_TEMPLATE/*.md files to configure them and view them as [template in the github web](https://github.com/ITISFoundation/osparc-simcore/issues/new/choose)


---

## Copilot Usage Tips

1. **Be Specific**: Provide clear and detailed prompts to Copilot for better suggestions.
2. **Iterate**: Review and refine Copilot's suggestions to ensure they meet project standards.
3. **Split Tasks**: Break down complex tasks into smaller, manageable parts for better suggestions.
4. **Test Suggestions**: Always test Copilot-generated code to ensure it works as expected.

- SEE https://code.visualstudio.com/docs/copilot/copilot-customization#_custom-instructions
80 changes: 43 additions & 37 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,58 @@ This document provides guidelines and best practices for using GitHub Copilot in

## General Guidelines

1. **Use Python 3.11**: Ensure that all Python-related suggestions align with Python 3.11 features and syntax.
2. **Node.js Compatibility**: For Node.js projects, ensure compatibility with the version specified in the project (e.g., Node.js 14 or later).
3. **Follow Coding Conventions**: Adhere to the coding conventions outlined in the `docs/coding-conventions.md` file.
4. **Test-Driven Development**: Write unit tests for all new functions and features. Use `pytest` for Python and appropriate testing frameworks for Node.js.
5. **Environment Variables**: Use environment variables as specified in `docs/env-vars.md` for configuration. Avoid hardcoding sensitive information.
6. **Documentation**: Prefer self-explanatory code; add documentation only if explicitly requested by the developer.
1. **Test-Driven Development**: Write unit tests for all new functions and features. Use `pytest` for Python and appropriate testing frameworks for Node.js.
2. **Environment Variables**: Use [Environment Variables Guide](../docs/env-vars.md) for configuration. Avoid hardcoding sensitive information.
3. **Documentation**: Prefer self-explanatory code; add documentation only if explicitly requested by the developer.

## Python-Specific Instructions
---

- Always use type hints and annotations to improve code clarity and compatibility with tools like `mypy`.
- An exception to that rule is in `test_*` functions return type hint must not be added
- Follow the dependency management practices outlined in `requirements/`.
- Use `ruff` for code formatting and for linting.
- Use `black` for code formatting and `pylint` for linting.
- ensure we use `sqlalchemy` >2 compatible code.
- ensure we use `pydantic` >2 compatible code.
- ensure we use `fastapi` >0.100 compatible code
- use f-string formatting
- Only add comments in function if strictly necessary
- use relative imports
- imports should be at top of the file
## πŸ› οΈCoding Instructions for Python in This Repository

Follow these rules strictly when generating Python code:

### Json serialization
### 1. Python Version

- Generally use `json_dumps`/`json_loads` from `common_library.json_serialization` to built-in `json.dumps` / `json.loads`.
- Prefer Pydantic model methods (e.g., `model.model_dump_json()`) for serialization.
* Use Python 3.11: Ensure all code uses features and syntax compatible with Python 3.11.

### 2. **Type Annotations**

## Node.js-Specific Instructions
* Always use full type annotations for all functions and class attributes.
* ❗ **Exception**: Do **not** add return type annotations in `test_*` functions.

- Use ES6+ syntax and features.
- Follow the `package.json` configuration for dependencies and scripts.
- Use `eslint` for linting and `prettier` for code formatting.
- Write modular and reusable code, adhering to the project's structure.
### 3. **Code Style & Formatting**

## Copilot Usage Tips
* Follow [Python Coding Conventions](../docs/coding-conventions.md) **strictly**.
* Format code with `black`.
* Lint code with `ruff` and `pylint`.

1. **Be Specific**: Provide clear and detailed prompts to Copilot for better suggestions.
2. **Iterate**: Review and refine Copilot's suggestions to ensure they meet project standards.
3. **Split Tasks**: Break down complex tasks into smaller, manageable parts for better suggestions.
4. **Test Suggestions**: Always test Copilot-generated code to ensure it works as expected.
### 4. **Library Compatibility**

## Additional Resources
Ensure compatibility with the following library versions:

- [Python Coding Conventions](../docs/coding-conventions.md)
- [Environment Variables Guide](../docs/env-vars.md)
- [Pydantic Annotated fields](../docs/llm-prompts/pydantic-annotated-fields.md)
- [Steps to Upgrade Python](../docs/steps-to-upgrade-python.md)
* `sqlalchemy` β‰₯ 2.x
* `pydantic` β‰₯ 2.x
* `fastapi` β‰₯ 0.100


### 5. **Code Practices**

* Use `f-string` formatting for all string interpolation except for logging message strings.
* Use **relative imports** within the same package/module.
* Place **all imports at the top** of the file.
* Add comments **only when the code is not self-explanatory**.


### 6. **JSON Serialization**

* Prefer `json_dumps` / `json_loads` from `common_library.json_serialization` instead of the built-in `json.dumps` / `json.loads`.
* When using Pydantic models, prefer methods like `model.model_dump_json()` for serialization.

---

## πŸ› οΈCoding Instructions for Node.js in This Repository

* Use ES6+ syntax and features.
* Follow the `package.json` configuration for dependencies and scripts.
* Use `eslint` for linting and `prettier` for code formatting.
* Write modular and reusable code, adhering to the project's structure.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Prompt
---
mode: 'edit'
description: 'Convert Pydantic model fields to use Annotated pattern'
---


```
Please convert all pydantic model fields that use `Field()` with default values to use the Annotated pattern instead.
Follow these guidelines:

Expand All @@ -10,7 +13,8 @@ Follow these guidelines:
4. Add the import: `from common_library.basic_types import DEFAULT_FACTORY` if it's not already present.
5. If `Field()` has no parameters (empty), don't use Annotated at all. Just use: `field_name: field_type = default_value`.
6. Leave any model validations, `model_config` settings, and `field_validators` untouched.
```


## Examples

### Before:
Expand Down Expand Up @@ -53,13 +57,11 @@ class ProjectModel(BaseModel):
id: str = Field(default_factory=uuid.uuid4, description="Unique project identifier")
name: str = Field(default="Untitled Project", min_length=3, max_length=50)
created_at: datetime = Field(default_factory=datetime.now)
value: int = Field(..., description="Project value")
str_with_default: str = Field(default="foo")

config: dict = Field(default={"version": "1.0", "theme": "default"})

@field_validator("name")
def validate_name(cls, v):
if v.isdigit():
raise ValueError("Name cannot be only digits")
return v
```

### After:
Expand All @@ -74,11 +76,9 @@ class ProjectModel(BaseModel):
id: Annotated[str, Field(default_factory=uuid.uuid4, description="Unique project identifier")] = DEFAULT_FACTORY
name: Annotated[str, Field(min_length=3, max_length=50)] = "Untitled Project"
created_at: Annotated[datetime, Field(default_factory=datetime.now)] = DEFAULT_FACTORY
value: Annotated[int, Field(description="Project value")]
str_with_default: str = "foo"

config: dict = {"version": "1.0", "theme": "default"}

@field_validator("name")
def validate_name(cls, v):
if v.isdigit():
raise ValueError("Name cannot be only digits")
return v
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from aiohttp import ClientError, ClientSession, web
from models_library.app_diagnostics import AppStatusCheck
from pydantic import BaseModel, Field
from pydantic import BaseModel
from servicelib.aiohttp.client_session import get_client_session
from servicelib.aiohttp.requests_validation import parse_request_query_parameters_as
from servicelib.utils import logged_gather
Expand All @@ -29,7 +29,7 @@


class StatusDiagnosticsQueryParam(BaseModel):
top_tracemalloc: int | None = Field(default=None)
top_tracemalloc: int | None = None


class StatusDiagnosticsGet(BaseModel):
Expand Down
Loading
Loading