Skip to content

Commit 8fc8c54

Browse files
committed
Add Nox commands & CONTRIBUTING instructions for Spyder submodule
1 parent fccd195 commit 8fc8c54

File tree

3 files changed

+152
-13
lines changed

3 files changed

+152
-13
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
path = spyder
33
url = https://github.com/spyder-ide/spyder.git
44
branch = 6.x
5+
update = rebase

CONTRIBUTING.md

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ If referring to a specific line or file, please be sure to provide a snippet of
5858
## Cloning the Repository
5959

6060
First, navigate to the [project repository](https://github.com/spyder-ide/spyder-api-docs) in your web browser and press the ``Fork`` button to make a personal copy of the repository on your own GitHub account.
61-
Then, click the ``Clone or Download`` button on your repository, copy the link and run the following on the command line to clone the repo:
61+
Then, click the ``Clone or Download`` button on your repository, copy the link and run the following on the command line to clone the repo (with submodules):
6262

6363
```shell
64-
git clone <LINK-TO-YOUR-REPO>
64+
git clone --recurse-submodules <LINK-TO-YOUR-REPO>
6565
```
6666

6767
After cloning the repository, navigate to its new directory using the `cd` command:
@@ -119,6 +119,22 @@ For advanced users, if you'd prefer to also have your own local environment with
119119
**Note**: You may need to substitute ``python3`` for ``python`` in the commands below on some Linux distros where ``python`` isn't mapped to ``python3`` (yet).
120120

121121

122+
### Configure Git
123+
124+
Make sure to set the upstream Git remote to the official Spyder-API-Docs repo with:
125+
126+
```shell
127+
git remote add upstream https://github.com/spyder-ide/spyder-api-docs.git
128+
```
129+
130+
It's also a good idea to configure Git to automatically pull, checkout and push submodules:
131+
132+
```shell
133+
git config --local submodule.recurse true
134+
git config --local push.recurseSubmodules check
135+
```
136+
137+
122138
### Create and activate a fresh environment
123139

124140
We highly recommend you create and activate a virtual environment to avoid any conflicts with other packages on your system or causing any other issues.
@@ -178,15 +194,6 @@ python -m pip install -r requirements.txt
178194
```
179195

180196

181-
### Add the upstream remote
182-
183-
Make sure to set the upstream Git remote to the official Spyder-API-Docs repo with:
184-
185-
```shell
186-
git remote add upstream https://github.com/spyder-ide/spyder-api-docs.git
187-
```
188-
189-
190197

191198
## Installing and Using the Pre-Commit Hooks
192199

@@ -295,7 +302,40 @@ git switch -c <FEATURE-BRANCH>
295302
```
296303

297304

298-
### Commit your changes
305+
### Sync the latest Spyder docstrings (optional)
306+
307+
*If* your pull request requires the latest docstring changes from the Spyder repo, or there's a reason to manually update them, you can update the submodule to the latest stable branch either with Nox:
308+
309+
```shell
310+
nox -s sync-spyder
311+
```
312+
313+
or manually:
314+
315+
```shell
316+
git submodule update --remote
317+
```
318+
319+
**Note**: If using the manual command and you've checked out the submodule to a topic branch tracking your fork rather than the upstream Spyder repository, you'll need to either check out `6.x` first (setting it to track the main Spyder repo if it isn't already):
320+
321+
```shell
322+
cd spyder
323+
git switch 6.x
324+
git --set-upstream-to upstream 6.x # If required
325+
cd ..
326+
```
327+
328+
Or, to integrate the changes into your own branch (assuming `upstream` is the Spyder repository):
329+
330+
```shell
331+
cd spyder
332+
git fetch upstream 6.x
333+
git rebase FETCH_HEAD
334+
cd ..
335+
```
336+
337+
338+
### Make and commit your changes
299339

300340
Once you've made and tested your changes, add them to the staging area, and then commit them with a descriptive message.
301341
Commit messages should be

noxfile.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _run(session):
230230
session.run(*posargs)
231231

232232

233-
@nox.session()
233+
@nox.session
234234
def run(session):
235235
"""Run any command."""
236236
session.notify("_execute", posargs=([_run], *session.posargs))
@@ -257,6 +257,22 @@ def clean(session):
257257
_clean(session)
258258

259259

260+
def _sync_spyder(session):
261+
"""Sync the latest docstrings from upstream Spyder into the submodule."""
262+
foreach_cmd = ["git", "submodule", "--quiet", "foreach"]
263+
session.run(
264+
*foreach_cmd,
265+
"git fetch upstream 6.x && git rebase FETCH_HEAD",
266+
external=True,
267+
)
268+
269+
270+
@nox.session(name="sync-spyder")
271+
def sync_spyder(session):
272+
"""Sync the latest docstrings from upstream Spyder into the submodule."""
273+
_sync_spyder(session)
274+
275+
260276
# --- Set up --- #
261277

262278

@@ -323,6 +339,41 @@ def setup_remotes(session):
323339
_setup_remotes(session)
324340

325341

342+
def _setup_submodule_remotes(session):
343+
"""Set up the upstream submodule remote to point to the Spyder repo."""
344+
foreach_cmd = ["git", "submodule", "--quiet", "foreach"]
345+
spyder_repo = "spyder"
346+
347+
# Check if an upstream remote already exists
348+
existing_remotes = (
349+
session.run(
350+
*foreach_cmd,
351+
"git remote",
352+
external=True,
353+
silent=True,
354+
log=False,
355+
).strip().split("\n")
356+
)
357+
358+
if "upstream" in existing_remotes:
359+
return
360+
361+
spyder_repo_url = REPO_URL_HTTPS.format(user=ORG_NAME, repo=spyder_repo)
362+
session.run(
363+
*foreach_cmd,
364+
f"git remote add upstream '{spyder_repo_url}'",
365+
external=True,
366+
)
367+
368+
session.run(*foreach_cmd, "git fetch --all", external=True)
369+
370+
371+
@nox.session(name="setup-submodule-remotes")
372+
def setup_submodule_remotes(session):
373+
"""Set up the upstream submodule remote to point to the Spyder repo."""
374+
_setup_submodule_remotes(session)
375+
376+
326377
def _ignore_revs(session):
327378
"""Configure the Git ignore revs file to the repo default."""
328379
if not IGNORE_REVS_FILE:
@@ -342,6 +393,50 @@ def ignore_revs(session):
342393
_ignore_revs(session)
343394

344395

396+
def _config_submodules(session):
397+
"""Configure Git to automatically recurse into Git submodules."""
398+
session.run(
399+
"git",
400+
"config",
401+
"--local",
402+
"submodule.recurse",
403+
"true",
404+
external=True,
405+
)
406+
session.run(
407+
"git",
408+
"config",
409+
"--local",
410+
"push.recurseSubmodules",
411+
"check",
412+
external=True,
413+
)
414+
415+
416+
@nox.session(name="config-submodules")
417+
def config_submodules(session):
418+
"""Initialize and download all Git submodules."""
419+
_config_submodules(session)
420+
421+
422+
423+
def _init_submodules(session):
424+
"""Initialize and download all Git submodules."""
425+
session.run(
426+
"git",
427+
"submodule",
428+
"update",
429+
"--init",
430+
external=True,
431+
)
432+
433+
434+
@nox.session(name="init-submodules")
435+
def init_submodules(session):
436+
"""Initialize and download all Git submodules."""
437+
_init_submodules(session)
438+
439+
345440
@nox.session()
346441
def setup(session):
347442
"""Set up the project; pass --https or --ssh to specify Git URL type."""
@@ -350,6 +445,9 @@ def setup(session):
350445
posargs=(
351446
[
352447
_ignore_revs,
448+
_config_submodules,
449+
_init_submodules,
450+
_setup_submodule_remotes,
353451
_setup_remotes,
354452
_install_hooks,
355453
_clean,

0 commit comments

Comments
 (0)