Skip to content

Commit 7bd413f

Browse files
authored
feat: Added basic action setup (#1)
* feat: Added header validation utils * style: Added style configs * ci: Added style check job * feat: Added action.yml * docs: Updated README * style: Fixed typo in mypy config * ci: Fixed CI job * ci: Fixed CI job
1 parent c710c17 commit 7bd413f

15 files changed

Lines changed: 619 additions & 2 deletions

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 120
3+
ignore = E203, E402, E265, F403, W503, W504, E731
4+
exclude = .git, venv*, docs, build
5+
per-file-ignores = **/__init__.py:F401
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 🐛 Bug report
2+
description: Create a report to help us improve the library
3+
labels: 'type: bug'
4+
assignees: frgfm
5+
6+
body:
7+
- type: markdown
8+
attributes:
9+
value: >
10+
#### Before reporting a bug, please check that the issue hasn't already been addressed in [the existing and past issues](https://github.com/frgfm/validate-python-headers/issues?q=is%3Aissue).
11+
- type: textarea
12+
attributes:
13+
label: Bug description
14+
description: |
15+
A clear and concise description of what the bug is.
16+
17+
Please explain the result you observed and the behavior you were expecting.
18+
placeholder: |
19+
A clear and concise description of what the bug is.
20+
validations:
21+
required: true
22+
23+
- type: textarea
24+
attributes:
25+
label: Code snippet to reproduce the bug
26+
description: |
27+
Sample code to reproduce the problem.
28+
29+
Please wrap your code snippet with ```` ```triple quotes blocks``` ```` for readability.
30+
placeholder: |
31+
```python
32+
Sample code to reproduce the problem
33+
```
34+
validations:
35+
required: true
36+
- type: textarea
37+
attributes:
38+
label: Error traceback
39+
description: |
40+
The error message you received running the code snippet, with the full traceback.
41+
42+
Please wrap your error message with ```` ```triple quotes blocks``` ```` for readability.
43+
placeholder: |
44+
```
45+
The error message you got, with the full traceback.
46+
```
47+
validations:
48+
required: true
49+
- type: textarea
50+
attributes:
51+
label: Environment
52+
description: |
53+
Please run the following command and paste the output below.
54+
```sh
55+
wget https://raw.githubusercontent.com/frgfm/validate-python-headers/main/.github/collect_env.py
56+
# For security purposes, please check the contents of collect_env.py before running it.
57+
python collect_env.py
58+
```
59+
validations:
60+
required: true
61+
- type: markdown
62+
attributes:
63+
value: >
64+
Thanks for helping us improve the library!

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Usage questions
4+
url: https://github.com/frgfm/validate-python-headers/discussions
5+
about: Ask questions and discuss with other community members
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 🚀 Feature request
2+
description: Submit a proposal/request for a new feature
3+
labels: 'type: enhancement'
4+
assignees: frgfm
5+
6+
body:
7+
- type: textarea
8+
attributes:
9+
label: 🚀 Feature
10+
description: >
11+
A clear and concise description of the feature proposal
12+
validations:
13+
required: true
14+
- type: textarea
15+
attributes:
16+
label: Motivation & pitch
17+
description: >
18+
Please outline the motivation for the proposal. Is your feature request related to a specific problem? e.g., *"I'm working on X and would like Y to be possible"*. If this is related to another GitHub issue, please link here too.
19+
validations:
20+
required: true
21+
- type: textarea
22+
attributes:
23+
label: Alternatives
24+
description: >
25+
A description of any alternative solutions or features you've considered, if any.
26+
- type: textarea
27+
attributes:
28+
label: Additional context
29+
description: >
30+
Add any other context or screenshots about the feature request.
31+
- type: markdown
32+
attributes:
33+
value: >
34+
Thanks for contributing 🎉

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# What does this PR do?
2+
3+
<!--
4+
Well, hello there! Thank you for proposing modifications to the project.
5+
6+
Make sure to have both a short descriptive title & explain your modifications with the relevant context. Make sure to include reference to Github issues it is related to. For the sake of keeping the library light, if you modified existing dependencies or added new ones, please state it clearly in your description.
7+
8+
-->
9+
10+
<!-- Remove if not applicable -->
11+
12+
Closes # (issue)
13+
14+
15+
## Before submitting
16+
- [ ] Was this discussed/approved in a Github [issue](https://github.com/frgfm/validate-python-headers/issues?q=is%3Aissue) or a [discussion](https://github.com/frgfm/validate-python-headers/discussions)? Please add a link to it if that's the case.
17+
- [ ] You have read the [contribution guidelines](https://github.com/frgfm/validate-python-headers/blob/main/CONTRIBUTING.md#submitting-a-pull-request) and followed them in this PR.
18+
- [ ] Did you make sure to update the documentation with your changes? Here are the
19+
[documentation guidelines](https://github.com/frgfm/validate-python-headers/tree/main/docs).
20+
- [ ] Did you write any new necessary tests?

.github/collect_env.py

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Copyright (C) 2022, François-Guillaume Fernandez.
2+
3+
# This program is licensed under the Apache License version 2.
4+
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.
5+
6+
"""
7+
Based on https://github.com/pytorch/pytorch/blob/master/torch/utils/collect_env.py
8+
This script outputs relevant system environment info
9+
Run it with `python collect_env.py`.
10+
"""
11+
12+
from __future__ import absolute_import, division, print_function, unicode_literals
13+
14+
import locale
15+
import re
16+
import subprocess
17+
import sys
18+
from collections import namedtuple
19+
20+
PY3 = sys.version_info >= (3, 0)
21+
22+
23+
# System Environment Information
24+
SystemEnv = namedtuple(
25+
"SystemEnv",
26+
[
27+
"os",
28+
"python_version",
29+
],
30+
)
31+
32+
33+
def run(command):
34+
"""Returns (return-code, stdout, stderr)"""
35+
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
36+
output, err = p.communicate()
37+
rc = p.returncode
38+
if PY3:
39+
enc = locale.getpreferredencoding()
40+
output = output.decode(enc)
41+
err = err.decode(enc)
42+
return rc, output.strip(), err.strip()
43+
44+
45+
def run_and_read_all(run_lambda, command):
46+
"""Runs command using run_lambda; reads and returns entire output if rc is 0"""
47+
rc, out, _ = run_lambda(command)
48+
if rc != 0:
49+
return None
50+
return out
51+
52+
53+
def run_and_parse_first_match(run_lambda, command, regex):
54+
"""Runs command using run_lambda, returns the first regex match if it exists"""
55+
rc, out, _ = run_lambda(command)
56+
if rc != 0:
57+
return None
58+
match = re.search(regex, out)
59+
if match is None:
60+
return None
61+
return match.group(1)
62+
63+
64+
def get_platform():
65+
if sys.platform.startswith("linux"):
66+
return "linux"
67+
elif sys.platform.startswith("win32"):
68+
return "win32"
69+
elif sys.platform.startswith("cygwin"):
70+
return "cygwin"
71+
elif sys.platform.startswith("darwin"):
72+
return "darwin"
73+
else:
74+
return sys.platform
75+
76+
77+
def get_mac_version(run_lambda):
78+
return run_and_parse_first_match(run_lambda, "sw_vers -productVersion", r"(.*)")
79+
80+
81+
def get_windows_version(run_lambda):
82+
return run_and_read_all(run_lambda, "wmic os get Caption | findstr /v Caption")
83+
84+
85+
def get_lsb_version(run_lambda):
86+
return run_and_parse_first_match(run_lambda, "lsb_release -a", r"Description:\t(.*)")
87+
88+
89+
def check_release_file(run_lambda):
90+
return run_and_parse_first_match(run_lambda, "cat /etc/*-release", r'PRETTY_NAME="(.*)"')
91+
92+
93+
def get_os(run_lambda):
94+
platform = get_platform()
95+
96+
if platform in ("win32", "cygwin"):
97+
return get_windows_version(run_lambda)
98+
99+
if platform == "darwin":
100+
version = get_mac_version(run_lambda)
101+
if version is None:
102+
return None
103+
return "Mac OSX {}".format(version)
104+
105+
if platform == "linux":
106+
# Ubuntu/Debian based
107+
desc = get_lsb_version(run_lambda)
108+
if desc is not None:
109+
return desc
110+
111+
# Try reading /etc/*-release
112+
desc = check_release_file(run_lambda)
113+
if desc is not None:
114+
return desc
115+
116+
return platform
117+
118+
# Unknown platform
119+
return platform
120+
121+
122+
def get_env_info():
123+
run_lambda = run
124+
125+
return SystemEnv(
126+
python_version=".".join(map(str, sys.version_info[:3])),
127+
os=get_os(run_lambda),
128+
)
129+
130+
131+
env_info_fmt = """
132+
OS: {os}
133+
134+
Python version: {python_version}
135+
""".strip()
136+
137+
138+
def pretty_str(envinfo):
139+
def replace_nones(dct, replacement="Could not collect"):
140+
for key in dct.keys():
141+
if dct[key] is not None:
142+
continue
143+
dct[key] = replacement
144+
return dct
145+
146+
def replace_bools(dct, true="Yes", false="No"):
147+
for key in dct.keys():
148+
if dct[key] is True:
149+
dct[key] = true
150+
elif dct[key] is False:
151+
dct[key] = false
152+
return dct
153+
154+
def maybe_start_on_next_line(string):
155+
# If `string` is multiline, prepend a \n to it.
156+
if string is not None and len(string.split("\n")) > 1:
157+
return "\n{}\n".format(string)
158+
return string
159+
160+
mutable_dict = envinfo._asdict()
161+
162+
# Replace True with Yes, False with No
163+
mutable_dict = replace_bools(mutable_dict)
164+
165+
# Replace all None objects with 'Could not collect'
166+
mutable_dict = replace_nones(mutable_dict)
167+
168+
return env_info_fmt.format(**mutable_dict)
169+
170+
171+
def get_pretty_env_info():
172+
"""Collects environment information for debugging purposes
173+
174+
Returns:
175+
str: environment information
176+
"""
177+
return pretty_str(get_env_info())
178+
179+
180+
def main():
181+
print("Collecting environment information...")
182+
output = get_pretty_env_info()
183+
print(output)
184+
185+
186+
if __name__ == "__main__":
187+
main()

.github/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- ignore-for-release
5+
categories:
6+
- title: Breaking Changes 🛠
7+
labels:
8+
- "type: breaking change"
9+
# NEW FEATURES
10+
- title: New Features 🚀
11+
labels:
12+
- "type: new feature"
13+
# BUG FIXES
14+
- title: Bug Fixes 🐛
15+
labels:
16+
- "type: bug"
17+
# IMPROVEMENTS
18+
- title: Improvements
19+
labels:
20+
- "type: enhancement"
21+
# MISC
22+
- title: Miscellaneous
23+
labels:
24+
- "type: misc"

0 commit comments

Comments
 (0)