Skip to content

Commit 0812eed

Browse files
authored
Merge pull request #935 from I2PC/olz_action_send_statistics
Consider environment variable when configuring statistics
2 parents c567a02 + 7d5661d commit 0812eed

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
- name: Compile Xmipp will all dependencies in branch ${{ github.head_ref }} (if such branch exists, default is devel)
6262
env:
6363
BRANCH_NAME: ${{ github.head_ref }}
64+
SEND_INSTALLATION_STATISTICS: 'OFF'
6465
run: |
65-
echo -e "XMIPP_LINK_TO_SCIPION=OFF\nSEND_INSTALLATION_STATISTICS=OFF" > xmipp.conf
6666
./xmipp all -b $BRANCH_NAME --keep-output || (cat compilation.log && false)
67+
68+
- name: Cat
69+
run: cat xmipp.conf

installer/api.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ def sendApiPOST(retCode: int=0):
6161
url = url[0]
6262
conn = http.client.HTTPSConnection(url, timeout=2, context=ssl._create_unverified_context()) # Unverified context because url does not have an ssl certificate
6363

64-
# Send the POST request
65-
conn.request("POST", path, params, headers)
66-
67-
# Get response from server
68-
conn.getresponse()
69-
70-
# Close the connection
71-
conn.close()
64+
try:
65+
# Send the POST request
66+
conn.request("POST", path, params, headers)
67+
68+
# Get response from server
69+
conn.getresponse()
70+
71+
# Close the connection
72+
conn.close()
73+
except Exception as e:
74+
pass
7275

7376
####################### UTILS FUNCTIONS #######################
7477
def getOSReleaseName() -> str:

installer/constants/config.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from .main import INSTALL_PATH
2828

2929
# Variable names
30-
__SEND_INSTALLATION_STATISTICS = 'SEND_INSTALLATION_STATISTICS'
30+
SEND_INSTALLATION_STATISTICS = 'SEND_INSTALLATION_STATISTICS'
31+
__SEND_INSTALLATION_STATISTICS_ENV = 'SEND_INSTALLATION_STATISTICS'
3132
CMAKE = 'CMAKE'
3233
CC = 'CMAKE_C_COMPILER'
3334
CXX = 'CMAKE_CXX_COMPILER'
@@ -64,7 +65,7 @@
6465
COMPILATION_FLAGS = 'flags'
6566
CONFIG_VARIABLES = {
6667
TOGGLES: [
67-
__SEND_INSTALLATION_STATISTICS, CUDA, MPI, MATLAB, LINK_SCIPION, __BUILD_TESTING, __SKIP_RPATH
68+
__SEND_INSTALLATION_STATISTICS_ENV, CUDA, MPI, MATLAB, LINK_SCIPION, __BUILD_TESTING, __SKIP_RPATH
6869
],
6970
LOCATIONS: [
7071
CMAKE, CC, CXX, CMAKE_INSTALL_PREFIX, __PREFIX_PATH, __MPI_HOME,
@@ -99,13 +100,15 @@ def __getCudaCompiler() -> Optional[str]:
99100
nvcc = os.path.join(nvcc, __NVCC_EXE)
100101

101102
return nvcc
102-
103+
104+
def __getSendStatistics():
105+
return os.environ.get(__SEND_INSTALLATION_STATISTICS_ENV, ON)
103106

104107

105108
ON = 'ON'
106109
OFF = 'OFF'
107110
CONFIG_DEFAULT_VALUES = {
108-
__SEND_INSTALLATION_STATISTICS: ON,
111+
__SEND_INSTALLATION_STATISTICS_ENV: __getSendStatistics(),
109112
CMAKE: None,
110113
CUDA: ON,
111114
MPI: ON,
@@ -131,4 +134,4 @@ def __getCudaCompiler() -> Optional[str]:
131134
}
132135

133136
# Do not pass this variables to CMake, only for installer logic
134-
INTERNAL_LOGIC_VARS = [__SEND_INSTALLATION_STATISTICS, CMAKE]
137+
INTERNAL_LOGIC_VARS = [__SEND_INSTALLATION_STATISTICS_ENV, CMAKE]

xmipp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from installer.constants import (MODE_ALL, MODE_COMPILE_AND_INSTALL, MODE_CONFIG
3535
PARAM_JOBS, PARAM_BRANCH, PARAM_GIT_COMMAND, PARAM_TEST_PRO, PARAM_TEST_PRO, PARAM_TEST_FUNC, PARAM_MODEL_PATH,
3636
PARAM_MODELS_DIRECTORY, PARAM_KEEP_OUTPUT, PARAM_SHOW_TESTS, PARAM_TEST_NAME, PARAM_UPDATE,
3737
PARAM_OVERWRITE, BUILD_PATH, INSTALL_PATH, BUILD_TYPE, SOURCES_PATH, XMIPP_SOURCES, XMIPP,
38-
LOG_FILE, CMAKE_ERROR, MODE_GET_SOURCES, VERSION_FILE, PARAMS, LONG_VERSION, SHORT_VERSION)
38+
LOG_FILE, CMAKE_ERROR, MODE_GET_SOURCES, VERSION_FILE, PARAMS, LONG_VERSION, SHORT_VERSION, SEND_INSTALLATION_STATISTICS)
3939
from installer.utils import runStreamingJob, runJob
4040
from installer.parser import ModeHelpFormatter, GeneralHelpFormatter, ErrorHandlerArgumentParser, getParamNames
4141
from installer.config import readConfig, writeConfig
@@ -122,22 +122,25 @@ def modeCompileAndInstall(args: argparse.Namespace, configDict: Dict={}):
122122
logger.startLogFile(LOG_FILE)
123123
configDict = readConfig(CONFIG_FILE)
124124
if not getCMake(configDict):
125-
handleRetCode(CMAKE_ERROR, predefinedErrorCode=CMAKE_ERROR)
125+
apiPost = True if configDict.get(SEND_INSTALLATION_STATISTICS) == 'ON' else False
126+
handleRetCode(CMAKE_ERROR, predefinedErrorCode=CMAKE_ERROR, sendAPI=apiPost)
126127

127128
# Compile with CMake
128129
cmakeExecutable = getCMake(configDict)
129130
logger(getSectionMessage("Compiling with CMake"), forceConsoleOutput=True)
130131
retCode = runStreamingJob(f"{cmakeExecutable} --build {BUILD_PATH} --config {BUILD_TYPE} -j {args.jobs}",
131132
showOutput=True, substitute=True)
132-
handleRetCode(retCode, predefinedErrorCode=CMAKE_COMPILE_ERROR)
133+
apiPost = True if configDict.get(
134+
SEND_INSTALLATION_STATISTICS) == 'ON' else False
135+
handleRetCode(retCode, predefinedErrorCode=CMAKE_COMPILE_ERROR, sendAPI=apiPost)
133136

134137
# Install with CMake
135138
logger(getSectionMessage("Installing with CMake"), forceConsoleOutput=True)
136139
retCode = runStreamingJob(f"{cmakeExecutable} --install {BUILD_PATH} --config {BUILD_TYPE}",
137140
showOutput=True, substitute=True)
138-
handleRetCode(retCode, predefinedErrorCode=CMAKE_INSTALL_ERROR)
141+
handleRetCode(retCode, predefinedErrorCode=CMAKE_INSTALL_ERROR, sendAPI=apiPost)
139142

140-
def modeConfigBuild(configDict: Dict={}):
143+
def modeConfigBuild(configDict: Dict={}, sendAPIPost: bool=False):
141144
"""
142145
### Configures the project using CMake.
143146
@@ -153,13 +156,13 @@ def modeConfigBuild(configDict: Dict={}):
153156
# Check if CMake exists
154157
cmakeExecutable = getCMake(configDict)
155158
if not getCMake(configDict):
156-
handleRetCode(CMAKE_ERROR, predefinedErrorCode=CMAKE_ERROR)
159+
handleRetCode(CMAKE_ERROR, predefinedErrorCode=CMAKE_ERROR, sendAPI=sendAPIPost)
157160

158161
logger(getSectionMessage("Configuring with CMake"), forceConsoleOutput=True)
159162
configureCmd = f"{cmakeExecutable} -S . -B {BUILD_PATH} -D CMAKE_BUILD_TYPE={BUILD_TYPE}"
160163
configureCmd += f" {getCMakeVarsStr(configDict)}"
161164
retCode = runStreamingJob(configureCmd, showOutput=True, substitute=True)
162-
handleRetCode(retCode, predefinedErrorCode=CMAKE_CONFIGURE_ERROR)
165+
handleRetCode(retCode, predefinedErrorCode=CMAKE_CONFIGURE_ERROR, sendAPI=sendAPIPost)
163166

164167
def modeConfig(overwrite: bool=False) -> Dict:
165168
"""
@@ -232,7 +235,6 @@ def modeTest(args: argparse.Namespace):
232235
logger("Running all tests--------------------------------------", forceConsoleOutput=True)
233236
runTests(PARAMS[PARAM_TEST_PRO][LONG_VERSION])
234237
elif args.allFuncs:
235-
print(args.allPrograms)
236238
runTests(PARAMS[PARAM_TEST_FUNC][LONG_VERSION])
237239

238240
elif args.testName:
@@ -265,7 +267,7 @@ def modeAll(args: argparse.Namespace):
265267
modeGetSources(args)
266268

267269
# Configure with CMake
268-
modeConfigBuild(configDict=configDict)
270+
modeConfigBuild(configDict=configDict, sendAPIPost=True)
269271

270272
# Compile and install with CMake
271273
modeCompileAndInstall(args, configDict=configDict)
@@ -282,8 +284,8 @@ def runSelectedMode(parser: ErrorHandlerArgumentParser, args: argparse.Namespace
282284
if args.mode == MODE_ADD_MODEL:
283285
modeAddModel(args)
284286
elif args.mode == MODE_ALL:
285-
modeAll(args)
286287
sendAPI = True
288+
modeAll(args)
287289
elif args.mode == MODE_CLEAN_ALL:
288290
modeCleanAll()
289291
elif args.mode == MODE_CLEAN_BIN:
@@ -292,8 +294,8 @@ def runSelectedMode(parser: ErrorHandlerArgumentParser, args: argparse.Namespace
292294
modeCompileAndInstall(args)
293295
sendAPI = True
294296
elif args.mode == MODE_CONFIG_BUILD:
295-
modeConfigBuild()
296297
sendAPI = True
298+
modeConfigBuild()
297299
elif args.mode == MODE_CONFIG:
298300
modeConfig(overwrite=args.overwrite)
299301
elif args.mode == MODE_GET_MODELS:
@@ -312,7 +314,9 @@ def runSelectedMode(parser: ErrorHandlerArgumentParser, args: argparse.Namespace
312314
exitXmipp(retCode=1)
313315

314316
# Send API message
315-
if sendAPI and os.path.exists(VERSION_FILE):
317+
apiPost = True if readConfig(CONFIG_FILE).get(
318+
SEND_INSTALLATION_STATISTICS) == 'ON' else False
319+
if sendAPI and apiPost and os.path.exists(VERSION_FILE):
316320
sendApiPOST()
317321

318322
# Print success message for specific modes

0 commit comments

Comments
 (0)