Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
8202037
Initial commit
jeffhandley Nov 14, 2014
ef7ef55
Initial commit
jeffhandley Nov 14, 2014
c4071e5
Initial commit
jeffhandley Nov 14, 2014
a6c382e
Adding to source control
emgarten Nov 21, 2014
6dc4fd9
ReadMe update
emgarten Nov 21, 2014
e7f638e
Initial commit
jeffhandley Dec 10, 2014
52bae7a
Initial commit
ranj-ini Jan 13, 2015
1a3cf1b
add readme for submodules
analogrelay Apr 24, 2015
7cbeef9
update readme
analogrelay Apr 24, 2015
dcb4cb1
Update README.md
analogrelay Apr 24, 2015
8bee23e
Update README.md
analogrelay Apr 24, 2015
3b228d9
remove common files pre-merge
analogrelay Apr 27, 2015
25e5ffe
Merge branch 'packaging/runtime-graph' into dev
analogrelay Apr 27, 2015
b0c563a
added common files
analogrelay Apr 27, 2015
22e0e84
prep for merge
analogrelay Apr 27, 2015
91af4d1
prep for merge
analogrelay Apr 27, 2015
b197c10
prep for merge
analogrelay Apr 27, 2015
4a72c6e
Merge branch 'protocol/merge' into dev
analogrelay Apr 27, 2015
19cb7cb
Merge branch 'versioning/merge' into dev
analogrelay Apr 27, 2015
76bd77f
Merge branch 'packaging/merge' into dev
analogrelay Apr 27, 2015
2fa29ba
prep for merge
analogrelay Apr 27, 2015
f749189
Merge branch 'nuget3/merge' into dev
analogrelay Apr 27, 2015
485c98a
prep for merge
analogrelay Apr 27, 2015
3e2e7be
Merge branch 'packaging/merge' into dev
analogrelay Apr 27, 2015
c5ed80c
prep for merge
analogrelay Apr 27, 2015
afa4a9b
Merge branch 'protocol/merge' into dev
analogrelay Apr 27, 2015
2292fdd
Code cleanup
AndriySvyryd May 7, 2015
137161c
Code cleanup
AndriySvyryd May 8, 2015
f9730d7
Code cleanup
AndriySvyryd May 7, 2015
5a3d8f7
Update README.md
Aug 28, 2015
6d212b5
Update README.md
Aug 28, 2015
b976b0f
Creating NuGet3 folder
emgarten Sep 15, 2015
463dbe1
Add 'PackageManagement/' from commit '44ef5619241377f0b0552eec4e64f42…
emgarten Sep 15, 2015
e59fe43
Add 'VisualStudioExtension/' from commit '6611daeaf0c407570066988c751…
emgarten Sep 15, 2015
bc15f79
Updating build scripts
emgarten Sep 16, 2015
b151ed0
Strcture the tests folder as the src folder
Sep 27, 2015
db64001
Adding NuGet.Client readme
emgarten Nov 10, 2015
c6cbcd2
Changing the Readme
Nov 10, 2015
e04af38
Updating versions to 3.3.0 stable
emgarten Nov 24, 2015
5a3d79d
Change version to 3.4
Dec 2, 2015
a9e3382
Updating to xunit 2.1.0
emgarten Nov 18, 2015
c3bc8c8
Upgraded SDK to rc1-u1
alpaix Dec 3, 2015
c2be8e0
Support for running dnxcore50 tests
emgarten Jan 6, 2016
ee344a1
Adding VersionRange.ToNonSnapshotRange
emgarten Jan 12, 2016
fa28064
Normalized .xproj settings to match build script output
alpaix Jan 22, 2016
aa470bd
Adding imports for dnxcore50 to allow portable-net45+win8
emgarten Feb 10, 2016
efa8be9
3.4.0-* -> 3.4.0-rtm-*
emgarten Mar 4, 2016
e5bec86
Revert "3.4.0-* -> 3.4.0-rtm-*"
alpaix Mar 7, 2016
8ec1d09
DNX -> CLI
emgarten Mar 15, 2016
64e74bc
Updating to NETStandard.Library 1.5.0-rc2-23911
emgarten Mar 16, 2016
9bc2f9d
Updating xproj targets
emgarten Mar 17, 2016
eabb7a5
Upgraded NETStandard.Library version
alpaix Mar 25, 2016
da26c52
Removing SemVer 2.0.0 metadata from ToNormalizedString, adding ToFull…
emgarten Mar 24, 2016
cce6f27
Updating to rc2-23930
emgarten Mar 31, 2016
68d6bd1
Updating dotnet-test-xunit
emgarten Apr 1, 2016
8fbb94e
dotnet-test-xunit -> 1.0.0-dev-91790-12
emgarten Apr 2, 2016
439665a
Updating dotnet-xunit-test to dev-*
emgarten Apr 2, 2016
c6bc58f
Updating to rc2-23931
emgarten Apr 5, 2016
24832e5
NetStandardApp -> NetCoreApp
emgarten Apr 11, 2016
839f689
Lowering netstandard from 1.5 to 1.3 and adding compiler flags for co…
emgarten Apr 15, 2016
a642828
NuGet.Versioning clean up and optimizations
emgarten Apr 21, 2016
9add937
Removing VersionRange.IncludePrerelease
emgarten Apr 29, 2016
dccc961
Updating dotnet cli
emgarten May 17, 2016
1d5621c
Adding local folder resources for v2 and v3 folder structures
emgarten May 20, 2016
aa5f4c2
Fix project.json schema change warnings
pranavkm May 25, 2016
1c2b7f9
update cli to rc3-24128-00
Jun 7, 2016
0422a83
Fix https://github.com/NuGet/Home/issues/1816
Jun 21, 2016
2b9a4bf
Fixed failing tests
Jun 21, 2016
5444fc4
Update README.md
Jun 23, 2016
5475d54
Changing the dotnet cli version to the preview2 release, and changing…
toddm Jun 24, 2016
87570fe
Added AppVeyor validation build configuration
alpaix May 2, 2016
f654f30
Build NuGet client solution with VS "15" willow
alpaix Sep 7, 2016
41c11d8
Updated README.md with build instructions
alpaix Nov 8, 2016
bc7d2a7
Migrating projects to net core and merging client and core solutions
Mar 27, 2017
9351e3b
removing appveyor since we dont use it anymore (#1300)
mishra14 Apr 7, 2017
1d4ece4
#5068 Fix inconsistency in keeping track of NuGetVersion.OriginalVers…
xavierdecoster Apr 25, 2017
8ecff0b
Fix for VersionRange.PrettyPrint
emgarten Apr 30, 2017
7a57512
Adding VSTS build status badge in the README (#1500)
mishra14 Jun 19, 2017
961a05c
Changing the logo in the README to match the new logo in NuGet/Home (…
mishra14 Jul 29, 2017
ce5bd5c
Support for numeric only release labels with floating ranges
emgarten Aug 1, 2017
2c23519
updated license to cover all files in the repo
zhili1208 Sep 19, 2017
baa7288
removing SkipVS14 flag from build.ps1 and updating the readme (#1758)
Oct 19, 2017
19849b9
Updating the license based on CELA recommendation. (#1802)
Nov 10, 2017
08ab0e3
Make VersionRange.TryParse return false on null values instead of thr…
joelverhagen Dec 5, 2017
454e4bf
Update to xunit 2.3.1
emgarten Dec 11, 2017
5af63f0
Add NuGetVersion.Equals check
emgarten Dec 12, 2017
af8677e
Removing badge from readme (#1917)
Jan 2, 2018
c1a0dd7
update readme.md to include .net core sdk 1.0.5 as requirement (#2112)
Mar 21, 2018
ac98513
Use MSBuildProjectExtensionsPath for RestoreOutputPath (#2131)
Mar 31, 2018
d7109bb
Fixing artifacts location in the readme (#2161)
Apr 12, 2018
73e3a30
README.md: add hint of where to file bugs (#2150)
knocte Apr 18, 2018
95c6fb8
Added Equals method for VersionRange to compare floating ranges (#2435)
Sep 26, 2018
2c2e7c5
improve docs/PR template (#2669)
nkolev92 Jan 4, 2019
ffe9714
Fix '*' normalization - make it round trippable (#3079)
nkolev92 Oct 30, 2019
06e36ac
Adding basic coding guidelines/workflows for the NuGet contributor (#…
nkolev92 Jan 10, 2020
3c651c4
Update NuGetVersion.TryParseStrict() to return appropriate value, bas…
VonOgre Mar 6, 2020
71aba44
Support floating prerelease and stable packages at the same time with…
nkolev92 Mar 17, 2020
602981c
Enable cross-platform package signature verification for restore (#3458)
heng-liu Jun 20, 2020
1024db1
Add SemanticVersionConverter (#3442)
thomaslevesque Jul 13, 2020
90ab3cc
automatic formatting (#3587)
zkat Aug 26, 2020
d60bed0
Make comparer static properties idempotent (#3782)
dtivel Dec 1, 2020
a822cb8
Restrict nuget version range allows incorrect ranges (#3917)
erdembayar Mar 27, 2021
521729f
SemanticVersion exceptions use Resource Strings (#3973)
donnie-msft Apr 1, 2021
eaf66b6
Make VersionRange.TryParse handle single-number version specs (#3991)
louis-z Apr 16, 2021
eef9248
Fix broken logo image (#4336)
mairaw Nov 17, 2021
76c6282
Relocate code to target directories
pombredanne Apr 1, 2022
615210f
Add ABOUT file and LICENSE
pombredanne Apr 1, 2022
3526346
Move to univers test directory
pombredanne Apr 1, 2022
725c4e2
Merge remote-tracking branch 'nuget/dev' into main
pombredanne Apr 1, 2022
d5a4fe8
Rename script to Python
pombredanne Apr 1, 2022
c7884d5
Rename C# files to .py
pombredanne Apr 1, 2022
34fbb9d
Port NuGet version tests to Python
pombredanne Apr 26, 2022
426181e
Merge remote-tracking branch 'origin/main' into nuget-versions
pombredanne Apr 26, 2022
067cb00
Move scripts to tests directory
pombredanne Apr 26, 2022
775c448
Correct ABOUT license for nuget tests
pombredanne Apr 26, 2022
1c099ec
Port partially Nuget version tests
pombredanne Apr 26, 2022
7eeaf4f
Merge branch 'main' into nuget-versions
pombredanne May 4, 2022
a656d23
Ignore NuGet floating range tests for now
pombredanne May 4, 2022
27f8e71
Format code
pombredanne May 4, 2022
b575744
Remove weird test
pombredanne May 4, 2022
a595e71
Make NuGet version tests pass
pombredanne May 4, 2022
943cea1
Remove tests for unused code
pombredanne May 4, 2022
796e194
Port nuget tests to Univers
pombredanne May 4, 2022
d5ee2ec
Rename NuGet tests with nuget prefix
pombredanne May 4, 2022
2f81985
Merge remote-tracking branch 'origin/main' into nuget-versions
pombredanne May 18, 2022
05f6a3e
Add md extension to Markdown file
pombredanne May 18, 2022
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
119 changes: 103 additions & 16 deletions src/univers/nuget.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
# Nuget version utility originally from:
# https://raw.githubusercontent.com/google/osv/f5647ad2f746685b08debfba0293e442f2fb9945/lib/osv/nuget.py
# Copyright 2022 Google LLC
# modified by nexB and others for integration in the Univers library
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download.

import functools
import re
Expand Down Expand Up @@ -129,8 +123,13 @@ def normalize(version):


def _extract_revision(str_version):
"""Extract revision (4th component) from version number (if any)."""
"""
Extract revision from ``str_version`` and return a tuple of:
(dotted version string without revision, revision integer).
The revision is the 4th numeric dotted component of a NuGet version.
"""
# e.g. '1.0.0.0-prerelease'
# note: each match group contains its leading dot.
pattern = re.compile(r"^(\d+)(\.\d+)(\.\d+)(\.\d+)(.*)")
match = pattern.match(str_version)
if not match:
Expand All @@ -142,20 +141,32 @@ def _extract_revision(str_version):
)


class InvalidNuGetVersion(Exception):
pass


@functools.total_ordering
class Version:
"""NuGet version."""

def __init__(self, base_semver, revision):
def __init__(self, base_semver, revision=0):
self._base_semver = base_semver
if self._base_semver.prerelease:
# TODO: why lowercasing this and not the build and why here and now?
self._base_semver = self._base_semver.replace(prerelease=base_semver.prerelease.lower())
self._revision = revision
self._revision = revision or 0
self._original_version = None

def __eq__(self, other):
return self._base_semver == other._base_semver and self._revision == other._revision
return (
isinstance(other, Version)
and self._base_semver == other._base_semver
and self._revision == other._revision
)

def __lt__(self, other):
if not isinstance(other, Version):
return NotImplemented
if self._base_semver.replace(prerelease="") == other._base_semver.replace(prerelease=""):
# If the first three components are the same, compare the revision.
if self._revision != other._revision:
Expand All @@ -166,6 +177,82 @@ def __lt__(self, other):

@classmethod
def from_string(cls, str_version):
if not str_version:
return

str_version = str_version.strip()
if " " in str_version:
raise InvalidNuGetVersion(f"version cannot contain spaces: {str_version}")

if not any(c.isdigit() for c in str_version):
raise InvalidNuGetVersion(f"version does not contain any digit: {str_version}")

original = str_version
str_version = coerce(str_version)
str_version, revision = _extract_revision(str_version)
return Version(parse(str_version), revision)
vers = Version(base_semver=parse(str_version), revision=revision)
vers._original_version = original
return vers

def __repr__(self):
return f"Version<{self.to_string()}>"

def to_string(self, with_empty_revision=False, include_prerelease=True, include_build=True):
major = self.major or "0"
minor = self.minor or "0"
patch = self.patch or "0"

if with_empty_revision:
revision = self.revision and f".{self.revision}" or ".0"
else:
revision = self.revision and f".{self.revision}" or ""

if include_prerelease:
prerelease = self.prerelease and f"-{self.prerelease}" or ""
else:
prerelease = ""
if include_build:
build = self.build and f"+{self.build}" or ""
else:
build = ""

return f"{major}.{minor}.{patch}{revision}{prerelease}{build}"

def __str__(self):
return self.to_string(
with_empty_revision=False, include_prerelease=True, include_build=True
)

@property
def base_version(self):
"""
Return the base version dotted string composed of the four numerical
segments including revision and ignoring prerelease and build.
"""
return self.to_string(
with_empty_revision=True, include_prerelease=False, include_build=False
)

@property
def major(self):
return self._base_semver.major

@property
def minor(self):
return self._base_semver.minor

@property
def patch(self):
return self._base_semver.patch

@property
def revision(self):
return self._revision

@property
def prerelease(self):
return self._base_semver.prerelease and self._base_semver.prerelease or ""

@property
def build(self):
return self._base_semver.build and self._base_semver.build or ""
2 changes: 1 addition & 1 deletion src/univers/nuget.py.ABOUT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
about_resource: nuget.py
package_url: pkg:github/google/osv@0.0.14#lib/osv/nuget.py
copyright: Copyright 2022 Google LLC
copyright: Copyright 2022 Google LLC and others
download_url: https://raw.githubusercontent.com/google/osv/f5647ad2f746685b08debfba0293e442f2fb9945/lib/osv/nuget.py
license_expression: apache-2.0
homepage_url: https://github.com/google/osv/
Expand Down
201 changes: 201 additions & 0 deletions tests/data/apache-2.0.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading