Skip to content

Commit 72359a1

Browse files
gundalowacozine
authored andcommitted
Tidy up Contributors Docs (ansible#47619)
* Tidy up docs on GitHub, direct people to docs.ansible.com * De-duplicate documentation and move useful info
1 parent 166e84b commit 72359a1

File tree

7 files changed

+74
-357
lines changed

7 files changed

+74
-357
lines changed

.github/CONTRIBUTING.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ Hi! Nice to see you here!
44

55
## QUESTIONS ?
66

7-
Please see the [community guide](https://docs.ansible.com/ansible/latest/community/index.html) for information on how to ask questions on the [mailing lists](https://docs.ansible.com/ansible/latest/community/communication.html#mailing-list-information) and IRC.
7+
Please see the [Community Guide](https://docs.ansible.com/ansible/latest/community/index.html) for information on how to ask questions on the [mailing lists](https://docs.ansible.com/ansible/latest/community/communication.html#mailing-list-information) and IRC.
88

99
The GitHub issue tracker is not the best place for questions for various reasons, but both IRC and the mailing list are very helpful places for those things, as the community page explains best.
1010

1111
## CONTRIBUTING ?
1212

13-
By contributing you agree that these contributions are your own (or approved by your employer) and you grant a full, complete, irrevocable copyright license to all users and developers of the project, present and future, pursuant to the license of the project.
13+
By contributing you agree that these contributions are your own (or approved by your employer) and you grant a full, complete, irrevocable copyright license to all users and developers of the project, present and future, pursuant to the license of the project. You can also read the same [CLA](https://docs.ansible.com/ansible/latest/community/contributor_license_agreement.html) on the Ansible docsite.
1414

15-
Please see the [community guide](https://docs.ansible.com/ansible/latest/community/index.html) for information regarding the contribution process. Important license agreement information is also included on that page.
15+
Please review the [Community Guide](https://docs.ansible.com/ansible/latest/community/index.html) for more information on contributing to Ansible.
1616

1717
## BUG TO REPORT ?
1818

19-
First and foremost, also check the [community guide](https://docs.ansible.com/ansible/latest/community/index.html).
19+
First and foremost, also check the [Community Guide](https://docs.ansible.com/ansible/latest/community/index.html).
2020

2121
You can report bugs or make enhancement requests at the [Ansible GitHub issue page](https://github.com/ansible/ansible/issues/new/choose) by filling out the issue template that will be presented.
2222

23-
Also please make sure you are testing on the latest released version of Ansible or the development branch. You can find the latest releases and development branch at:
24-
25-
- https://github.com/ansible/ansible/releases
26-
- https://github.com/ansible/ansible/archive/devel.tar.gz
23+
Also please make sure you are testing on the latest released version of Ansible or the development branch; see the [Installation Guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) for details.
2724

2825
Thanks!

CODING_GUIDELINES.md

+4-310
Original file line numberDiff line numberDiff line change
@@ -1,316 +1,10 @@
11
Coding Guidelines
22
=================
33

4-
Hi! Thanks for your interest in contributing to Ansible.
4+
Hi! Thanks for your interest in contributing to Ansible. We document our Coding Guidelines in the [Developer Guide](https://docs.ansible.com/ansible/devel/dev_guide/). We particularly suggest you review:
55

6-
Here are some guidelines for contributing code. The purpose of this document is to establish what we're looking for in code contributions, and to make sure
7-
new contributors know some of the conventions that we've been using.
6+
* [Contributing your module to Ansible](https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_checklist.html)
87

9-
We don't think much of this should be too strange to readers familiar with contributing to Python projects, though it helps if we all get on the same page.
8+
* [Development conventions, tips and pitfalls](https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_best_practices.html)
109

11-
Language
12-
========
13-
14-
* While not all components of Ansible must be in Python, core contributions to the Ansible repo must be written in Python. This is to maximize the ability of everyone to contribute.
15-
* If you want to write non-Python ansible modules or inventory scripts, that's fine, but they are not going to get merged in most likely. Sorry!!
16-
17-
PEP 8 and basic style checks
18-
============================
19-
20-
* [PEP 8](https://www.python.org/dev/peps/pep-0008/) is a great Python style guide, which you should read.
21-
* PEP 8 must not be strictly followed in all aspects, but most of it is good advice.
22-
* The line is limited to 160 characters.
23-
* To run checks for things we care about, use [ansible-test](https://docs.ansible.com/ansible/devel/dev_guide/testing_sanity.html).
24-
* Similarly, additional checks can be made with "make pyflakes".
25-
* There is no need to submit code changes for PEP 8 and pyflakes fixes, as these break attribution history. Project leadership will make these periodically.
26-
* Do not submit pull requests that simply adjust whitespace in the code.
27-
28-
Testing
29-
=======
30-
31-
* Much of Ansible's testing needs are in integration, not unit tests. Add module tests there.
32-
* That being said, there are unit tests too!
33-
* Code written must absolutely pass tests (i.e. "make tests")
34-
* You should anticipate any error paths in your code and test down those error paths.
35-
* Additions to tests for core code are welcome, but not always possible. Be sure things are at least well tested manually in that case.
36-
37-
Whitespace
38-
==========
39-
40-
* Four space indent is strictly required
41-
* Include meaningful whitespace between lines of code
42-
43-
Shebang Lines
44-
=============
45-
46-
* /usr/bin/scripts should start with '/usr/bin/env python'
47-
* module code should still use '/usr/bin/python' as this is replaced automatically by 'ansible_python_interpreter', see the FAQ in the docs for more info.
48-
49-
Comments
50-
========
51-
52-
* Readability is one of the most important goals for this project
53-
* Comment any non-trivial code where someone might not know why you are doing something in a particular way
54-
* Though if something should be commented, that's often a sign someone should write a function
55-
* All new functions must have a basic docstring comment
56-
* Commenting above a line is preferable to commenting at the end of a line
57-
58-
Classes
59-
=======
60-
61-
* With the exception of module code (where inline is better), it is desirable to see classes in their own files.
62-
* Classes should generally not cause side effects as soon as they are instantiated, move meaningful behavior to methods rather than constructors.
63-
64-
Functions and Methods
65-
=====================
66-
67-
* In general, functions should not be 'too long' and should describe a meaningful amount of work
68-
* When code gets too nested, that's usually the sign the loop body could benefit from being a function
69-
* Parts of our existing code are not the best examples of this at times.
70-
* Functions should have names that describe what they do, along with docstrings
71-
* Functions should be named with_underscores
72-
* "Don't repeat yourself" is generally a good philosophy
73-
74-
Variables
75-
=========
76-
77-
* Use descriptive variable names instead of variables like 'x', unless x is an obvious loop index
78-
* Ansible python code uses identifiers like 'ClassesLikeThis and variables_like_this
79-
* Module parameters should also use_underscores and not runtogether
80-
81-
Module Security
82-
===============
83-
84-
* Modules must take steps to avoid passing user input from the shell and always check return codes
85-
* always use module.run_command instead of subprocess or Popen or os.system -- this is mandatory
86-
* if you need to use the shell you must pass use_unsafe_shell=True to module.run_command
87-
* if you do not need the shell, avoid using the shell
88-
* any variables that can come from the user input with use_unsafe_shell=True must be wrapped by pipes.quote(x)
89-
* downloads of https:// resource urls must import module_utils.urls and use the fetch_url method
90-
91-
Misc Preferences
92-
================
93-
94-
Use the dict constructor where possible when allocating dictionaries:
95-
96-
# not this:
97-
foo = {
98-
'a' : 12,
99-
'b' : 34
100-
}
101-
102-
# this:
103-
foo = dict(
104-
a=12,
105-
b=34,
106-
)
107-
108-
Do not line up variables
109-
110-
# not this
111-
a = 12
112-
foosball = 34
113-
xyz = 'dog'
114-
115-
# this
116-
a = 12
117-
foosball = 34
118-
xyz = 'dog'
119-
120-
Don't use line continuations:
121-
122-
# no
123-
if (this_is_a_very_long_line and foo and \
124-
i_am_going_to_continue_it):
125-
bar()
126-
127-
# better:
128-
if (this_is_a_very_long_line and foo and i_am_going_to_continue_it):
129-
bar()
130-
131-
Spacing:
132-
133-
# no
134-
x = [1,2,3]
135-
136-
# no
137-
x = [ 1, 2, 3 ]
138-
139-
# yes
140-
x = [1, 2, 3]
141-
142-
Spacing continued:
143-
144-
# no
145-
x=foo(12)
146-
147-
# no
148-
x = foo( 12 )
149-
150-
# yes
151-
x = foo(12)
152-
153-
Licenses
154-
========
155-
156-
Every file should have a license header, including the copyright of the original author. Major additions to the module are allowed
157-
to add an additional copyright line, and this is especially true of rewrites, but original authorship copyright messages should be preserved.
158-
159-
All contributions to the core repo should preserve original licenses and new contributions must include the GPLv3 header.
160-
161-
Module Documentation
162-
====================
163-
164-
All module pull requests must include a DOCUMENTATION docstring (YAML format,
165-
see other modules for examples) as well as an EXAMPLES docstring, which is free form.
166-
167-
When adding new modules, any new parameter must have a "version_added" attribute.
168-
When submitting a new module, the module should have a "version_added" attribute in the
169-
pull request as well, set to the current development version.
170-
171-
Be sure to check grammar and spelling.
172-
173-
It's frequently the case that modules get submitted with YAML that isn't valid,
174-
so you can run "make webdocs" from the checkout to preview your module's documentation.
175-
If it fails to build, take a look at your DOCUMENTATION string
176-
or you might have a Python syntax error in there too.
177-
178-
Python Imports
179-
==============
180-
181-
To make it clear what a module is importing, imports should not be sprinkled throughout the code.
182-
183-
Python Imports should happen at the top of the file, exempting code from module_utils.
184-
185-
When a conditional runtime import is required, do so something like this instead:
186-
187-
HAS_FOO = False
188-
try:
189-
import foo
190-
HAS_FOO = True
191-
except ImportError:
192-
pass
193-
194-
...
195-
196-
if not HAS_FOO:
197-
raise Exception("the foo library is required")
198-
199-
This makes it clear what optional dependencies are but allows this to be deferred until runtime. In the case of module code, the raising of the Exception will be replaced
200-
with a "module.exit_json" call.
201-
202-
Exceptions
203-
==========
204-
205-
In the main body of the code, use typed exceptions where possible:
206-
207-
# not this
208-
raise Exception("panic!")
209-
210-
# this
211-
from ansible import errors
212-
...
213-
raise errors.AnsibleError("panic!")
214-
215-
Similarly, exception checking should be fine grained:
216-
217-
# not this
218-
try:
219-
foo()
220-
except:
221-
bar()
222-
223-
# but this
224-
try:
225-
foo()
226-
except SomeTypedException:
227-
bar()
228-
229-
List Comprehensions
230-
===================
231-
232-
In general list comprehensions are always preferred to map() and filter() calls.
233-
234-
However, they can be abused. Optimize for readability, and avoid nesting them too deeply.
235-
236-
Regexes
237-
=======
238-
239-
There is a time and place for them, but here's an illustrative joke.
240-
241-
"A developer had a problem, and used a regular expression to solve it. Now the developer had two problems".
242-
243-
Often regexes are difficult to maintain, and a trusty call to other string operations can be a great solution, faster,
244-
and more readable.
245-
246-
File Conventions
247-
================
248-
249-
If a piece of code looks for a named YAML file in a directory, it should assume it can take no extension, or an extension of '.yml' or '.yaml'.
250-
This should be true against all code that loads files.
251-
252-
Any code that uses directories should consider the possibility that the directory may be symlink.
253-
254-
New Ansible language parameters
255-
===============================
256-
257-
If adding a new parameter, like 'can_fizzbuzz: True/False' be sure the value of the parameter is templated somewhere in the Runner code, as if anything can be parameterized in Ansible,
258-
there is a user that will try to parameterize it.
259-
260-
String Find
261-
===========
262-
263-
Use 'in':
264-
265-
# not this:
266-
if x.find('foo') != -1:
267-
268-
# this:
269-
if 'foo' in x:
270-
271-
String checks
272-
=============
273-
274-
To test if something is a string, consider that it may be unicode.
275-
276-
# no
277-
if type(x) == str:
278-
279-
# yes
280-
from ansible.module_utils.six import string_types
281-
if isinstance(x, string_types):
282-
283-
Cleverness
284-
==========
285-
286-
Ansible's code is intended to be read by as many people as possible, so we don't particularly encourage clever or heavily idiomatic code.
287-
288-
In particular, metaclasses are probably not appropriate, however entertaining they may be to add.
289-
290-
Git Practices
291-
=============
292-
293-
Pull requests cannot be accepted if they contain merge commits.
294-
295-
Always do "git pull --rebase" and "git rebase" vs "git pull" or "git merge". See [rebasing a pull request](https://docs.ansible.com/ansible/latest/dev_guide/developing_rebasing.html) for more information.
296-
297-
Always create a new branch for each pull request to avoid intermingling different features or fixes on the same branch.
298-
299-
300-
Python Version Compliance
301-
=========================
302-
303-
All code in Ansible core must support a minimum version of Python 2.6.
304-
305-
Module code must support a minimum of Python 2.4, with occasional exceptions for modules that require code that themselves require 2.6 and later.
306-
307-
A quick reminder is that list comprehensions in Python 2.4 are not as fully fleshed out, there are no 'dict' comprehensions, and there is no 'with' statement.
308-
But otherwise it's pretty much all the same.
309-
310-
The End
311-
=======
312-
313-
This was not meant to be a scary document, so we hope it wasn't, but we also hope this helps you write code that is easier to maintain by others in the future.
314-
If you have questions about this document, please ask on the ansible-devel mailing list.
315-
316-
Thank you!
10+
Our [Community Guide](https://docs.ansible.com/ansible/devel/community/) may also help you connect with the community of Ansible developers.

MODULE_GUIDELINES.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Module Maintainer Guidelines
22

33
The Ansible Module Maintainer Guidelines can now be found in the [official Ansible community guide](https://docs.ansible.com/ansible/latest/community/maintainers.html).
4+
5+
See also the [Developers Guide](https://docs.ansible.com/ansible/latest/dev_guide/)

0 commit comments

Comments
 (0)