Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 99f3032

Browse files
authored
Add testing workflow and update contributing guide (#259)
1 parent 894d0c4 commit 99f3032

File tree

4 files changed

+226
-23
lines changed

4 files changed

+226
-23
lines changed

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
paths:
6+
- 'model_card_toolkit/**'
7+
- '.github/workflows/ci.yml'
8+
- 'setup.py'
9+
- 'pyproject.toml'
10+
branches:
11+
- master
12+
- r*
13+
pull_request:
14+
paths:
15+
- 'model_card_toolkit/**'
16+
- '.github/workflows/ci.yml'
17+
- 'setup.py'
18+
- 'pyproject.toml'
19+
branches:
20+
- master
21+
- r*
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
ci:
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 60
31+
32+
steps:
33+
- uses: actions/checkout@v2
34+
- name: Set up Python 3.7
35+
uses: actions/setup-python@v2
36+
with:
37+
python-version: 3.7
38+
- name: Cache python environment
39+
uses: actions/cache@v2
40+
with:
41+
# Cache pip
42+
path: ~/.cache/pip
43+
# Check the cache for a given setup.py + MCT version
44+
key: ${{ runner.os }}-pip-${{ hashFiles('model_card_toolkit/version.py') }}
45+
restore-keys: |
46+
${{ runner.os }}-pip
47+
- name: Install dependencies
48+
run: |
49+
python -m pip install --upgrade pip wheel
50+
python -m pip install -e ".[test]"
51+
- name: Run tests
52+
run: pytest model_card_toolkit

CONTRIBUTING.md

Lines changed: 159 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,168 @@
1-
# How to Contribute
1+
# Contribute to Model Card Toolkit
22

3-
We'd love to accept your patches and contributions to this project. There are
4-
just a few small guidelines you need to follow.
3+
Model Card Toolkit can only grow through the contributions of this community.
4+
Thanks so much for your enthusiasm and your work—we appreciate everything you do!
55

6-
## Contributor License Agreement
6+
There are many ways to contribute to Model Card Toolkit! You can contribute code,
7+
improve tests and API documentation, or create new end-to-end examples. Code
8+
contributions are not the only way to help the community. Proposing usability
9+
and design improvements, answering questions, and helping others are also
10+
immensely valuable.
711

8-
Contributions to this project must be accompanied by a Contributor License
9-
Agreement. You (or your employer) retain the copyright to your contribution;
10-
this simply gives us permission to use and redistribute your contributions as
11-
part of the project. Head over to <https://cla.developers.google.com/> to see
12-
your current agreements on file or to sign a new one.
12+
It also helps us if you spread the word! Reference the library in blog posts
13+
about the awesome projects it made possible, shout out on social media every
14+
time it has helped you, or simply star the repository to say thank you.
1315

14-
You generally only need to submit a CLA once, so if you've already submitted one
15-
(even if it was for a different project), you probably don't need to do it
16-
again.
16+
For more ways to contribute, refer to GitHub's
17+
[guide to making open source contributions](https://opensource.guide/how-to-contribute/)
1718

18-
## Code reviews
19+
**However you choose to contribute, please follow
20+
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).**
21+
22+
*This guide was heavily inspired by other guides in the
23+
[Tensorflow GitHub organization](https://github.com/tensorflow) and the
24+
[🤗 Transformers guide to contributing](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).*
25+
26+
## Contributing Code
27+
28+
If you have improvements to Model Card Toolkit, send us your pull requests!
29+
Before writing any code, we strongly advise you to search through the existing
30+
[pull requests](https://github.com/tensorflow/model-card-toolkit/pulls)
31+
or [issues](https://github.com/tensorflow/model-card-toolkit/issues) to make sure
32+
nobody is already working on the same thing.
33+
34+
If you would like to contribute code and are not sure where to start, take look
35+
at issues with the labels
36+
["good first issue"](https://github.com/tensorflow/model-card-toolkit/labels/good%20first%20issue)
37+
or ["contributions welcome"](https://github.com/tensorflow/model-card-toolkit/labels/stat%3Acontributions%20welcome).
38+
39+
When you find an issue that you want to work on, please leave a comment so other
40+
people know you're working on it. If you need help or would prefer to work on the
41+
issue with others, you may use the issue comment thread ask questions or coordinate.
42+
43+
### Code reviews
1944

2045
All submissions, including submissions by project members, require review. We
21-
use GitHub pull requests for this purpose. Consult
22-
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23-
information on using pull requests.
46+
use GitHub pull requests for this purpose. For those just getting started, GitHub
47+
has a [pull requests guide](https://help.github.com/articles/using-pull-requests/).
48+
49+
Before submitting your pull request for review, make sure your changes follow the
50+
Model Card Toolkit guidelines and coding style. Maintainers and other contributors
51+
will review your pull request. Please participate in the discussion and make the
52+
requested changes.
53+
54+
### Contributor License Agreements
55+
56+
We'd love to accept your patches! Before we can take them, we have to jump
57+
a couple of legal hurdles.
58+
59+
Please fill out either the individual or corporate Contributor License Agreement (CLA).
60+
61+
- If you are an individual writing original source code and you're sure you own the
62+
intellectual property, then you'll need to sign an
63+
[individual CLA](https://code.google.com/legal/individual-cla-v1.0.html).
64+
- If you work for a company that wants to allow you to contribute your work, then you'll
65+
need to sign a [corporate CLA](https://code.google.com/legal/corporate-cla-v1.0.html).
66+
67+
Follow either of the two links above to access the appropriate CLA and instructions
68+
for how to sign and return it. Once we receive it, we'll be able to accept your pull
69+
requests.
70+
71+
***NOTE***: Only original source code from you and other people that have signed the
72+
CLA can be accepted into the main repository.
73+
74+
### Setting up a local development environment
75+
76+
Follow these steps to install `model-card-toolkit`:
77+
78+
1. Install [Bazel](https://bazel.build/install), which powers the protobuf stub
79+
code generation. Confirm that Bazel is installed and executable:
80+
81+
```sh
82+
bazel --version
83+
```
84+
85+
2. Fork the [repository](https://github.com/tensorflow/model-card-toolkit) by
86+
clicking on the **[Fork](https://github.com/tensorflow/model-card-toolkit/fork)**
87+
button on the repository's page. This creates a copy of the code under your
88+
GitHub user account.
89+
90+
3. Clone your fork to your local machine:
91+
92+
```sh
93+
git clone git@github.com:<your GitHub username>/model-card-toolkit.git
94+
cd model-card-toolkit
95+
```
96+
97+
4. Create and activate a virtual environment:
98+
99+
```sh
100+
python3 -m venv env
101+
source env/bin/activate
102+
pip install --upgrade pip
103+
```
104+
105+
5. Install the `model-card-toolkit` development package in editable mode:
106+
107+
```sh
108+
pip install -e ".[test]"
109+
```
110+
111+
When you install the library in editable mode (with the `-e` flag), your local
112+
changes will be picked up without needing to re-install the library.
113+
114+
### Re-generating protobuf stub code
115+
116+
If you make changes to a `.proto` file, you should re-generate the
117+
protobuf stub code before using it. The command used to do this is
118+
automatically invoked once when you first install `model-card-toolkit` in
119+
editable mode, but further stub generation requires manual invocation.
120+
121+
```sh
122+
bazel run //model_card_toolkit:move_generated_files
123+
```
124+
125+
### Licenses
126+
127+
Include a license at the top of new files.
128+
129+
- [Python license example](https://github.com/tensorflow/model-card-toolkit/blob/master/setup.py#L1)
130+
- [Bash license example](https://github.com/tensorflow/model-card-toolkit/blob/master/model_card_toolkit/move_generated_files.sh#L2)
131+
132+
Bazel BUILD files also need to include a license section. See
133+
[BUILD example](https://github.com/tensorflow/model-card-toolkit/blob/master/model_card_toolkit/BUILD#L15).
134+
135+
**Do not** include a license at the top of Jinja template files.
136+
137+
### Python coding style
138+
139+
Changes to Model Card Toolkit Python code should conform to the
140+
[Google Python Style Guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md)
141+
with indentation width of 2 spaces.
142+
143+
### Testing your changes
144+
145+
#### Writing and updating unit tests
146+
147+
Include unit tests when you contribute new features, as they help to a) prove
148+
that your code works correctly, and b) guard against future breaking
149+
changes to lower maintenance costs. Bug fixes also generally require creating
150+
or updating unit tests, because the presence of bugs usually indicates insufficient
151+
test coverage.
152+
153+
In general, all Python files have at least one corresponding test file. For example,
154+
`awesome.py` should have a corresponding `awesome_test.py`.
155+
156+
#### Running unit tests
157+
158+
To run a specific test suite, e.g. `ModelCardTest`, run its test file:
159+
160+
```sh
161+
pytest model_card_toolkit/model_card_test.py
162+
```
24163

25-
## Community Guidelines
164+
Use the following command to run all unit tests:
26165

27-
This project follows [Google's Open Source Community
28-
Guidelines](https://opensource.google/conduct/).
166+
```sh
167+
pytest model_card_toolkit
168+
```

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.pytest.ini_options]
6+
addopts = "--verbose"
7+
python_files = "*_test.py"

setup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737
'tensorflow-model-analysis>=0.36.0,<0.42.0',
3838
'tensorflow-metadata>=1.5.0,<2.0.0',
3939
'ml-metadata>=1.5.0,<2.0.0',
40-
'dataclasses;python_version<"3.7"',
4140
]
4241

43-
TESTS_REQUIRE = ['tensorflow-datasets']
42+
TESTS_REQUIRE = [
43+
'pytest',
44+
'tensorflow-datasets',
45+
]
46+
4447
EXTRAS_REQUIRE = {'test': TESTS_REQUIRE}
4548

4649
# Get version from version module.
@@ -123,7 +126,7 @@ def run(self):
123126
package_data={
124127
'model_card_toolkit': ['schema/**/*.json', 'template/**/*.jinja']
125128
},
126-
python_requires='>=3.6,<4',
129+
python_requires='>=3.7,<4',
127130
install_requires=REQUIRED_PACKAGES,
128131
tests_require=TESTS_REQUIRE,
129132
extras_require=EXTRAS_REQUIRE,
@@ -137,7 +140,8 @@ def run(self):
137140
'Operating System :: OS Independent',
138141
'Programming Language :: Python :: 3',
139142
'Programming Language :: Python :: 3.7',
140-
'Programming Language :: Python :: 3 :: Only',
143+
'Programming Language :: Python :: 3.8',
144+
'Programming Language :: Python :: 3.9',
141145
'Topic :: Scientific/Engineering',
142146
'Topic :: Scientific/Engineering :: Mathematics',
143147
'Topic :: Scientific/Engineering :: Artificial Intelligence',

0 commit comments

Comments
 (0)