Skip to content

Commit 7541c50

Browse files
committed
Add freethreaded input
1 parent 24d9e13 commit 7541c50

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import sys
22

3-
def check_version(version):
3+
def check_version(version, freethreaded):
44
split_version = version.split('.')
55
if int(split_version[0]) != sys.version_info[0]:
66
return False
77
if split_version[1] != 'x' and int(split_version[1]) != sys.version_info[1]:
88
return False
99
if split_version[2] != 'x' and int(split_version[2].split('-')[0]) != sys.version_info[2]:
1010
return False
11+
if freethreaded:
12+
try:
13+
if sys._is_gil_enabled():
14+
return False
15+
except:
16+
return False
1117
return True
1218

1319
if __name__ == '__main__':
1420
version = sys.argv[1]
21+
freethreaded = False
22+
if version.endswith("t"):
23+
freethreaded = True
24+
version = version[:-1]
1525
while version.count('.') < 2:
1626
version += '.x'
17-
if not check_version(version):
27+
if not check_version(version, freethreaded):
1828
raise ValueError('Expected python version to be ' + str(version) + ', got ' + str(sys.version_info.major) + '.' + str(sys.version_info.minor) + '.' + str(sys.version_info.micro) + '.')

.github/scripts/create_python_matrix.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
minor = int(splits[1])
2424
if major == 3 and minor >= 8 and short_tag not in json_dict['python-version']:
2525
json_dict['python-version'].append(short_tag)
26+
if minor >= 13:
27+
json_dict['python-version'].append(f"{short_tag}t")
2628

2729
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
2830
print(f'matrix={json.dumps(json_dict)}', file=fh)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ For a more complete view on the actions see [action.yml](action.yml) or look in
3030
In general you could replace the original action with this one and it should already work (all its supported inputs are also supported in this one):
3131

3232
```yaml
33-
- uses: MatteoH2O1999/setup-python@v5
33+
- uses: MatteoH2O1999/setup-python@v6
3434
with:
3535
python-version: '3.8'
3636
```
3737
3838
But if you wish for a more optimized experience you could use inputs exclusive to this action:
3939
4040
```yaml
41-
- uses: MatteoH2O1999/setup-python@v5
41+
- uses: MatteoH2O1999/setup-python@v6
4242
with:
4343
python-version: '3.8'
4444
allow-build: info
@@ -111,6 +111,7 @@ This action supports the following inputs (in bold are the names of the exclusiv
111111
|token|The token used to authenticate when fetching Python distributions from [actions/python-versions](https://github.com/actions/python-versions). When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.|example: `TokenString`|`github.token`|
112112
|cache-dependency-path|Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.|example: `path/to/dependency/files`|`''`|
113113
|update-environment|Set this option if you want the action to update environment variables.|`true`, `false`|`true`|
114+
|freethreaded| When 'true', use the freethreaded version of Python.|`true`, `false`|`false`|
114115
|**cache-build**|Whether to cache the built Python distribution to speed up successive runs.|`true`, `false`|`false`|
115116
|**allow-build**|Set the behavior of the action when [actions/setup-python](https://github.com/actions/setup-python) fails and has to be built from source.|`allow`, `info`, `warn`, `error`, `force`|`warn`|
116117

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ inputs:
3636
allow-prereleases:
3737
description: "When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython."
3838
default: false
39+
freethreaded:
40+
description: "When 'true', use the freethreaded version of Python."
41+
default: false
3942
outputs:
4043
python-version:
4144
description: "The installed Python or PyPy version. Useful when given a version range as input."
@@ -60,6 +63,7 @@ runs:
6063
allow-build: ${{ inputs.allow-build }}
6164
token: ${{ inputs.token }}
6265
allow-prereleases: ${{ inputs.allow-prereleases }}
66+
freethreaded: ${{ inputs.freethreaded }}
6367
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
6468
id: setup
6569
with:
@@ -70,6 +74,7 @@ runs:
7074
token: ${{ inputs.token }}
7175
cache-dependency-path: ${{ inputs.cache-dependency-path }}
7276
update-environment: ${{ inputs.update-environment }}
77+
freethreaded: ${{ steps.build.outputs.freethreaded }}
7378
- run: ${{ github.action_path }}/setup_pip.ps1
7479
shell: pwsh
7580
env:

0 commit comments

Comments
 (0)