Skip to content

Commit

Permalink
Merge pull request #65 from GhostofGoes/refactor
Browse files Browse the repository at this point in the history
Refactor for 0.9.0
  • Loading branch information
GhostofGoes authored Jan 23, 2023
2 parents 25c7152 + 4e64fb3 commit 07fcabf
Show file tree
Hide file tree
Showing 125 changed files with 5,617 additions and 1,582 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Temporary hack until we remove shutilwhich with removal of Python 2
# TODO: move relative_files into tox.ini
[run]
relative_files = True
omit =
getmac/shutilwhich.py
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*.md text eol=lf

# Samples
tests/samples/windows*/*.out text eol=crlf
tests/samples/**/*.out text eol=lf
tests/samples/*.out text eol=lf
tests/samples/windows*/*.out text eol=crlf

# Windows
*.ps1 text eol=crlf
Expand All @@ -16,7 +17,6 @@ tests/samples/*.out text eol=lf
# POSIX
*.sh text eol=lf
*.bash text eol=lf
.travis-osx text eol=lf
*.1 text eol=lf
packaging/*.spec text eol=lf
Makefile text eol=lf
Expand Down
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ A clear and concise description of what you expected to happen.

**System info**
(please complete the following information):
- OS name: [e.g. Windows 10 x64]
- OS Version: [1804 build 17134]
- Python version: [3.6.5 x64]
- OS name (e.g. Windows 10 x64):
- OS Version (e.g. 1804 build 17134):
- Python version (e.g. CPython 3.6.5 x64):
- getmac version (e.g. getmac 0.8.3):

**Additional context**
Add any other context about the problem here.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_allowed: true
contact_links:
- name: Have a general question or comment?
url: "https://github.com/GhostofGoes/getmac/discussions"
about: Open a discussion thread!
24 changes: 12 additions & 12 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
### All Submissions:

* [ ] Have you followed the guidelines in our Contributing document?
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
- [ ] Have you followed the guidelines in our Contributing document?
- [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
- [ ] Have you added an explanation of what your changes do and why you'd like us to include them?

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### Code changes:

* [ ] Did you format your code with Black?
* [ ] `black getmac tests`
* [ ] Are the linting checks passing?
* [ ] `tox -e check`
* [ ] Do all tests pass locally?
* [ ] `tox`
* [ ] Have you updated the [CHANGELOG](CHANGELOG.md) with a summary of your change?
* [ ] Did you add your name to the contributors list in the [README](README.md)?
- [ ] Did you format your code with Black?
- `black getmac tests`
- [ ] Are the linting checks passing?
- `tox -e check`
- [ ] Do all tests pass locally?
- `tox`
- [ ] Have you updated the [CHANGELOG](CHANGELOG.md) with a summary of your change?
- [ ] Did you add your name to the contributors list in the [README](README.md)?

### Summary of changes:
*
-
142 changes: 142 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: CI

on:
- release
- push
- pull_request

jobs:
lint:
name: Run lint checks
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.8"
- name: Install tox
run: python -m pip install tox
- name: Run lint checks
run: tox -e check
test:
name: Run tests
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
# Versions available:
# pypy: https://downloads.python.org/pypy/versions.json
# Python: https://github.com/actions/python-versions/blob/main/versions-manifest.json
# Additional info: https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md
# OS images: https://github.com/actions/runner-images
matrix:
python-version:
- "2.7"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "pypy-2.7"
- "pypy-3.6"
- "pypy-3.7"
- "pypy-3.8"
- "pypy-3.9"
architecture:
- x86
- x64
platform:
- ubuntu-20.04
- windows-latest
- macos-latest
exclude:
- platform: ubuntu-20.04
architecture: x86
- platform: macos-latest
architecture: x86
- platform: ubuntu-20.04
python-version: "3.4"
- platform: macos-latest
python-version: "3.4"
- platform: macos-latest
python-version: "pypy-2.7"
- platform: macos-latest
python-version: "pypy-3.6"
- platform: macos-latest
python-version: "pypy-3.7"
- platform: macos-latest
python-version: "pypy-3.8"
- platform: windows-latest
python-version: "pypy-2.7"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Display platform and environment information
run: |
python --version
python -c "import sys; print('sys.version: %s' % str(sys.version))"
python -c "import sys; print('sys.platform: %s' % str(sys.platform))"
python -c "import os; print('os.name: %s' % str(os.name))"
python -c "import platform; print('platform.uname(): %s' % str(platform.uname()))"
- name: Install dependencies
run: python -m pip install tox coveralls tox-gh-actions
# TODO: fix benchmark results (maybe a separate Job?)
- name: Run tests
run: tox
- uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
- name: Coveralls
if: ${{ matrix.platform == 'ubuntu-20.04' && github.event_name != 'pull_request' }}
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: ${{ matrix.python-version }}-${{ matrix.platform }}
coveralls_finish:
needs: test
runs-on: ubuntu-20.04
steps:
- name: Coveralls Finished
if: ${{ github.event_name != 'pull_request' }}
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true


# TODO: publish
# TODO: need to do this for both "getmac" and "get-mac" packages
# TODO: don't publish pre-releases OR publish them as pre-releases to PyPI

# https://github.com/marketplace/actions/upload-a-build-artifact

# name: "Build and publish a release"

# on:
# release:
# types: [released]

# jobs:
# publish:
# name: "📦 Publish Python distributions"
# runs-on: "ubuntu-20.04"
# strategy:
# matrix:
# python-version:
# - "3.8"
# steps:
# - uses: "actions/checkout@master"
# - name: "🐍 Set up Python ${{ matrix.python-version }}"
# uses: "actions/setup-python@v2"
# with:
# python-version: "${{ matrix.python-version }}"
# - name: "🐍 Install wheel"
# run: "python -m pip install wheel --user"
# - name: "🐍 Build a binary wheel and a source tarball"
# run: "python setup.py sdist bdist_wheel"
# - name: "📦 Publish distribution to PyPI"
# uses: "pypa/gh-action-pypi-publish@master"
# if: "startsWith(github.ref, 'refs/tags')"
# with:
# password: "${{ secrets.pypi_password }}"
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
permissions:
actions: read
contents: read
Expand All @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -53,7 +53,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -67,4 +67,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

58 changes: 56 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,62 @@
**NOTE**: if any changes significantly impact your project or use case, please open an issue on [GitHub](https://github.com/GhostofGoes/getmac/issues) or email me (see git commit author info for address).


## NEXT (XX/XX/XXXX)
* TBD
## 0.9.0 (01/23/2023)
**Announcement**: Compatibility with Python versions older than 3.6 (2.7, 3.4, and 3.5) is deprecated and will be removed in getmac 1.0.0. If you are stuck on an unsupported Python, considor loosely pinning the version of this package in your dependency list, e.g. `getmac<1`.

This release is a *complete rewrite of getmac from the ground up*. The public API of `getmac` is **unchanged** as part of this rewrite. `get_mac_address()` is still the primary way of getting a MAC address, it's just the "under the hood" internals that have changed completely.

It's passing tests and seems to be operable. However, with a change this large there are ineviteably issues that the tests or I don't catch, so I'm doing a series of pre-releases until I'm 99% confident in it's stability. Refer to `docs/rewrite.md` for a in-depth explanation of the rewrite changes.

The new system has a number of benefits
- Reduction of false-positives and false-negatives by improving method selection accuracy (platform, validity, etc.)
- *Significantly* faster overall
- "Misses" have the same performance as "Hits"
- Easier to test, since each method can be tested directly via it's class
- Easier to type annotate and analyze with mypy
- Easier to read, improving reviewability and ease of contributing for newcomers
- Extensible! Custom methods can be defined and added at runtime (which is perfect if you have some particular edge case but aren't able to open-source it).

### Added
* Fully support Python 3.9 (automated tests in CI)
* Tentatively support Python 3.10 and 3.11 (unable to test due to the need to be able to still test 2.7)
* Added default interface detection for MacOS (command: `route get default`)
* Added initial support for Solaris/SunOS. There were a few existing methods that worked as-is, so just added indicators that those methods support `sunos` (Which applies to any system where `platform.system() == SunOS`).
* `arping` (POSIX) or `SendARP` (Windows) will now *always* be used instead of sending a UDP packet when looking for the MAC of a IPv4 host, if they're available and operable (otherwise, UDP + ARP table check will be used like before).
* The amount of time taken to get a result (in seconds) will now be recorded and logged if debugging is enabled (`DEBUG>=1` or `-d`)
* Added command line argument to override the UDP port for network requests: `--override-port` (this was already possible in Python via `getmac.getmac.PORT`, but wasn't configurable via the CLI. Now it is!).
* Added ability to override the detected platform via `--override-platform` argument (CLI) or `getmac.getmac.OVERRIDE_PLATFORM` variable (Python). This will force methods for that platform to be used, regardless of the actual platform. Here's an example forcing `linux` to be used as the platform: `getmac -i eth0 --override-platform linux`. In version 1.0.0, this feature will added as an argument to `get_mac_address()`.
* Added ability to force a specific method to be used via `--force-method` argument (CLI) or `getmac.getmac.FORCE_METHOD` variable (Python). This is useful for troubleshotting issues, general debugging, and testing changes. Example: `getmac -v -dddd --ip 192.168.0.1 --force-method ctypeshost`

### Changed
* **Complete rewrite of `getmac` from the ground up. Refer to `docs/rewrite.md` for a in-depth explanation of the rewrite changes**
* Fixed a failure to look up a hostname now returns `None`, as expected, instead of raising an exception (`socket.gaierror`).
* Fixed numerous false-negative and false-positive bugs
* Improved overall performance
* Performance for cases where no MAC is found is now the same as cases where a MAC is found (speed of "misses" now equals that of "hits")
* Improved the reliability and performance of many methods
* Fixed `netstat` on older Linux distros (such as Ubuntu 12.04)
* Overhauled `ifconfig` parsing. It should now be far more reliable and accurate across all platforms.
* Improved Android support. Note that newer devices are locked down and the amount of information that's obtainable by an unprivileged process is quite limited (Android 7/9 and newer, not sure exactly when they changed this, I'm not an Android guy). That being said, the normal Linux methods should work fine, provided you have the proper permissions (usually, `root`).
* Fixed bug with `/proc/net/route` parsing (this affected Android and potentially other platforms)
* Improve default interface detection for FreeBSD (command: `route get default`)

### Removed
* Removed man pages from distribution (`getmac.1`/`getmac2.1`). They were severely out of date and unused. May re-add at a later date.

### Dev
* Migrate CI to GitHub Actions, remove TravisCI and Appveyor
* Add flake8 plugins: `flake8-pytest-style` and `flake8-annotations`
* Add additional samples and tests for WSL1 (with the Ubuntu 18.04 distro)
* Add additional samples for Windows 10
* Add additional samples for MacOS
* Add samples and tests for Ubuntu 12.04
* Add samples for NetBSD 8 (support coming in a future release)
* Add samples for Solaris 10 (support TBD)
* Add samples for several versions of Android
* Add new tests
* Improve existing tests
* Consolidate everything related to RPM packaging to `packaging/rpm/`. This stuff hasn't been updated since 0.6.0, may remove in the future and leave distro packaging to distro maintainers.


## 0.8.3 (12/10/2021)
Expand Down
Loading

0 comments on commit 07fcabf

Please sign in to comment.