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

Recognizing macOS Platform #55

Closed
crisluengo opened this issue Nov 12, 2021 · 6 comments
Closed

Recognizing macOS Platform #55

crisluengo opened this issue Nov 12, 2021 · 6 comments

Comments

@crisluengo
Copy link

crisluengo commented Nov 12, 2021

The code that determines the platform (in _utility.platform.py) doesn't work for macOS, and it doesn't work for most flavors of Unix:

def platform(): # the platform (eg: linux) you are using plotext with
    platform = sys.platform
    names = ["win", "linux", "unix"]
    platforms = ["windows", "linux", "unix"]
    for i in range(3):
        if names[i] in platform:
            return platforms[i]
    return "not found"

On macOS, platform is "darwin", which contains "win" and therefore gets labeled "windows".

I recommend rewriting that function to:

def platform(): # the platform (eg: linux) you are using plotext with
    platform = sys.platform
    # According to the docs, this returns one of: 'aix', 'linux', 'win32', 'cygwin', 
    # 'darwin', or the modified result of `uname -s` on other Unix systems.
    if platform in {'win32', 'cygwin'}:
        # These are the only two possible outputs on Windows systems
        return 'windows'
    else:
        # Anything that is not Windows and that runs Python is a flavor of Unix
        return 'unix'

Since you only ever check this value for Windows, I see no benefit in making a distinction between flavors of Unix. If you do want to make that distinction, why not just return the value of sys.platform for Unix systems?

Similarly, your function _utility.platform.shell() returns "cmd" in any shell that is not Bash. On macOS, the new default is Zsh (which may people use on Linux too), and I'm sure there are people out there still using Csh and even Ksh. But it looks like this value is never actually used anywhere, so I guess it doesn't matter.

I won't submit a pull request, because this repository seems to have erased all its history. If you want people to contribute code, you should not do that.

@piccolomo
Copy link
Owner

piccolomo commented Nov 12, 2021

Hi @crisluengo,
I will answer first to the erasing of github history issue as it seems more important for now. I am not an expert either in Python or GitHub and frankly I do not even know what a repo history is, let alone how to remove it.

This is the sequence of commands I use to publish on GitHib. It would be kind of you, if you could help me find the problem, that cause the history deletion.

git config --global user.email "piccolomo@gmail.com"
git init
git add .
git commit -m "commit new message"
git remote rm origin
git remote add origin "https://github.com/piccolomo/plotext.git"
git push -f origin master

@Dev-iL
Copy link
Contributor

Dev-iL commented Nov 13, 2021

@piccolomo
History refers, in this case, to all commits contributed over the life of the project by the various authors (see Network for a visualization). If you take a look at the commit graph of the repo, you'll only see the 4 commits by yourself (and none of the code contributed by others through the various PRs).

I think git remote rm origin + git push -f origin master are the culprits. For typical use cases, git add git commit and git push should suffice.

I recommend using one of the available GUI clients for git (e.g. GitKraken, which is free for public projects), which can preview the changes you're about to do to the remote branch (in this case what's kept on the cloud, vs what's kept locally).

@crisluengo
Copy link
Author

@piccolomo
A colleague of mine recently evaluated a bunch of git courses for our team members. He recommended this (free) course on Udacity:
https://www.udacity.com/course/version-control-with-git--ud123
He thought it would take maybe 10 hours to go all the way through it. If you take a bit of time every day, in no time you should understand one of the most important software development tools we have today.

in short:

  • git add . stages all changes in the current directory and subdirectories for commit.
  • git commit makes the commit.
  • git push pushes the changes to the remote server.

if you need to do git push -f you’re doing it wrong. -f tells git to overwrite things on the remote repository. It should be used only in extreme circumstances. In fact, I think by default GitHub protects the master branch, disallowing this -f action. Because it doesn’t only hide other peoples’ contributions, but it also invalidates links and commit references other people might be using.

@ethack
Copy link
Contributor

ethack commented Nov 14, 2021

I think it's worth trying to restore your commit history. It can help with tracking down bugs as well (contributors could use git bisect or git blame to narrow down the context of when the bug was introduced).

If possible, I'd suggest finding a friend or colleague who could help guide you through restoring the history. But I think this process should work assuming you have a copy of the pre-4.0 repo still on your computer (if you don't you could potentially grab one from one of the forked repos):

  1. Clone a fresh copy of plotext from github git clone https://github.com/piccolomo/plotext.git or git clone git@github.com:piccolomo/plotext.git depending on whether you use HTTPS or SSH to work with Github. This ensures that when you follow the rest of the steps, the actual files on Github will remain the same (i.e. the 4.0 release).
  2. Change into this fresh directory cd plotext
  3. Remove the .git directory rm -rf .git/
  4. Copy the .git directory from your pre-4.0 repo directory to your current plotext directory. cp -r path/to/plotext/3/.git/ ./. This will contain all the past history.
  5. Add all the files already in the current plotext directory (the v4 ones from Github) git add --all . (you may want to do git add --all --dry-run . first to double check nothing is going to be added you don't want to be).
  6. Create a commit message git commit -m 'version 4.0.0'
  7. Force push all past history and the new 4.0 commit to Github git push -f

At this point you can copy any of your work in progress files into this new directory and continue working as you were before (hopefully not ever needing to use git push -f again 😄 )

Note: I haven't tested this which is why I suggest getting someone who knows a bit more about git to look over your shoulder while you do this.

@Dev-iL
Copy link
Contributor

Dev-iL commented Nov 14, 2021

@ethack If you look at the network (forks) chart, you'll see that this history deletion was done at multiple points in the history of the project, and so there are several disconnected master branches. I think the best way to reconstruct the history would be to cherry-pick commits in chronological order from various forks, resolve any conflicts and amend the time and author to the commits' original. Unfortunately, I don't know how to automate parts or all of this procedure (list all unique commits across all forks in chronological order, filter out those that were never merged to the main fork, cherry-pick/rebase/merge the remaining commits to a single linear branch such that all conflicts are resolved by taking the contents of the newer commit).

@piccolomo
Copy link
Owner

piccolomo commented Dec 10, 2021

Hi @crisluengo,

I reply now to the original issue report. I should have sorted this in the newly updated 4.1.0 version, available on github and pypi.

I have removed the shell function and updated the platform function to your version.

Please let me know if the issue persists.

Thanks also for the git hub guidance! P.S. @Dev-iL, @ethack If you are still up for restoring the GitHub history, I may need the exact terminal commands.

Thanks and all the best,
Savino.

@piccolomo piccolomo changed the title Recognizing macOS Recognizing macOS Platform Dec 12, 2021
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

No branches or pull requests

4 participants