Skip to content

Commit 17e8541

Browse files
committed
refactor: Use environments to install Conan
- Move previous conan/conan2 naming approach to Python environment solution. A wrapper that detects CONAN_SERIES environment var switchis between the two release series. Defaults to CONAN_SERIES=2. - Enable profile creation support by default Passing environment var CONAN_CREATE_PROFILE=false will prevent to generate a default profile. - Remove DUMMY_COMPILER_SETTINGS from plugin code as breaks any non-linux systems. Signed-off-by: Helio Chissini de Castro <[email protected]>
1 parent f26c647 commit 17e8541

File tree

6 files changed

+90
-21
lines changed

6 files changed

+90
-21
lines changed

Diff for: Dockerfile

+17-9
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ARG PYTHON_VERSION
136136
ARG PYENV_GIT_TAG
137137

138138
ENV PYENV_ROOT=/opt/python
139-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
139+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin
140140
RUN curl -kSs https://pyenv.run | bash \
141141
&& pyenv install -v $PYTHON_VERSION \
142142
&& pyenv global $PYTHON_VERSION
@@ -170,18 +170,26 @@ RUN pip install --no-cache-dir -U \
170170
wheel \
171171
&& pip install --no-cache-dir -U \
172172
Mercurial \
173-
conan=="$CONAN_VERSION" \
174173
pipenv=="$PYTHON_PIPENV_VERSION" \
175174
poetry=="$PYTHON_POETRY_VERSION" \
176175
poetry-plugin-export=="$PYTHON_POETRY_PLUGIN_EXPORT_VERSION" \
177176
python-inspector=="$PYTHON_INSPECTOR_VERSION" \
178177
setuptools=="$PYTHON_SETUPTOOLS_VERSION"
179-
RUN mkdir /tmp/conan2 && cd /tmp/conan2 \
180-
&& wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \
181-
&& tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\
182-
# Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager.
183-
&& mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \
184-
&& mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2
178+
179+
# Create conan environments
180+
COPY scripts/setup_conan.sh ${PYENV_ROOT}/bin/conan
181+
RUN eval "$(pyenv init - bash)" \
182+
&& eval "$(pyenv virtualenv-init -)" \
183+
&& pyenv virtualenv conan \
184+
&& pyenv activate conan \
185+
&& pip install conan==${CONAN_VERSION} \
186+
&& pyenv deactivate \
187+
&& pyenv virtualenv conan2 \
188+
&& pyenv activate conan2 \
189+
&& pip install conan==${CONAN2_VERSION} \
190+
&& pyenv deactivate \
191+
&& sudo chmod +x ${PYENV_ROOT}/bin/conan
192+
185193

186194
FROM scratch AS python
187195
COPY --from=pythonbuild /opt/python /opt/python
@@ -484,7 +492,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
484492

485493
# Python
486494
ENV PYENV_ROOT=/opt/python
487-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
495+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/plugins/pyenv-virtualenv/shims
488496
COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT
489497

490498
# NodeJS

Diff for: plugins/package-managers/conan/src/main/kotlin/Conan.kt

-7
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ class Conan(
112112
override val descriptor: PluginDescriptor = ConanFactory.descriptor,
113113
private val config: ConanConfig
114114
) : PackageManager("Conan") {
115-
companion object {
116-
internal val DUMMY_COMPILER_SETTINGS = arrayOf(
117-
"-s", "compiler=gcc",
118-
"-s", "compiler.libcxx=libstdc++",
119-
"-s", "compiler.version=11.1"
120-
)
121-
122115
internal const val SCOPE_NAME_DEPENDENCIES = "requires"
123116
internal const val SCOPE_NAME_DEV_DEPENDENCIES = "build_requires"
124117
}

Diff for: plugins/package-managers/conan/src/main/kotlin/ConanV1Handler.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.ossreviewtoolkit.model.PackageReference
3030
import org.ossreviewtoolkit.model.RemoteArtifact
3131
import org.ossreviewtoolkit.model.Scope
3232
import org.ossreviewtoolkit.model.VcsInfo
33-
import org.ossreviewtoolkit.plugins.packagemanagers.conan.Conan.Companion.DUMMY_COMPILER_SETTINGS
3433
import org.ossreviewtoolkit.plugins.packagemanagers.conan.Conan.Companion.SCOPE_NAME_DEPENDENCIES
3534
import org.ossreviewtoolkit.plugins.packagemanagers.conan.Conan.Companion.SCOPE_NAME_DEV_DEPENDENCIES
3635
import org.ossreviewtoolkit.utils.common.Os
@@ -63,8 +62,7 @@ internal class ConanV1Handler(private val conan: Conan) : ConanVersionHandler {
6362
"info",
6463
definitionFile.name,
6564
"--json",
66-
jsonFile.absolutePath,
67-
*DUMMY_COMPILER_SETTINGS
65+
jsonFile.absolutePath
6866
).requireSuccess()
6967
}
7068

Diff for: plugins/package-managers/conan/src/main/kotlin/ConanV2Handler.kt

-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
7070
lockfileName,
7171
"--out-file",
7272
jsonFile.absolutePath,
73-
*DUMMY_COMPILER_SETTINGS,
7473
definitionFile.name
7574
).requireSuccess()
7675
} else {
@@ -82,7 +81,6 @@ internal class ConanV2Handler(private val conan: Conan) : ConanVersionHandler {
8281
"json",
8382
"--out-file",
8483
jsonFile.absolutePath,
85-
*DUMMY_COMPILER_SETTINGS,
8684
definitionFile.name
8785
).requireSuccess()
8886
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.plugins.packagemanagers.python
21+
22+
import io.kotest.core.spec.style.WordSpec
23+
import io.kotest.matchers.should
24+
25+
import org.ossreviewtoolkit.analyzer.resolveSingleProject
26+
import org.ossreviewtoolkit.model.toYaml
27+
import org.ossreviewtoolkit.utils.test.getAssetFile
28+
import org.ossreviewtoolkit.utils.test.matchExpectedResult
29+
30+
class UvFunTest : WordSpec({
31+
"Python 3" should {
32+
"resolve dependencies correctly" {
33+
val definitionFile = getAssetFile("projects/synthetic/uv/uv.lock")
34+
val expectedResultFile = getAssetFile("projects/synthetic/uv-expected-output.yml")
35+
36+
val result = UvFactory.create().resolveSingleProject(definitionFile)
37+
38+
result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
39+
}
40+
}
41+
})

Diff for: scripts/setup_conan.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
conan_option=${CONAN_SERIES:-2}
4+
create_profile=${CONAN_CREATE_PROFILE:-true}
5+
6+
# Setup pyenv
7+
eval "$(pyenv init - bash)"
8+
eval "$(pyenv virtualenv-init -)"
9+
10+
# Setting up Conan 1.x
11+
if [[ "$conan_option" -eq 1 ]]; then # Setting up Conan 1.x series
12+
pyenv activate conan
13+
if "$create_profile"; then
14+
echo "Creating Conan profile."
15+
conan profile new default --detect
16+
# Docker has modern libc
17+
conan profile update settings.compiler.libcxx=libstdc++11 default
18+
fi
19+
echo "Using Conan 1.x series."
20+
elif [[ "$conan_option" -eq 2 ]]; then # Setting up Conan 2.x series
21+
pyenv activate conan2
22+
if "$create_profile"; then
23+
echo "Creating Conan profile."
24+
conan profile detect --force
25+
fi
26+
echo "Using Conan 2.x series."
27+
fi
28+
29+
# Runs conan from activated profile
30+
conan "$@"
31+

0 commit comments

Comments
 (0)