Suggest a first step
cover Suggest a first step
This is a first version of a cargo fetcher. It mimics cargo fetch means it creates cargo cache in ${DL_DIR}/cargo. As mentioned in comments the proxy-thingy was stolen from npmsw for shrinkwrap files.
First approach was to parse Cargo.toml for projects that don't ship a Cargo.lock (crates for rustlibs should do this) but that was skipped:
An unknown magic inside cargo detects which libs are avaiable: Blindly followin -> download explodedc [1]
As proof of concept I did (no meta-rust in layers to avoid surprises):
* add a simple cargo-fetch.bbclass to oe-core [2]
* adapt a pure rust recipe 'spotifyd' to new fetcher [3-4]
* moved console to source of spotifyd and did
Quoted 3 lines
export CARGO_HOME="<DL_DIR>/cargo"
export CARGO_TARGET_DIR="<B>"
cargo build --frozen
--> project was build without issues
Please review carefully because I am aware that:
* my python could be better
* the 'one cache for all in download area thingy' might cause issues I do not see yet
Am also aware that this is not more than a first step. Once this makes it in, further TODOs are:
* Merge latest meta-rust -> oe-core (latest: There were some riscv adjustments recently - and I am not sure if these are in the poky-contrib of Alex/Ross)
* Add documentation / tests / devtool-support / ??
[1] https://github.com/schnitzeltony/mimic-cargo-fetcher/blob/master/test.py
[2] https://github.com/schnitzeltony/openembedded-core/blob/cargo-fetcher/meta/classes/cargo-fetch.bbclass
[3] https://github.com/schnitzeltony/meta-musicians/blob/cargo-fetcher/recipes-streaming/spotify/spotifyd.bb
[4] https://github.com/schnitzeltony/meta-musicians/blob/cargo-fetcher/recipes-streaming/spotify/spotifyd/Cargo.lock
Andreas Müller (3):
Add a fetcher for cargo crate index
Add parser for toml configuration files
Add a fetcher for cargo crates
lib/bb/fetch2/__init__.py | 4 + lib/bb/fetch2/crateindex.py | 155 +++++ lib/bb/fetch2/cratelock.py | 268 +++++++++ lib/toml/LICENSE | 27 + lib/toml/README | 8 + lib/toml/__init__.py | 25 + lib/toml/__init__.pyi | 15 + lib/toml/decoder.py | 1057 +++++++++++++++++++++++++++++++++++ lib/toml/decoder.pyi | 52 ++ lib/toml/encoder.py | 304 ++++++++++ lib/toml/encoder.pyi | 34 ++ lib/toml/ordered.py | 15 + lib/toml/ordered.pyi | 7 + lib/toml/source-origin | 1 + lib/toml/tz.py | 24 + lib/toml/tz.pyi | 9 + 16 files changed, 2005 insertions(+) create mode 100644 lib/bb/fetch2/crateindex.py create mode 100644 lib/bb/fetch2/cratelock.py create mode 100644 lib/toml/LICENSE create mode 100644 lib/toml/README create mode 100644 lib/toml/__init__.py create mode 100644 lib/toml/__init__.pyi create mode 100644 lib/toml/decoder.py create mode 100644 lib/toml/decoder.pyi create mode 100644 lib/toml/encoder.py create mode 100644 lib/toml/encoder.pyi create mode 100644 lib/toml/ordered.py create mode 100644 lib/toml/ordered.pyi create mode 100644 lib/toml/source-origin create mode 100644 lib/toml/tz.py create mode 100644 lib/toml/tz.pyi
Signature · 1 line
2.26.2
PATCH 1/3 Add a fetcher for cargo crate index
Mimic cargo fetch for common crate index
--- lib/bb/fetch2/__init__.py | 2 + lib/bb/fetch2/crateindex.py | 155 ++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 lib/bb/fetch2/crateindex.py
lib/bb/fetch2/__init__.py +2 -0
@@ -1908,6 +1908,7 @@ from . import repo from . import clearcase from . import npm from . import npmsw +from . import crateindex methods.append(local.Local()) methods.append(wget.Wget())
@@ -1927,3 +1928,4 @@ methods.append(repo.Repo()) methods.append(clearcase.ClearCase()) methods.append(npm.Npm()) methods.append(npmsw.NpmShrinkWrap()) +methods.append(crateindex.CrateIndex())
lib/bb/fetch2/crateindex.py new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 2/3 Add parser for toml configuration files
In reply to Andreas Müller* Cargo.lock files follow toml specification
* Add a README to explain why and where this code was stolen and explain that this can possibly go in the far future
--- lib/toml/LICENSE | 27 + lib/toml/README | 8 + lib/toml/__init__.py | 25 + lib/toml/__init__.pyi | 15 + lib/toml/decoder.py | 1057 ++++++++++++++++++++++++++++++++++++++++ lib/toml/decoder.pyi | 52 ++ lib/toml/encoder.py | 304 ++++++++++++ lib/toml/encoder.pyi | 34 ++ lib/toml/ordered.py | 15 + lib/toml/ordered.pyi | 7 + lib/toml/source-origin | 1 + lib/toml/tz.py | 24 + lib/toml/tz.pyi | 9 + 13 files changed, 1578 insertions(+) create mode 100644 lib/toml/LICENSE create mode 100644 lib/toml/README create mode 100644 lib/toml/__init__.py create mode 100644 lib/toml/__init__.pyi create mode 100644 lib/toml/decoder.py create mode 100644 lib/toml/decoder.pyi create mode 100644 lib/toml/encoder.py create mode 100644 lib/toml/encoder.pyi create mode 100644 lib/toml/ordered.py create mode 100644 lib/toml/ordered.pyi create mode 100644 lib/toml/source-origin create mode 100644 lib/toml/tz.py create mode 100644 lib/toml/tz.pyi
lib/toml/LICENSE new file +27 -0
@@ -0,0 +1,27 @@ +The MIT License + +Copyright 2013-2019 William Pearson +Copyright 2015-2016 Julien Enselme +Copyright 2016 Google Inc. +Copyright 2017 Samuel Vasko +Copyright 2017 Nate Prewitt +Copyright 2017 Jack Evans +Copyright 2019 Filippo Broggini + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
lib/toml/README new file +8 -0
@@ -0,0 +1,8 @@ +TOML parser is not part of python core and there are open discussions which +implementation (toml, pytoml..) and when TOML parser will be added [1]. As long +as toml parrser is not included, use a copy of [2]. FWIW: If pytoml will be +included python core, the only changes required here is changing imports (tested +at the time of writing) + +[1] https://discuss.python.org/t/adopting-recommending-a-toml-parser/4068/17 +[2] https://github.com/uiri/toml
lib/toml/__init__.py new file +25 -0
@@ -0,0 +1,25 @@ +"""Python module which parses and emits TOML. + +Released under the MIT license. +""" + +from toml import encoder +from toml import decoder + +__version__ = "0.10.2" +_spec_ = "0.5.0" + +load = decoder.load +loads = decoder.loads +TomlDecoder = decoder.TomlDecoder +TomlDecodeError = decoder.TomlDecodeError +TomlPreserveCommentDecoder = decoder.TomlPreserveCommentDecoder + +dump = encoder.dump +dumps = encoder.dumps +TomlEncoder = encoder.TomlEncoder +TomlArraySeparatorEncoder = encoder.TomlArraySeparatorEncoder +TomlPreserveInlineDictEncoder = encoder.TomlPreserveInlineDictEncoder +TomlNumpyEncoder = encoder.TomlNumpyEncoder +TomlPreserveCommentEncoder = encoder.TomlPreserveCommentEncoder +TomlPathlibEncoder = encoder.TomlPathlibEncoder
lib/toml/__init__.pyi new file +15 -0
@@ -0,0 +1,15 @@ +from toml import decoder as decoder, encoder as encoder + +load = decoder.load +loads = decoder.loads +TomlDecoder = decoder.TomlDecoder +TomlDecodeError = decoder.TomlDecodeError +TomlPreserveCommentDecoder = decoder.TomlPreserveCommentDecoder +dump = encoder.dump +dumps = encoder.dumps +TomlEncoder = encoder.TomlEncoder +TomlArraySeparatorEncoder = encoder.TomlArraySeparatorEncoder +TomlPreserveInlineDictEncoder = encoder.TomlPreserveInlineDictEncoder +TomlNumpyEncoder = encoder.TomlNumpyEncoder +TomlPreserveCommentEncoder = encoder.TomlPreserveCommentEncoder +TomlPathlibEncoder = encoder.TomlPathlibEncoder
lib/toml/decoder.py new file +1057 -0
1,057 lines not on this page · raw message
lib/toml/decoder.pyi new file +52 -0
52 lines not on this page · raw message
lib/toml/encoder.py new file +304 -0
304 lines not on this page · raw message
lib/toml/encoder.pyi new file +34 -0
@@ -0,0 +1,34 @@ +from toml.decoder import InlineTableDict as InlineTableDict +from typing import Any, Optional + +unicode = str + +def dump(o: Mapping[str, Any], f: IO[str], encoder: TomlEncoder = ...) -> str: ... +def dumps(o: Mapping[str, Any], encoder: TomlEncoder = ...) -> str: ... + +class TomlEncoder: + preserve: Any = ... + dump_funcs: Any = ... + def __init__(self, _dict: Any = ..., preserve: bool = ...): ... + def get_empty_table(self): ... + def dump_list(self, v: Any): ... + def dump_inline_table(self, section: Any): ... + def dump_value(self, v: Any): ... + def dump_sections(self, o: Any, sup: Any): ... + +class TomlPreserveInlineDictEncoder(TomlEncoder): + def __init__(self, _dict: Any = ...) -> None: ... + +class TomlArraySeparatorEncoder(TomlEncoder): + separator: Any = ... + def __init__(self, _dict: Any = ..., preserve: bool = ..., separator: str = ...) -> None: ... + def dump_list(self, v: Any): ... + +class TomlNumpyEncoder(TomlEncoder): + def __init__(self, _dict: Any = ..., preserve: bool = ...) -> None: ... + +class TomlPreserveCommentEncoder(TomlEncoder): + def __init__(self, _dict: Any = ..., preserve: bool = ...): ... + +class TomlPathlibEncoder(TomlEncoder): + def dump_value(self, v: Any): ...
lib/toml/ordered.py new file +15 -0
@@ -0,0 +1,15 @@ +from collections import OrderedDict +from toml import TomlEncoder +from toml import TomlDecoder + + +class TomlOrderedDecoder(TomlDecoder): + + def __init__(self): + super(self.__class__, self).__init__(_dict=OrderedDict) + + +class TomlOrderedEncoder(TomlEncoder): + + def __init__(self): + super(self.__class__, self).__init__(_dict=OrderedDict)
lib/toml/ordered.pyi new file +7 -0
@@ -0,0 +1,7 @@ +from toml import TomlDecoder as TomlDecoder, TomlEncoder as TomlEncoder + +class TomlOrderedDecoder(TomlDecoder): + def __init__(self) -> None: ... + +class TomlOrderedEncoder(TomlEncoder): + def __init__(self) -> None: ...
lib/toml/source-origin new file +1 -0
@@ -0,0 +1 @@ +https://github.com/uiri/toml
lib/toml/tz.py new file +24 -0
@@ -0,0 +1,24 @@ +from datetime import tzinfo, timedelta + + +class TomlTz(tzinfo): + def __init__(self, toml_offset): + if toml_offset == "Z": + self._raw_offset = "+00:00" + else: + self._raw_offset = toml_offset + self._sign = -1 if self._raw_offset[0] == '-' else 1 + self._hours = int(self._raw_offset[1:3]) + self._minutes = int(self._raw_offset[4:6]) + + def __deepcopy__(self, memo): + return self.__class__(self._raw_offset) + + def tzname(self, dt): + return "UTC" + self._raw_offset + + def utcoffset(self, dt): + return self._sign * timedelta(hours=self._hours, minutes=self._minutes) + + def dst(self, dt): + return timedelta(0)
lib/toml/tz.pyi new file +9 -0
@@ -0,0 +1,9 @@ +from datetime import tzinfo +from typing import Any + +class TomlTz(tzinfo): + def __init__(self, toml_offset: Any) -> None: ... + def __deepcopy__(self, memo: Any): ... + def tzname(self, dt: Any): ... + def utcoffset(self, dt: Any): ... + def dst(self, dt: Any): ...
Signature · 1 line
2.26.2
PATCH 3/3 Add a fetcher for cargo crates
In reply to Andreas MüllerParse Cargo.lock, download crates and generate cargo cache as 'cargo fetch' would do.
--- lib/bb/fetch2/__init__.py | 2 + lib/bb/fetch2/cratelock.py | 268 +++++++++++++++++++++++++++++++++++++ 2 files changed, 270 insertions(+) create mode 100644 lib/bb/fetch2/cratelock.py
lib/bb/fetch2/__init__.py +2 -0
@@ -1909,6 +1909,7 @@ from . import clearcase from . import npm from . import npmsw from . import crateindex +from . import cratelock methods.append(local.Local()) methods.append(wget.Wget())
@@ -1929,3 +1930,4 @@ methods.append(clearcase.ClearCase()) methods.append(npm.Npm()) methods.append(npmsw.NpmShrinkWrap()) methods.append(crateindex.CrateIndex()) +methods.append(cratelock.CrateLock())
lib/bb/fetch2/cratelock.py new file +268 -0
268 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 28 lines · Andreas Müller
This is a first version of a cargo fetcher. It mimics cargo fetch means it creates cargo cache in ${DL_DIR}/cargo. As mentioned in comments the proxy-thingy was stolen from npmsw for shrinkwrap files.
First approach was to parse Cargo.toml for projects that don't ship a Cargo.lock (crates for rustlibs should do this) but that was skipped:
An unknown magic inside cargo detects which libs are avaiable: Blindly followin -> download explodedc [1]As proof of concept I did (no meta-rust in layers to avoid surprises):
* add a simple cargo-fetch.bbclass to oe-core [2]
* adapt a pure rust recipe 'spotifyd' to new fetcher [3-4]
* moved console to source of spotifyd and did
> export CARGO_HOME="<DL_DIR>/cargo"
> export CARGO_TARGET_DIR="<B>"
> cargo build --frozen
--> project was build without issuesPlease review carefully because I am aware that:
* my python could be better
* the 'one cache for all in download area thingy' might cause issues I do not see yetAm also aware that this is not more than a first step. Once this makes it in, further TODOs are:
Quoted 8 lines
* Merge latest meta-rust -> oe-core (latest: There were some riscv adjustments recently - and I am not sure if these are in the poky-contrib of Alex/Ross)
* Add documentation / tests / devtool-support / ??[1] https://github.com/schnitzeltony/mimic-cargo-fetcher/blob/master/test.py
[2] https://github.com/schnitzeltony/openembedded-core/blob/cargo-fetcher/meta/classes/cargo-fetch.bbclass
[3] https://github.com/schnitzeltony/meta-musicians/blob/cargo-fetcher/recipes-streaming/spotify/spotifyd.bb
[4] https://github.com/schnitzeltony/meta-musicians/blob/cargo-fetcher/recipes-streaming/spotify/spotifyd/Cargo.lock
Thanks for putting this together. Out of interest how does it compare to the code in meta-rust?
I'm hoping Paul Barker and Randy MacLeod can take a look at this as they've done a lot more work in the area than I have.
Cheers,
Richard