Skip to content

Commit 415d053

Browse files
committed
removed target flag and wanted to try extlink plugin along with testing requirement and class info addition
1 parent e3a305f commit 415d053

File tree

11 files changed

+112
-47
lines changed

11 files changed

+112
-47
lines changed

docs/python/classes.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ sidebar_label: Classes
88

99
* Avoid inbuilt names.
1010
* Classes names should always be `PascalCase`. i.e. `MyClass`
11-
* Even if you are building datatypes based on inbuilt class use PascalCase. i.e. `MyDict(dict):`
11+
* Use [abstract containers](https://docs.python.org/3/library/collections.abc.html#module-collections.abc) if need to override datatypes.
12+
+ If you must build datatypes based on inbuilt class use PascalCase. i.e. `MyDict(dict):`.
1213
* Describe the class responsibility in name.
1314
* Custom Exceptions should always be named ending with `Error` i.e. `MyCustomError`
15+
16+
##### Example
17+
18+
```
19+
class HelloWorld:
20+
pass
21+
22+
class HelloWorldError(Exception):
23+
pass
24+
```

docs/python/docstrings.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ The developers should add docstrings in the following locations
139139
- At the beginning of every class
140140
- After each function declaration
141141
- At the beginning of the `__init__.py` file for Module/Package documentation
142+
- In their tests to describe what they are testing.
142143
143144
### What to not miss
144145
@@ -155,9 +156,9 @@ to check that your docstrings render correctly
155156
156157
### Checking Docstring coverage
157158
158-
If you want to check docstring coverage in your project. Try interrogate (example below)
159+
- Use [pycodestyle](https://pycodestyle.pycqa.org/en/latest/) for linting your code against docstrings. When using `flake8`, [this](https://gitlab.com/pycqa/flake8-docstrings) plugin can be used.
160+
- [interrogate](https://interrogate.readthedocs.io/en/latest/) (example below) is **recommended** to use for docstring coverage in the code.
159161
160-
- [interrogate](https://interrogate.readthedocs.io/en/latest/)
161162
162163
```
163164
@@ -547,7 +548,3 @@ Thanks to the following
547548
- [Documenting in Python - DevGuide](https://devguide.python.org/documenting/)
548549
- [daouzli - stackoverflow](https://stackoverflow.com/questions/3898572/what-is-the-standard-python-docstring-format)
549550
- [interrogate](https://interrogate.readthedocs.io/en/latest/)
550-
551-
552-
553-

docs/python/environment_and_dependency.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ sidebar_label: Environment Isolation and Dependency Management
1010

1111
* System installed `python` should never be used for development. Isolate your development.
1212
* Any of the following can be used for python isolation:
13-
- [pyenv](https://github.com/pyenv/pyenv){:target="_blank"}. **Recommended** as this supports local python install and multiple python versions.
14-
- [virtualenv](https://virtualenv.pypa.io/en/latest/){:target="_blank"}. _Third Party_
15-
- [venv](https://docs.python.org/3/tutorial/venv.html){:target="_blank"}. _Inbuilt_ `python -m venv`
13+
- [pyenv](https://github.com/pyenv/pyenv). **Recommended** as this supports local python install and multiple python versions.
14+
- [virtualenv](https://virtualenv.pypa.io/en/latest/). _Third Party_
15+
- [venv](https://docs.python.org/3/tutorial/venv.html). _Inbuilt_ `python -m venv`
1616
* Use `pip` for installing packages if not using `poetry`.
1717

1818

1919

2020
##### Dependency Management:
2121

22-
* [poetry](https://python-poetry.org/){:target="_blank"} is recommended as it handles dependency as well as build system.
22+
* [poetry](https://python-poetry.org/) is recommended as it handles dependency as well as build system.
2323
* You can use `setuptools` and `setup.py` as well for requirements handling through `requires`. They **must** be used for install-able modules.

docs/python/functions.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ sidebar_label: Functions
1212
* for bound methods in class `self` should be used for first argument.
1313
* for class methods in class `cls` should be used for first argument.
1414
* `decorators` should be named in function convention.
15+
16+
17+
```
18+
def get_db_connection(username, db_name):
19+
return connection
20+
21+
#method
22+
23+
def get_db_connection(self, username, db_name):
24+
return connection
25+
26+
27+
# classmethod
28+
@classmethod
29+
def multiple_param_initializer(cls, cls_param):
30+
return cls(cls_param)
31+
32+
```

docs/python/general.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ sidebar_label: General Coding Guidelines
66

77
#### These are the general guidelines to be followed:
88

9+
* See [tools](tools.md) that can be used in development environment setup to ease your coding process.
910
* Always use `python3` and try to stay above version `3.5`. **Latest stable** is recommended.
1011
* Indentation should always be **space** and width should always be **4**.
1112
* File size and functionality:
@@ -19,19 +20,21 @@ sidebar_label: General Coding Guidelines
1920
- `classmethod` for multiple way of class initialization
2021
* Imports:
2122
- Always `import` specific namespace.
22-
- Try to use parent namespace for actions. i.e. `import os: os.path` rather that `from os import path`
23+
- Try to use parent namespace for actions. i.e. `import sys: sys.path` rather that `from sys import path`
2324
- Never use `import *` i.e. `from MODULE import *`
2425
- use namespace whenever possible. Use `as SOMEOTHERNAMESPACE` for collision of namespace
2526
* Use `else: #nobreak` if you are using `else` with loops that has `break`.
26-
* use `mypy` and type annotation when possible for type safe code.
27-
* `Docker` can be used for deployment. Use `python` images for [docker](https://hub.docker.com/_/python){:target="_blank"}.
27+
* Use `pathlib` for path related use case rather than `os.path`
28+
* Use `mypy` and type annotation when possible for type safe code.
29+
* `Docker` can be used for deployment. Use `python` images for [docker](https://hub.docker.com/_/python).
2830
* Use `generators` and `yield` instead of data structures for high streams of data.
2931
* Use `itertools`, `functools` for utilities and `collection` for data structures.
3032
* Use `dataclasses` if available. Go for `attrs` library if `dataclass` is not present.
3133
* Use `is not` and `is` for `None`, `True` and `False` specific check only. If most cases truthy and falsy can be checked with if `VARNAME:`.
3234
* Strings:
3335
- Adhere to one quote practice. Double quote is recommended. Python doesnot differentiate between **'** or **"**.
34-
- Should be interpolated with either [fstring](https://www.python.org/dev/peps/pep-0498/){:target="_blank"} or `.format` methods. Try to avoid `%`.
36+
- Should be interpolated with either [fstring](https://www.python.org/dev/peps/pep-0498/) or `.format` methods. Try to avoid `%`.
37+
+ `format_map` should be used for key mapped formatting.
3538
- `+` can be used for direct string concatenation. Use `join` method for concatenation instead of `+=` when iterating.
3639
* Use `context` whenever supported especially for io related closing actions.
3740
- i.e. `with` statement when supported.
@@ -45,8 +48,8 @@ sidebar_label: General Coding Guidelines
4548
- Use `asyncio` for IO bound async flow. This is something new and constantly changing in `python`.
4649
* Recommended third party modules:
4750
- For Relational Database:
48-
+ Use `sqlalchemy` [core](https://docs.sqlalchemy.org/en/13/core/){:target="_blank"} for DB abstraction. This is particularly helpful when doing testing in `sqlite` and some other database for production. Also, for query consistency.
49-
+ Use `sqlalchemy` [ORM](https://docs.sqlalchemy.org/en/13/orm/){:target="_blank"} or framework supported ORM when using specific framework.
51+
+ Use `sqlalchemy` [core](https://docs.sqlalchemy.org/en/13/core/) for DB abstraction. This is particularly helpful when doing testing in `sqlite` and some other database for production. Also, for query consistency.
52+
+ Use `sqlalchemy` [ORM](https://docs.sqlalchemy.org/en/13/orm/) or framework supported ORM when using specific framework.
5053
+ Use DBAPI drivers such as `pyodbc`, `sqlite`, `mysqlclient` etc only when you donot want `sqlalchemy` dependency or when you are very performance conscious. While the API will be mostly compatible for this as python has DBAPI specification. Parameters binding and some methods may be incompatible or unavailable.
5154
- `requests` for http request stuff.
5255
- `attrs` for data oriented objects and class.

docs/python/project_structure.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ sidebar_label: Project Structure
1818
+ :file_folder: service
1919
+ :file_folder: config
2020
- :file_folder: tests
21-
+ test of projects
21+
+ :file_folder: test of projects
22+
+ :memo: conftest.py
2223
- :memo: LICENSE (**OPTIONAL**)
2324
- :memo: README (can be `md` or `rst`)
2425
- Other configurable from third parties (**OPTIONAL**) such as tox.ini
2526

2627

28+
+ **There can be cases where MVC folder structure as well as framework related folder structure can be used.**
29+
- The framework recommended structure shoudl be followed in such case.
30+
+ The OOP style cases of class as filename structue is not always necessary but can be used if needed.
31+
32+
2733

2834
##### Template Generation:
29-
* Look into [cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/){:target="_blank"} tool for template generation.
30-
- [List of templates for cookiecutter](http://cookiecutter-templates.sebastianruml.name/){:target="_blank"}
35+
* Look into [cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/) tool for template generation.
36+
- [List of templates for cookiecutter](http://cookiecutter-templates.sebastianruml.name/)

docs/python/testing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
id: testing
3+
title: Testing in `python`
4+
sidebar_label: Testing
5+
---
6+
7+
### Test is integral part of sofware quality and should not be missed.
8+
9+
10+
11+
* Always use `pytest` for testing codes.
12+
+ `unittest` provided by standard python can be used too if there is some blockage in using `pytest`.
13+
* `tox` and `nox` are vey good tools especially for CI and multiple version tests.
14+
* `hypothesis` and `mock` can be used for faking data and property testing.
15+
* Testing should be broken to `unit` as well as `functional`.
16+
* Use `coverage` to alert yourself of test coverage.
17+
* Only test the changes you made or functionality you added when testing a codebase of well known frameworks.
18+
* `selenium` as well as `webtest` can be used for web based API testing.
19+
* `jsonschema` and `genson` like tool can be used for JSON validity.
20+
* Always confirm the `schema` when testing Web API response data.
21+
* Passing tests for `merge` should be priority for all projects.

docs/python/tools.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,44 @@
22
id: tools
33
title: Tools to use for easing development and maintaining consistency. There are links to readings as well.
44
sidebar_label: Tools and Libraries
5-
---
5+
---
6+
7+
:::info
8+
These tools can be used along with your development environment and IDE so that you can follow coding conventions better.
9+
:::
610

711
#### Templates:
8-
* [cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/){:target="_blank"}
12+
* [cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/)
913

1014
#### Dependency Management:
11-
* [poetry](https://python-poetry.org/){:target="_blank"}
15+
* [poetry](https://python-poetry.org/)
1216

1317
#### Linters:
14-
* [flake8](https://flake8.pycqa.org/en/latest/){:target="_blank"} with [plugins](https://github.com/DmytroLitvinov/awesome-flake8-extensions){:target="_blank"}
15-
* Alternative: [pylint](https://www.pylint.org){:target="_blank"}
16-
* [bandit](https://bandit.readthedocs.io/en/latest/){:target="_blank"} to find common security issues. This can be used with `flake8` as a [plugin](https://pypi.org/project/flake8-bandit/){:target="_blan.k"}
18+
* [flake8](https://flake8.pycqa.org/en/latest/) with [plugins](https://github.com/DmytroLitvinov/awesome-flake8-extensions)
19+
* Alternative: [pylint](https://www.pylint.org)
20+
* [bandit](https://bandit.readthedocs.io/en/latest/) to find common security issues. This can be used with `flake8` as a [plugin](https://pypi.org/project/flake8-bandit/)
1721

1822
#### Formatters:
19-
* [black](https://black.readthedocs.io/en/stable/){:target="_blank"}
20-
- Alternative: [autopep8](https://pypi.org/project/autopep8/){:target="_blank"}
21-
- Alternative: [yapf](https://pypi.org/project/yapf/){:target="_blank"}
22-
* [isort](https://timothycrosley.github.io/isort/){:target="_blank"} for sorting only imports in codes. This is OPTIONAL.
23-
23+
* [black](https://black.readthedocs.io/en/stable/)
24+
- Alternative: [autopep8](https://pypi.org/project/autopep8/)
25+
- Alternative: [yapf](https://pypi.org/project/yapf/)
26+
* [isort](https://timothycrosley.github.io/isort/) for sorting only imports in codes. This is OPTIONAL.
27+
- Alternative: [reorder-python-imports](https://github.com/asottile/reorder_python_imports) another way of sorting imports.
28+
2429
#### Testing:
25-
* [pytest](https://pytest.org){:target="_blank"} with [plugins](https://docs.pytest.org/en/2.7.3/plugins_index/index.html){:target="_blank"}
30+
* [pytest](https://pytest.org) with [plugins](https://docs.pytest.org/en/2.7.3/plugins_index/index.html)
2631
- Alternative: Inbuilt `unittest`
27-
* [hypothesis](https://hypothesis.readthedocs.io/en/latest/){:target="_blank"} and `mock` for data generation and mocking in tests.
28-
* [tox](https://tox.readthedocs.io/en/latest/){:target="_blank"} for test automation in different `python` version
29-
- Alternative: [nox](https://nox.thea.codes/en/stable/){:target="_blank"} is an alternative to `tox`.
32+
* [hypothesis](https://hypothesis.readthedocs.io/en/latest/) and `mock` for data generation and mocking in tests.
33+
* [tox](https://tox.readthedocs.io/en/latest/) for test automation in different `python` version
34+
- Alternative: [nox](https://nox.thea.codes/en/stable/) is `tox` with `python` API i.e. py file settings so can be used if you need any dynamism.
3035

3136
#### Other tools:
32-
* [coverage](https://coverage.readthedocs.io/en/coverage-5.1/){:target="_blank"} for checking code coverage of tests.
33-
* [interrogate](https://interrogate.readthedocs.io/en/latest/){:target="_blank"} for docstring coverage check.
34-
* [mypy](http://mypy-lang.org/index.html){:target="_blank"} optional static type coding with python through annotations.
37+
* [coverage](https://coverage.readthedocs.io/en/coverage-5.1/) for checking code coverage of tests.
38+
* [interrogate](https://interrogate.readthedocs.io/en/latest/) for docstring coverage check.
39+
* [mypy](http://mypy-lang.org/index.html) optional static type coding with python through annotations.
3540

3641
#### Readings and References:
37-
* [Design Patterns](https://python-patterns.guide/){:target="_blank"}
38-
* [Official Documentation](https://docs.python.org/3/){:target="_blank"}
39-
* [Python Code Quality](https://meta.pycqa.org/en/latest/index.html){:target="_blank"} for the tools like `flake8`, `pylint`, `bandit` etc along with others.
40-
* [Python Packages](https://www.pypa.io/en/latest/){:target="_blank"}
42+
* [Design Patterns](https://python-patterns.guide/)
43+
* [Official Documentation](https://docs.python.org/3/)
44+
* [Python Code Quality](https://meta.pycqa.org/en/latest/index.html) for the tools like `flake8`, `pylint`, `bandit` etc along with others.
45+
* [Python Packages](https://www.pypa.io/en/latest/)

docusaurus.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const remarkLinks = require('remark-external-links');
12
module.exports = {
23
title: 'Coding Standards And Convention',
34
tagline: 'Coding Standards And Convention Documentation',
@@ -87,6 +88,7 @@ module.exports = {
8788
homePageId: 'doc1',
8889
sidebarPath: require.resolve('./sidebars.js'),
8990
// Please change this to your repo.
91+
remarkPlugins: [remarkLinks],
9092
editUrl:
9193
'https://github.com/facebook/docusaurus/edit/master/website/',
9294
},

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"deploy": "docusaurus deploy"
1010
},
1111
"dependencies": {
12-
"@docusaurus/core": "^2.0.0-alpha.55",
13-
"@docusaurus/preset-classic": "^2.0.0-alpha.55",
12+
"@docusaurus/core": "^2.0.0-alpha.56",
13+
"@docusaurus/preset-classic": "^2.0.0-alpha.56",
1414
"classnames": "^2.2.6",
1515
"react": "^16.8.4",
16-
"react-dom": "^16.8.4"
16+
"react-dom": "^16.8.4",
17+
"remark-external-links": "^6.0.0"
1718
},
1819
"browserslist": {
1920
"production": [
@@ -27,4 +28,4 @@
2728
"last 1 safari version"
2829
]
2930
}
30-
}
31+
}

0 commit comments

Comments
 (0)