Comments (2)
Alternatively, we can ask Git itself to give us the list of files it sees, that's what pre-commit does internally - see here.
from agda-unimath.
I asked GPT4 for a solution:
The easiest way to achieve this is by using the
pathspec
Python library, which allows you to match paths using.gitignore
style patterns.First, you'll need to install the library. You can do this using pip:
pip install pathspecThen, you can use the library in your script. You will need to read the contents of your
.gitignore
file and use them to compile aPathSpec
object. Then you can use thematch_file
method on this object to test whether a given path should be ignored.Here's how you can modify your
generate_index
function to ignore directories specified in your.gitignore
:from pathspec import PathSpec from pathspec.patterns import GitWildMatchPattern def generate_index(root, header): status = 0 entry_lists = [] # Read .gitignore file with open('.gitignore', 'r') as f: gitignore = f.read().splitlines() # Compile .gitignore file into a PathSpec pathspec = PathSpec.from_lines(GitWildMatchPattern, gitignore) for namespace in sorted(utils.get_subdirectories_recursive(root)): if namespace == 'temp': continue # Test if path matches .gitignore if pathspec.match_file(namespace): continue entry_list, s = generate_namespace_entry_list(namespace) entry_lists.append(entry_list) status |= s index = f'{header}\n\n' + '\n\n'.join(entry_lists) + '\n' return index, statusIn this script,
pathspec.match_file(namespace)
returnsTrue
if thenamespace
matches any pattern in your.gitignore
. If it does, thencontinue
skips to the next iteration of the loop, effectively ignoring that directory.Remember to take care of the relative paths. If your
.gitignore
file is not in the same directory as the script, you'll need to adjust the path when opening the file. Similarly, you'll need to make sure the paths you're testing withmatch_file
are relative to the location of your.gitignore
.
from agda-unimath.
Related Issues (20)
- Level universe HOT 1
- The module index generator doesn't support modules with unicode characters in their names HOT 14
- Record user statistics for the webpage HOT 2
- Record performance statistics for type-checking
- The equivalences on hom-sets in adjunctions of large (pre)categories go the unnatural way HOT 1
- Project: Sheaves and excision with respect to regular cd-structures HOT 4
- Refactor categories to come equipped with an identity system on its morphisms HOT 2
- Idea: refactor categories to build on the theory of wild categories HOT 2
- Idea: refactor (nonunital) precategories to have both directions of the associativity witness HOT 1
- Necessary truncations on formalizing cardinal arithmetic
- Autoformatting for Python files HOT 3
- Idea: use coherently invertible maps as default notion of equivalence HOT 1
- Bibliography HOT 1
- Retracts of sequential diagrams HOT 1
- Sync up nomenclature between towers and cotowers HOT 3
- Add `is-sequential-colimit`
- Discuss replacing `-whisk-` with `-whisker-` HOT 2
- Competing conventions for operations on propositions HOT 5
- Investigate memory usage when typechecking the whole library HOT 2
- Resolve duplicate definitions
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 agda-unimath.