Skip to content

Commit 24bd344

Browse files
Select/exclude a branch from processing (#69)
* Read and parse CLI ``--branches`` option * Process the selected and excluded branches. * Refactor: Moved the function responsible for getting all versions to `GitVersions` * testing infra for branch selection * simplify branch selection for maintainability * moved branch selection infra to `sphinx_versioned.lib`. * Modified gh-action to accomodate branch selection/exclusion. * updated docstrings * updated documentation * changelog
1 parent 9afa5d7 commit 24bd344

File tree

11 files changed

+323
-133
lines changed

11 files changed

+323
-133
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8-
workflow_dispatch:
98

109
jobs:
1110
legacy-build:
@@ -15,7 +14,7 @@ jobs:
1514
python-version: ["3.9"]
1615
steps:
1716
- name: Check out repository
18-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1918
- name: Check out that no sensitive environment variable is shared
2019
run: env
2120
- name: Set up Python ${{ matrix.python-version }}
@@ -46,7 +45,7 @@ jobs:
4645
toxenv: py310
4746
steps:
4847
- name: Check out repository
49-
uses: actions/checkout@v3
48+
uses: actions/checkout@v4
5049
- name: Check out that no sensitive environment variable is shared
5150
run: env
5251
- name: Set up Python ${{ matrix.python-version }}
@@ -68,7 +67,7 @@ jobs:
6867
python-version: ["3.10"]
6968
steps:
7069
- name: Check out repository
71-
uses: actions/checkout@v3
70+
uses: actions/checkout@v4
7271
- name: Check out that no sensitive environment variable is shared
7372
run: env
7473
- name: Set up Python ${{ matrix.python-version }}
@@ -97,7 +96,7 @@ jobs:
9796
toxenv: py310
9897
steps:
9998
- name: Check out repository
100-
uses: actions/checkout@v3
99+
uses: actions/checkout@v4
101100
- name: Check out that no sensitive environment variable is shared
102101
run: env
103102
- name: Set up Python ${{ matrix.python-version }}
@@ -112,7 +111,7 @@ jobs:
112111
run: |
113112
tox -e ${{ matrix.toxenv }}
114113
115-
theme-build:
114+
theme-feat-build:
116115
runs-on: ${{ matrix.os }}
117116
needs: py-build
118117
strategy:
@@ -127,9 +126,12 @@ jobs:
127126
- os: ubuntu-latest
128127
python-version: "3.10"
129128
toxenv: alabaster
129+
- os: ubuntu-latest
130+
python-version: "3.10"
131+
toxenv: branch_selection
130132
steps:
131133
- name: Check out repository
132-
uses: actions/checkout@v3
134+
uses: actions/checkout@v4
133135
- name: Check out that no sensitive environment variable is shared
134136
run: env
135137
- name: Set up Python ${{ matrix.python-version }}

docs/changes/69.feature.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Modified the ``--branch``/ ``-b`` to accomodate branch selection/exclusion. Now, any branch can be selected
2+
by mentioning it in ``--branch``/``--b`` and any can be excluded by adding a ``-`` infront of the branch/tag
3+
name in the cli argument.
4+
Like ``--branch main,-v1.0,v2.0`` will select ``main``, ``v2.0`` and will exclude ``v1.0``.

docs/install.rst

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,80 @@
44
Installation
55
============
66

7-
The ``sphinx-versioned-docs`` project has the following requirements.
7+
The ``sphinx-versioned-docs`` project has the following requirements.
88

99
.. _requirements-to-use:
1010

1111
Requirements
12-
============
13-
14-
.. code-block:: markdown
12+
------------
1513

16-
GitPython>=3.1.31
17-
loguru>=0.7.0
18-
setuptools>=66.0.0
19-
sphinx>=4.6.0
20-
typer>=0.9.0
21-
rich
14+
.. code-block:: markdown
2215
23-
Installing
24-
==========
16+
GitPython>=3.1.31
17+
loguru>=0.7.0
18+
setuptools>=66.0.0
19+
sphinx>=4.6.0
20+
typer>=0.9.0
2521
26-
Now, it can be installed via the following methods:
22+
Now, it can be installed via the following methods:
2723

28-
Installing using pip
29-
--------------------
24+
1. Installing using pip
25+
------------------------
3026

31-
For this you will require that python3 and `pip <https://pip.pypa.io/en/stable/installation/>`__ are already installed.
27+
For this you will require that python3 and `pip <https://pip.pypa.io/en/stable/installation/>`__ are already installed.
3228

33-
.. code-block:: console
29+
.. code-block:: console
3430
35-
$ pip install sphinx-versioned-docs
31+
$ pip install sphinx-versioned-docs
3632
37-
Installing using conda
38-
----------------------
33+
2. Installing using conda
34+
--------------------------
3935

40-
In this method, please make sure that anaconda/conda is properly installed:
36+
In this method, please make sure that anaconda/conda is properly installed:
4137

42-
.. code-block:: console
38+
.. code-block:: console
4339
44-
$ conda install sphinx-versioned-docs
40+
$ conda install sphinx-versioned-docs
4541
46-
In order to create a separate environment in conda, follow these instructions:
42+
In order to create a separate environment in conda, follow these instructions:
4743

48-
.. code-block:: console
44+
.. code-block:: console
4945
50-
$ conda create --name versioned
51-
$ conda activate versioned
52-
$ conda install sphinx-versioned-docs
46+
$ conda create --name versioned
47+
$ conda activate versioned
48+
$ conda install sphinx-versioned-docs
5349
54-
Installing from source
55-
----------------------
50+
3. Installing from source
51+
--------------------------
5652

57-
This method typically installs that lastest developer version of the package, however, it be used to install stable branches too.
53+
This method typically installs that lastest developer version of the package, however, it be used to install stable branches too.
5854

59-
To install the latest developer version:
55+
To install the latest developer version:
6056

61-
.. code-block:: console
57+
.. code-block:: console
6258
63-
$ git clone https://github.com/devanshshukla99/sphinx-versioned-docs
64-
$ cd sphinx-versioned-docs
65-
$ pip install .
59+
$ git clone https://github.com/devanshshukla99/sphinx-versioned-docs
60+
$ cd sphinx-versioned-docs
61+
$ pip install .
6662
67-
To install the latest stable release, specified via the ``<release tag>``:
63+
To install the latest stable release, specified via the ``<release tag>``:
6864

69-
.. code-block:: console
65+
.. code-block:: console
7066
71-
$ git clone https://github.com/devanshshukla99/sphinx-versioned-docs
72-
$ cd sphinx-versioned-docs
73-
$ git checkout <release tag>
74-
$ pip install .
67+
$ git clone https://github.com/devanshshukla99/sphinx-versioned-docs
68+
$ cd sphinx-versioned-docs
69+
$ git checkout <release tag>
70+
$ pip install .
7571
7672
.. _dev-version:
7773

78-
Installing the developer version
79-
--------------------------------
74+
4. Installing the developer version
75+
-------------------------------------
8076

81-
If you are interested in contributing to the project, then you can setup the developer environment by using:
77+
If you are interested in contributing to the project, then you can setup the developer environment by using:
8278

83-
.. code-block:: console
79+
.. code-block:: console
8480
85-
$ git clone https://github.com/devanshshukla99/sphinx-versioned-docs
86-
$ cd sphinx-versioned-docs
87-
$ pip install -e .[all]
81+
$ git clone https://github.com/devanshshukla99/sphinx-versioned-docs
82+
$ cd sphinx-versioned-docs
83+
$ pip install -e .[all]

docs/settings.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
Settings
55
========
66

7-
.. code-block::
7+
.. code-block:: console
88
9-
sphinx-versioned [OPTIONS]
9+
$ sphinx-versioned [OPTIONS]
1010
1111
The ``sphinx-versioned-docs`` reads options from two sources:
1212

docs/tutorial.rst

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ Make sure that you've already :ref:`installed <install>` it.
1212
Building versioned docs
1313
=======================
1414

15+
.. _initializing_sphinx:
16+
17+
Initializing project with sphinx and git
18+
----------------------------------------
19+
20+
If you have problems initializing sphinx and git, then follow these instructions, otherwise you can skip directly to :ref:`initializing sphinx-versioned-docs <initializing_versioned_docs>`
21+
22+
Before we begin make sure you have `sphinx <https://pypi.org/project/Sphinx/>`__ install and some git history already in your project.
23+
If not, read `first steps with sphinx <http://www.sphinx-doc.org/en/stable/tutorial.html>`_ first.
24+
If you just want something quick and dirty you can do the following:
25+
26+
.. code-block:: console
27+
28+
$ sphinx-quickstart docs -p projectname -a author -v version --makefile --no-sep -r version -l en -q
29+
$ git checkout -b feature_branch main # Create new branch from main.
30+
31+
$ echo -e "Test\n====\n\nSample Documentation" > docs/index.rst # Create one doc.
32+
$ git add .
33+
$ git commit -m "initial"
34+
35+
$ sphinx-versioned
36+
37+
.. _initializing_versioned_docs:
38+
39+
Initializing sphinx-versioned-docs
40+
----------------------------------
41+
1542
Before using the ``sphinx-versioned-docs`` to build a versioned documentation. Make sure you have following things done:
1643

1744
- [x] Project initialized.
@@ -33,49 +60,60 @@ you can run the following command to generate the versioned documentation:
3360
3461
$ sphinx-versioned
3562
36-
-----------------
63+
If you have problems initializing project and running sphinx, then follow at :ref:`initializing sphinx and git <initializing_sphinx>`.
3764

38-
If you have problems initializing sphinx and git, then follow these instructions:
65+
------------------------------
3966

40-
Before we begin make sure you have some Sphinx docs already in your project. If not, read `First Steps with Sphinx <http://www.sphinx-doc.org/en/stable/tutorial.html>`_ first. If you just want something quick
41-
and dirty you can do the following:
67+
Generated output
68+
----------------
4269

43-
.. code-block:: console
70+
After the build has succeded, your docs should be available in ``<output directory>/<branch>/index.html`` with a version selector menu/badge present.
4471

45-
$ sphinx-quickstart docs -p projectname -a author -v version --makefile --no-sep -r version -l en -q
46-
$ git checkout -b feature_branch main # Create new branch from main.
72+
.. note::
4773

48-
$ echo -e "Test\n====\n\nSample Documentation" > docs/index.rst # Create one doc.
49-
$ git add .
50-
$ git commit -m "initial"
74+
By default, ``sphinx-versioned-docs`` pre-builds the branches to see which of them fails; but this behaviour can be mitigated using the ``--no-prebuild`` argument.
5175

52-
$ sphinx-versioned
76+
.. note::
5377

54-
------------------------------
78+
Use ``--no-quite`` option to get output from the sphinx builder, adjust verbosity using ``-v``
79+
80+
---------------------------
81+
82+
Selecting/ Excluding branches and tags
83+
--------------------------------------
5584

5685
By default, ``sphinx-versioned-docs`` will try to build all tags and branches present in the git repo.
57-
However, to build some particular branch(s) and tag(s), they can be specified in the ``--branches`` argument as:
86+
However, this behaviour can be augmented using the ``--branch`` command-line-argument, to build/exclude
87+
some particular branch(s) and tag(s), they can be specified in the ``--branch`` argument as:
5888

59-
.. code-block:: console
89+
#. **For selecting a branch:** mention the branch/tag name in the CLI arugment like:
6090

61-
$ sphinx-versioned --branches "main, docs"
91+
.. code-block:: console
6292
63-
This command will build the ``main`` and ``docs`` branches.
64-
More such options are available at :ref:`options <settings>`.
93+
$ sphinx-versioned --branch "main,v2.0"
94+
$ sphinx-versioned --branch "+main,+v2.0"
6595
96+
Either of the two options above will select ``main``, ``v2.0`` and will only build these.
6697

98+
#. **For excluding a branch:** mention the branch/tag name with ``-`` in the CLI argument like:
6799

68-
After the build has succeded, your docs should be available in ``<output directory>/<branch>/index.html`` with a version selector menu/badge present.
100+
.. code-block:: console
69101
70-
.. note::
102+
$ sphinx-versioned --branch "-main,-v2.0"
71103
72-
By default, ``sphinx-versioned-docs`` pre-builds the branches to see which of them fails; but this behaviour can be mitigated using the ``--no-prebuild`` argument.
104+
The above command will build all available branches and tags except ``main``, ``v2.0``
73105

74-
.. note::
106+
#. **For selecting and excluding simultaneously:** mention the branch/tag name with ``-`` in the CLI argument like:
75107

76-
Use ``--no-quite`` option to get output from the sphinx builder, adjust verbosity using ``-v``
108+
.. code-block:: console
77109
78-
---------------------------
110+
$ sphinx-versioned --branch "main,-v2.0"
111+
112+
The above command will only build ``main`` and will exclude ``-v2.0`` (untouched because the package was only building ``main``).
113+
114+
More such options are available at :ref:`options <settings>`.
115+
116+
------------------------------
79117

80118
Deploy to github pages via github actions
81119
=========================================

0 commit comments

Comments
 (0)