Skip to content

Commit

Permalink
sagemathgh-38914: Replace os.uname by more universal platform.system
Browse files Browse the repository at this point in the history
    
`os.uname` is not available on Windows, so we replace it by
`platform.system`. Also replace the `UNAME` variable in `sage.env` which
is was only used in one place.

Extracted from sagemath#38872

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38914
Reported by: Tobias Diez
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Nov 13, 2024
2 parents 1badf10 + e78be76 commit 1bffa69
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/sage/doctest/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
#*****************************************************************************

import multiprocessing
import os
import platform

# With OS X, Python 3.8 defaults to use 'spawn' instead of 'fork' in
# multiprocessing, and Sage doctesting doesn't work with 'spawn'. See
# trac #27754.
if os.uname().sysname == 'Darwin':
if platform.system() == 'Darwin':
multiprocessing.set_start_method('fork', force=True)
Array = multiprocessing.Array

Expand Down
3 changes: 2 additions & 1 deletion src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@


import os
import platform
import sys
import time
import signal
Expand Down Expand Up @@ -80,7 +81,7 @@
# With OS X, Python 3.8 defaults to use 'spawn' instead of 'fork' in
# multiprocessing, and Sage doctesting doesn't work with 'spawn'. See
# trac #27754.
if os.uname().sysname == 'Darwin':
if platform.system() == 'Darwin':
multiprocessing.set_start_method('fork', force=True)


Expand Down
2 changes: 1 addition & 1 deletion src/sage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from typing import Optional
import sage
import platform
import os
import socket
import sys
Expand Down Expand Up @@ -165,7 +166,6 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st


# system info
UNAME = var("UNAME", os.uname()[0])
HOSTNAME = var("HOSTNAME", socket.gethostname())
LOCAL_IDENTIFIER = var("LOCAL_IDENTIFIER", "{}.{}".format(HOSTNAME, os.getpid()))

Expand Down
3 changes: 2 additions & 1 deletion src/sage/interfaces/singular.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
# ****************************************************************************

import os
import platform
import re
import sys
import pexpect
Expand Down Expand Up @@ -407,7 +408,7 @@ def __init__(self, maxread=None, script_subdirectory=None,
restart_on_ctrlc=True,
verbose_start=False,
logfile=logfile,
eval_using_file_cutoff=100 if os.uname()[0] == "SunOS" else 1000)
eval_using_file_cutoff=100 if platform.system() == "SunOS" else 1000)
self.__libs = []
self._prompt_wait = prompt
self.__to_clear = [] # list of variable names that need to be cleared.
Expand Down
3 changes: 2 additions & 1 deletion src/sage/misc/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
---------------------
"""

import platform
from sage.structure.sage_object import SageObject


Expand Down Expand Up @@ -66,7 +67,7 @@ def default_viewer(viewer=None):
PDF_VIEWER = BROWSER
PNG_VIEWER = BROWSER

elif os.uname()[0] == 'Darwin':
elif platform.system() == 'Darwin':
# Simple on OS X, since there is an open command that opens
# anything, using the user's preferences.
BROWSER = 'open -W'
Expand Down
3 changes: 2 additions & 1 deletion src/sage_docbuild/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import errno
import os
import platform
import traceback
from typing import Optional

Expand Down Expand Up @@ -193,7 +194,7 @@ def build_many(target, args, processes=None):
# With OS X, Python 3.8 defaults to use 'spawn' instead of 'fork'
# in multiprocessing, and Sage docbuilding doesn't work with
# 'spawn'. See trac #27754.
if os.uname().sysname == "Darwin":
if platform.system() == "Darwin":
set_start_method("fork", force=True)
from queue import Empty

Expand Down
6 changes: 3 additions & 3 deletions src/sage_setup/setenv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set some environment variables in the running process

import os
import sage.env
import platform
from pathlib import Path

def _environ_prepend(var, value, separator=':'):
Expand All @@ -12,7 +12,7 @@ def _environ_prepend(var, value, separator=':'):
os.environ[var] = value

def setenv():
from sage.env import UNAME, SAGE_LOCAL, SAGE_VENV, SAGE_ARCHFLAGS, SAGE_PKG_CONFIG_PATH
from sage.env import SAGE_LOCAL, SAGE_VENV, SAGE_ARCHFLAGS, SAGE_PKG_CONFIG_PATH

##
## from sage-env:
Expand All @@ -32,7 +32,7 @@ def setenv():
_environ_prepend('CPATH', f'{SAGE_LOCAL}/include')
_environ_prepend('LDFLAGS', f'-L{SAGE_LOCAL}/lib -Wl,-rpath,{SAGE_LOCAL}/lib',
separator=' ')
if UNAME == 'Linux':
if platform.system() == 'Linux':
_environ_prepend('LDFLAGS', f'-Wl,-rpath-link,{SAGE_LOCAL}/lib',
separator=' ')
if Path(SAGE_VENV).resolve() != Path(SAGE_LOCAL).resolve():
Expand Down

0 comments on commit 1bffa69

Please sign in to comment.