Comments (12)
Yeah, I can put up a PR Friday.
Update: Ended up a little busy today (4/26) so didn't get to this but will add it next week.
from rattler.
Do you have an example and how you would change it?
from rattler.
For example, the current PathType
class in rattler (eg; here) has getters for hardlink
, softlink
, etc. that just return True if the PathType
is of that value. In other words, to get the path type you have to do a bunch of if/else until you hit a possible value that returns True. That's not really idiomatic and a major hassle if you have a lot of values. It also means downstream code needs to worry about any new enum values not being handled.
So for example, to determine the type of a path in Python I have to do something like:
(currently)
...
if path_type.directory:
return "directory"
elif path_type.softlink:
return "softlink"
elif path_type.hardlink:
return "hardlink"
In the rust code in rattler-conda-types
however (eg; here this is an enum. That is, the values are mutually exclusive. This means it would be also safe to expose these types as python enums.
If we did that, now it would be easy in python to:
- Get all possible valid values for the enum
- Convert from a string to the enum type easily
- Convert from the enum type to a string
- Check equality across enums of the same type
For example:
>>> print(path_type.value)
PathType.hardlink
>>> PathType["hardlink"] == PathType.hardlink
`True`
>>> assert path_type == PathType.symlink, "some assertion error"
Doing some cursory research, PyO3 does not natively have a way to export rust enums as Python enums. But a few approaches are suggested in this SO post. Another approach I don't see listed there that might be cleaner (and backwards compatible with older versions of Python) is to expose an int member for these types and on the python side have a matching int based enum with those values. That's more memory efficient too.
from rattler.
Thanks for the writeup! That makes total sense to me. Would you be able to whip up a Pr?
from rattler.
Related Issues (20)
- Allow `!=1.2.3.*` in strict parsing mode
- Add support for interactive authentication HOT 1
- The file backend for rattler authentication should have a constructor that returns an error
- Add retry/backoff to file removing on Windows
- Update rust version in pixi.toml
- Add extra solve options HOT 3
- Replace very long shebangs with a shorter variant HOT 3
- Error in getting sparse_repo_datas HOT 6
- Prefix with spaces does not work for some executables / entry points on Windows HOT 2
- Consider resetting the code page after activation
- Why is paths_data in a PrefixRecord not a list of PathsEntry objects? HOT 4
- UrlOrPath - store absolute Windows URLs with `file:///`? HOT 8
- Feature request: create SparseRepoData from memory HOT 2
- OCI: use `zstd` for the zstd encoded repodata layer
- py-rattler's `PackageRecord` is missing the `noarch` type attribute? HOT 1
- Add setters to PrefixRecord and add methods to write back a PrefixRecord to JSON HOT 2
- Expose PackageCache in py-rattler
- Add functionality for (re)populating package cache
- Remove uncommented code (or clarify why it's there) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rattler.