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

msvc: Fix default MICROPYPATH #1290

Closed
wants to merge 1 commit into from
Closed

Conversation

stinos
Copy link
Contributor

@stinos stinos commented May 27, 2015

Default windows installations do not use HOME but USERPROFILE as the environment
variable for the user's home directory. Also there is no notion of a common
directory like /usr/lib so exclude it from the default path.

Default windows installations do not use HOME but USERPROFILE as the environment
variable for the user's home directory. Also there is no notion of a common
directory like /usr/lib so exclude it from the default path.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 93.82% when pulling b4602ee on stinos:msvc-pathenv into c754d80 on micropython:master.

@pfalcon
Copy link
Contributor

pfalcon commented May 27, 2015

Default windows installations do not use HOME but USERPROFILE as the environment variable for the user's home directory.

That means that "default" Windows is not suitable for more or less advanced usage, so anyone who wants to do that, goes and defines HOME, like it's done on any other system.

Also there is no notion of a common directory like /usr/lib so exclude it from the default path.

Of course there is. You just create it, and put common stuff in there.

@dpgeorge
Copy link
Member

An alternative is for windows port to provide its own special getenv and do a translation from HOME to USERPROFILE.

What's the default path for CPython?

@stinos
Copy link
Contributor Author

stinos commented May 27, 2015

special getenv

Thought of that but then everyone should use some macro like mp_getenv instead of getenv. But maybe it is nicer after all.

What's the default path for CPython?

Doesn't even include home directory: ['', 'C:\\Windows\\system32\\python34.zip', 'c:\\Python34\\DLLs', 'c:\\Python34\\lib', 'c:\\Python34', 'c:\\Python34\\lib\\site-packages']

@pfalcon
Copy link
Contributor

pfalcon commented May 27, 2015

Doesn't even include home directory:

Sure, that's because of differing requirements for CPython and MicroPython. MicroPython, as coming from a git repo, should be usable without requiring root permissions, etc. Note that a distro package would follow different requirement, exactly not having something in ~ by default, so we should make search path compile-time configurable anyway.

And what requirements do you follow with this change? Windows being different just for the purpose of being different is easily criticized, per above.

@stinos
Copy link
Contributor Author

stinos commented May 27, 2015

And what requirements do you follow with this change?

I mainly want to fix getenv("HOME") already because that is also used in the unix-mp-readline-v2 branch to get the path to the history file, and hence gives me no history at all.

@pfalcon
Copy link
Contributor

pfalcon commented May 27, 2015

So, the easiest fix for you would be to define HOME. If you want to fix it for other people, then who're these people (different target groups), how they're supposed to use uPy, would they care about such fix at all (maybe one group wouldn't use associated features at all, so won't notice any fixes, and the other can make POSIXish set up anyway), etc. We'd need to answer such questions sooner or later to better support Windows anyway, but if it's not right time and you don't want to consider that, then maybe using existing features as is instead of applying such "spaghetti" patches is suitable alternative for now.

@stinos
Copy link
Contributor Author

stinos commented May 27, 2015

Fair enough, I have HOME and MICROPYPATh defined anyway so don't really care

@stinos stinos closed this May 27, 2015
@stinos stinos deleted the msvc-pathenv branch May 28, 2015 07:27
@stinos
Copy link
Contributor Author

stinos commented May 28, 2015

Of course there is. You just create it, and put common stuff in there.

Still wanted to comment on this but forgot: it's not as easy as you put it here. Using a single slash at the start of a path will point to the root of the drive of the current working directory. So to get this working reliably (well, sort of) one would for have to make links on each drive to point to one common location. But that is then just for /usr/lib. So in practice it means you just don't use a single slash at the start because you never really know where it's going to end up. Unless you want to rely on cwd but that's a nightmare as well. Or you modify whatever code you use to replace starting / with some fixed value like //location/

@pfalcon
Copy link
Contributor

pfalcon commented May 28, 2015

Using a single slash at the start of a path will point to the root of the drive of the current working directory.

Yes, so you just stick to one drive. That may seem hard, but using Windows is already pretty hard, so that doesn't change anything much ;-). And it's not that hard actually, because: a) layman users already have a single drive, because that's how vendors usually partition it (and they do it for good reason - to avoid situation when system disk is full and system glitches, while another disk is empty, because user has no idea that it can be used); b) advanced users have >1 drive, but on their experience, use single for "work", like running apps on, and the rest as kind of archives (noexec mount option in unix terms).

So, again, it boils down to question whether there's good overall strategy how to deal with Windows support. For example, I hoped - wished - that for a question above you answered: "I'm looking how to make possible (and streamlined) micropython-lib usage on Windows". But you don't, right? Then average users simply won't have any library modules, and all munging with default MICROPYPATH value simply doesn't make much sense.

That said, this issue shows some points to work on - make default path configurable via define, perhaps add get_home() function for ports to override.

@stinos
Copy link
Contributor Author

stinos commented May 28, 2015

using Windows is already pretty hard

But is it really? It simply depends on what you're used to, on what you learned. E.g. I find using OSX hard. Is it hard in general? I doubt it. Would I still find it hard if having used it a couple of months? I doubt it. Likewise I don't find linux hard to use for the things I use it for because I'm used to that. Idem for Windows.

Yes, so you just stick to one drive

Meh, no :) Maybe they're layman nor advanced but apart from a) and b) (what is ever black and white?) there's a whole lot of other types of users with good reasons to use multiple drives who don't want to adhere to some special, very fragile, rules just to be able to use a forward slash in some program. Instead they will ditch the option of using / and having to hope to have it correct, and just choose the robust option of specifying the exact drive since then you are sure you end up where you want.

Whether there's good overall strategy how to deal with Windows support

There isn't? It's pretty hard to come up with something good when requirements are not known. At least I have no clue of other users nor their usecases.

"I'm looking how to make possible (and streamlined) micropython-lib usage on Windows". But you don't, right?

No because I haven't (yet) had the need for that. And because if I'd had it would still require serious consideration. Lots of interesting stuff in micropython-lib is implemented using libffi to call into libc for instance but there's no such thing on this platform I use so that's facing unknown but likely large amount of time to get that working.

@dhylands
Copy link
Contributor

You could take the cygwin approach where they create a pseudo root for each
drive /cygdrive/c_drive. When I used windows and cygwin, I tended to create
/c which mapped to c:\ and /d which mapped to d:\

FatFS (used by stmhal) uses drive numbers instead of drive letters and we
changed it to have /flash map to 0: and /sdcard map to 1:

On Thu, May 28, 2015 at 2:53 AM, stinos notifications@github.com wrote:

using Windows is already pretty hard

But is it really? It simply depends on what you're used to, on what you
learned. E.g. I find using OSX hard. Is it hard in general? I doubt it.
Would I still find it hard if having used it a couple of months? I doubt
it. Likewise I don't find linux hard to use for the things I use it for
because I'm used to that. Idem for Windows.

Yes, so you just stick to one drive

Meh, no :) Maybe they're layman nor advanced but apart from a) and b)
(what is ever black and white?) there's a whole lot of other types of users
with good reasons to use multiple drives who don't want to adhere to some
special, very fragile, rules just to be able to use a forward slash in some
program. Instead they will ditch the option of using / and having to hope
to have it correct, and just choose the robust option of specifying the
exact drive since then you are sure you end up where you want.

Whether there's good overall strategy how to deal with Windows support

There isn't? It's pretty hard to come up with something good when
requirements are not known. At least I have no clue of other users nor
their usecases.

"I'm looking how to make possible (and streamlined) micropython-lib usage
on Windows". But you don't, right?

No because I haven't (yet) had the need for that. And because if I'd had
it would still require serious consideration. Lots of interesting stuff in
micropython-lib is implemented using libffi to call into libc for instance
but there's no such thing on this platform I use so that's facing unknown
but likely large amount of time to get that working.


Reply to this email directly or view it on GitHub
#1290 (comment)
.

Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com

@stinos
Copy link
Contributor Author

stinos commented May 28, 2015

Such approcahes are indeed feasible since there's a fixed mapping. However I think they always have to be implemented at a low level, like the standard library used, so that every way of talking to the filesystem is covered. So I don't think it's practical for use with uPy on windows (unless I'm missing something, e.g. windows port could supply an implementation for open which maps / to c:/ or so, but then only opening files is covered and not creating/listing directories etc) when the workaround is simple enough i.e. specify full paths including drives

@dhylands
Copy link
Contributor

This is true, and internally the runtime library supports both forward slashed and backward slashes (and thise has been the case since DOS). It's only CMD.EXE/COMMAND.COM and other programs which filter for it which don't like forward slashes (you probably already knew that - but I figured it can't hurt to mention it - just in case)

@stinos
Copy link
Contributor Author

stinos commented May 28, 2015

Yes I'm aware of the limitations, I'm used to using / everywhere so I don't have to switch some mental model when switching between platforms (and because it just makes more sense in general) but then once in a while there's always a situation where it won't cut it - backwards compatibility at it's finest I guess.

@pfalcon
Copy link
Contributor

pfalcon commented May 29, 2015

using Windows is already pretty hard

But is it really?

Well, I can't put smiley after every word I write ;-). And otherwise I meant "using for development". You don't have standard POSIX API and a lot of other things. On top of that, people try to vary in path separators, paths, etc. But that's not really needed.

with good reasons to use multiple drives who don't want to adhere to some special, very fragile, rules just to be able to use a forward slash in some program

Drive letters and forward slashes are orthogonal.

and just choose the robust option of specifying the exact drive since then you are sure you end up where you want.

Ok, let them choose and specify MICROPYPATH explicitly. The talk in the original patch was about munging default value. But the default value for Windows cannot be improved. And that's example of those "hard" Windows things. You can't arbitrarily put "C:" for global path - other users may have it on another drive. You cannot use system drive, you cannot use the drive where the executable - all these choices are random and arbitrary. And among all these choices, sticking to concept of current drive as a default is not the worst choice by number of criteria, including ability to use POSIX paths, and even the same values of them as on POSIX system.

@pfalcon
Copy link
Contributor

pfalcon commented May 29, 2015

Lots of interesting stuff in micropython-lib is implemented using libffi to call into libc for instance but there's no such thing on this platform

Stating the obvious, libffi also works for Windows (be it mingw or msvc). Yes, underlying API/libraries are different.

@pfalcon
Copy link
Contributor

pfalcon commented May 29, 2015

You could take the cygwin approach where they create a pseudo root for each drive /cygdrive/c_drive.

... And the easiest way to achieve that is to build against cygwin. I don't think that uPy should do anything like that, because that's pretty big departure from native Windows way. But using forwards slashes or sticking to current drive are native Windows features OTOH, so using them makes good sense IMHO.

@pfalcon
Copy link
Contributor

pfalcon commented May 29, 2015

FYI: 51726b4

tannewt added a commit to tannewt/circuitpython that referenced this pull request Oct 23, 2018
shared-bindings/time: introduce time.monotonic_ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants