Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If system dotnet version is higher than dotnetcore2 runtime one, use that. #21

Merged
merged 5 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

CREDENTIAL_PROVIDER = (
"https://github.com/Microsoft/artifacts-credprovider/releases/download/"
+ "v0.1.20"
+ "v0.1.22"
+ "/Microsoft.NuGet.CredentialProvider.tar.gz"
)

Expand Down
17 changes: 15 additions & 2 deletions src/artifacts_keyring/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import sys
import warnings
import shutil

from . import __version__
from .support import Popen
Expand All @@ -32,7 +33,19 @@ def __init__(self):
self.exe = [tool_path]
else:
try:
from dotnetcore2.runtime import get_runtime_path
sys_version = tuple(int(i) for i in
subprocess.check_output(["dotnet", "--version"]).decode().strip().partition("-")[0].split("."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding by exception anti-pattern here, but l guess it simplifies the flow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aasim If anything, this is the opposite of coding by exception because we're handling too broad a base class. We could have replaced except Exception below with except (subprocess.CalledProcessError, OSError, TypeError, ValueError, OverflowError, UnicodeDecodeError) to handle all the possibilities, but there's really nothing gained by that.

Also, exception handling in general is not an anti-pattern in Python. It's often more efficient than look-before-you-leap style (unlike say, .NET, which is wildly inefficient).

except Exception:
sys_version = None
try:
from dotnetcore2.runtime import get_runtime_path, __version__ as runtime2version
try:
dotnetcore2version = tuple(int(i) for i in runtime2version.split("."))
if sys_version and sys_version > dotnetcore2version:
warnings.warn("Using system 'dotnet' with later version than dotnetcore2 package")
get_runtime_path = lambda: "dotnet"
except Exception:
pass
except ImportError as e:
message = (
"Unable to find dependency dotnetcore2; the tool will"
Expand All @@ -42,6 +55,7 @@ def __init__(self):
)
warnings.warn(message + str(e))
get_runtime_path = lambda: "dotnet"

tool_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"plugins",
Expand Down Expand Up @@ -134,4 +148,3 @@ def _get_credentials_from_credential_provider(self, url, is_retry):
return parsed["Username"], parsed["Password"]
except ValueError:
raise RuntimeError("Failed to get credentials: the Credential Provider's output could not be parsed as JSON.")