-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e217fb0
Showing
17 changed files
with
1,834 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, | ||
body size, disability, ethnicity, gender identity and expression, level of | ||
experience, education, socio-economic status, nationality, personal | ||
appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an | ||
appointed representative at an online or offline event. Representation of a | ||
project may be further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at [email protected]. All | ||
complaints will be reviewed and investigated and will result in a response | ||
that is deemed necessary and appropriate to the circumstances. The project | ||
team is obligated to maintain confidentiality with regard to the reporter of | ||
an incident. Further details of specific enforcement policies may be posted | ||
separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], | ||
version 1.4, available at | ||
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2020, ActiveState Software | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# What Is This | ||
|
||
The langtools repo contains packages and tools that we at ActiveState have | ||
developed as part of the [ActiveState | ||
Platform](https://platform.activestate.com/). The platform provides automated | ||
language builds, where you can pick a language core and a set of packages to | ||
be built on a variety of platforms. Since building the platform requires us to | ||
understand a number of language package ecosystems, we are building tools for | ||
working with these ecosystems. | ||
|
||
## Version Parsing | ||
|
||
This repo contains a Go package for version parsing, | ||
`github.com/ActiveState/langtools/pkg/version`: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/ActiveState/langtools/pkg/version" | ||
) | ||
|
||
func main() { | ||
v, err := version.ParseGeneric("1.2") | ||
if err != nil { | ||
log.Fatalf("Could not parse 1.2 as a generic version: %s", err) | ||
} | ||
log.Printf("Parsed as %v", v.Decimal) | ||
} | ||
``` | ||
|
||
### `parseversion` Command Line Tool | ||
|
||
This repository also contains the code for a `parseversion` CLI tool. You can | ||
install this by running `go get | ||
github.com/ActiveState/langtools/cmd/parseversion`. Run `parseversion --help` | ||
for details on this tool. | ||
|
||
## Build Status | ||
|
||
[![CircleCI](https://circleci.com/gh/ActiveState/langtools.svg?style=svg)](https://circleci.com/gh/ActiveState/langtools) | ||
|
||
## Authors | ||
|
||
This library was created by: | ||
|
||
* Sean Fitzgerald | ||
* Jason Palmer | ||
* Dave Rolsky \<[email protected]\> | ||
* Tyler Santerre | ||
* Stephen Reichling | ||
|
||
## Copyright | ||
|
||
Copyright (c) 2020, ActiveState Software. | ||
All rights reserved. | ||
|
||
## License | ||
|
||
This software is licensed under the BSD 3-Clause License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/ActiveState/langtools/pkg/version" | ||
"gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
const appVersion = "0.0.1" | ||
|
||
func main() { | ||
pv, err := new() | ||
if err != nil { | ||
pv.app.FatalUsage("%s\n", err) | ||
} | ||
|
||
if pv.printVersion { | ||
fmt.Fprintf(os.Stdout, "version %s\n", appVersion) | ||
os.Exit(0) | ||
} | ||
|
||
count := len(pv.args) | ||
if count%2 == 1 || count == 0 { | ||
pv.app.FatalUsage("You must pass one or more pairs of arguments, where each pair consists of a type and version string.\n") | ||
} | ||
|
||
var output []*version.Version | ||
for i := 0; i < count; i += 2 { | ||
typ := pv.args[i] | ||
ver := pv.args[i+1] | ||
|
||
var parsed *version.Version | ||
|
||
switch typ { | ||
case "generic": | ||
parsed, err = version.ParseGeneric(ver) | ||
case "semver": | ||
parsed, err = version.ParseSemVer(ver) | ||
case "perl": | ||
parsed, err = version.ParsePerl(ver) | ||
case "python": | ||
parsed, err = version.ParsePython(ver) | ||
default: | ||
pv.app.FatalUsage("Unknown version type requested: %s\n", typ) | ||
} | ||
|
||
if err != nil { | ||
pv.app.FatalUsage("Error parsing %s as %s: %s\n", ver, typ, err) | ||
} | ||
|
||
output = append(output, parsed) | ||
} | ||
|
||
j, err := json.Marshal(output) | ||
if err != nil { | ||
log.Fatalf("Error marshalling %+v as JSON: %s", output, err) | ||
} | ||
|
||
fmt.Println(string(j)) | ||
} | ||
|
||
type parseversion struct { | ||
app *kingpin.Application | ||
printVersion bool | ||
args []string | ||
} | ||
|
||
const extraDocs = ` | ||
This command parses one or more versions and emits a JSON array containing one | ||
or more objects describing those versions. Currently these JSON obejcts have | ||
two keys: | ||
* "version" - The original string. | ||
* "sortable_version" - An array of strings. Each element of the array is a | ||
stringified decimal number. Taken as a whole, this array can be sorted | ||
_numerically_ against other versions of the same package. | ||
The following version types are available: | ||
* semver - A version following the semver specification (https://semver.org/) | ||
* python - A Python PEP440 or legacy version | ||
* perl - A Perl module version | ||
* generic - Anything not covered by another type, such as C libraries, etc. | ||
` | ||
|
||
func new() (*parseversion, error) { | ||
app := kingpin.New("parseversion", "A command line tool for parsing version strings."). | ||
Author("ActiveState, Inc. <[email protected]>"). | ||
Version(appVersion). | ||
UsageWriter(os.Stdout). | ||
UsageTemplate(kingpin.DefaultUsageTemplate + extraDocs) | ||
app.HelpFlag.Short('h') | ||
|
||
args := app.Arg( | ||
"type/version pairs", | ||
"One or more pairs of version types and versions to parse", | ||
).Required().Strings() | ||
|
||
pv := &parseversion{app: app} | ||
|
||
_, err := app.Parse(os.Args[1:]) | ||
|
||
pv.args = *args | ||
|
||
return pv, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
golangci-lint run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
git config core.hooksPath git/hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/ActiveState/langtools | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect | ||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect | ||
github.com/ericlagergren/decimal v0.0.0-20191206042408-88212e6cfca9 | ||
github.com/stretchr/testify v1.4.0 | ||
golang.org/x/text v0.3.2 | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | ||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= | ||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= | ||
github.com/apmckinlay/gsuneido v0.0.0-20190404155041-0b6cd442a18f/go.mod h1:JU2DOj5Fc6rol0yaT79Csr47QR0vONGwJtBNGRD7jmc= | ||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/ericlagergren/decimal v0.0.0-20191206042408-88212e6cfca9 h1:mMVotm9OVwoOS2IFGRRS5AfMTFWhtf8wj34JEYh47/k= | ||
github.com/ericlagergren/decimal v0.0.0-20191206042408-88212e6cfca9/go.mod h1:ZWP59etEywfyMG2lAqnoi3t8uoiZCiTmLtwt6iESIsQ= | ||
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= | ||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | ||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package name | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var replacement = regexp.MustCompile(`[\.\_-]+`) | ||
|
||
// NormalizePython takes a Python package name and returns it in normalized | ||
// form. Specifically, that means it is in all lower case and all periods (.) | ||
// and underscores (_) with hyphens. See | ||
// https://www.python.org/dev/peps/pep-0503/#name for ddetails on how names | ||
// should be normalized in Python. | ||
func NormalizePython(name string) string { | ||
return strings.ToLower(replacement.ReplaceAllString(name, "-")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package name | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNormalizePython(t *testing.T) { | ||
cases := map[string]string{ | ||
"flask": "flask", | ||
"Flask": "flask", | ||
"FLASK": "flask", | ||
"backports.ssl": "backports-ssl", | ||
"backports-----ssl": "backports-ssl", | ||
"backports.SSL": "backports-ssl", | ||
"Backports.SSL": "backports-ssl", | ||
"backports-datetime-fromisoformat": "backports-datetime-fromisoformat", | ||
"backports-datetime_fromisoformat": "backports-datetime-fromisoformat", | ||
"BACKPORTS-DATETIME-FROMISOFORMAT": "backports-datetime-fromisoformat", | ||
"BACKPORTS-.-DATETIME__-.-FROMISOFORMAT": "backports-datetime-fromisoformat", | ||
} | ||
|
||
for from, norm := range cases { | ||
assert.Equal(t, norm, NormalizePython(from), `normalization of "%s" is "%s"`, from, norm) | ||
} | ||
} |
Oops, something went wrong.